Skip to content

Instantly share code, notes, and snippets.

@cryptexvinci
Created January 6, 2024 16:56
Show Gist options
  • Save cryptexvinci/2668f6a86db6394ec8c4f91e361eb634 to your computer and use it in GitHub Desktop.
Save cryptexvinci/2668f6a86db6394ec8c4f91e361eb634 to your computer and use it in GitHub Desktop.
Ultimate Member - Adds a user to a specified group
<?php
/*
* Adds a user to a specified group with specific details, such as the group ID, user ID,
* when a user registers on a website using the Ultimate Member plugin.
*/
add_action( 'um_registration_set_extra_data', 'my_registration_set_extra_data', 10, 2 );
function my_registration_set_extra_data( $user_id, $args ) {
global $wpdb;
$table_name = UM()->Groups()->setup()->db_groups_table;
$wpdb->insert(
$table_name,
array(
'group_id' => 'YOUR_GROUP_ID',
'user_id1' => $user_id,
'user_id2' => $user_id,
'status' => 'approved',
'role' => 'member',
'date_joined' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) )
),
array( '%d', '%d', '%d', '%s', '%s', '%s' )
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment