Sync users after user activation
-
Hello.
I’m using a code like that to generate an activation code after registration. The user have to click on it in the mail we’ve sent him to be activated.
Unfortunately, Multisite User Management doesn’t sync the users with all sites as set in the options anymore.
Can you help? Thank you.
/** * Create an activation key for the * user at registration. */ add_action( 'wpmem_post_register_data', 'my_generate_key' ); function my_generate_key( $fields ) { // generate a random key $key = md5( wp_generate_password() ); // save this for the new user account add_user_meta( $fields['ID'], 'activation_key', $key ); } /** * Include the activation key in the new user * registration email as an activation link. */ add_filter( 'wpmem_email_filter', 'my_add_key_to_email', 10, 3 ); function my_add_key_to_email( $arr, $wpmem_fields, $field_data ) { // only do this for new registrations if( $arr['toggle'] == 'newmod' ) { // get the stored key $key = get_user_meta( $arr['user_id'], 'activation_key', true ); // set up query string for passing the key $key_path = '/?activate=' . $key; // add text and link to the email body $arr['body'] = $arr['body'] . "\r\n" . 'Click this link to activate your account: ' . get_site_url() . $key_path; } return $arr; } /** * Check for an activation key and if one exists, * validate and log in user. */ add_action( 'init', 'my_validate_key' ); function my_validate_key(){ // check for activation key if( isset( $_GET['activate'] ) ) { // get the user account the key is for $user = reset( get_users( array( 'meta_key' => 'activation_key', 'meta_value' => $_GET['activate'], 'number' => 1, 'count_total' => false ) ) ); if( $user ) { // the provided activation key was valid, log in wp_set_auth_cookie( $user->ID, 'true' ); // delete activation_key meta and set active delete_user_meta( $user->ID, 'activation_key' ); update_user_meta( $user->ID, 'active', '1' ); } } }
- The topic ‘Sync users after user activation’ is closed to new replies.