Send activation email to user after signup [duplicate]

For activation process you can follow following steps:

  1. As you can see user_activation_key column in wp_users table. You can make use of that column for sending user activation link.
  2. While signing up users you can insert certain code into that column
    with custom sql. After the user is signed up with
    wp_insert_user() and returns an id to $user_id, a custom insert
    sql can be run

        $user_id = wp_insert_user($user_detail);
    
        if ( $user_id && !is_wp_error( $user_id ) ) {
    
            $code = sha1( $user_id . time() );    
            global $wpdb;    
            $wpdb->update( 
                'wp_users', //table name     
                    array( 'user_activation_key' => $code,  // string    ),       
                    array( 'ID' =>    $user_id ),     
                    array( '%s',    // value1     )
                );
    
            $activation_link = add_query_arg( array( 'key' => $code, 'user' => $user_id ), get_permalink( /* your activation page id here*/ ));  
    
            wp_mail( $user_email, 'SUBJECT', 'Activation link : ' . $activation_link );
        }. 
    

    This will send user an activation link like http://example.com/activation-page/?key=CERTAIN_KEY&user=USER_ID to their email and on the activation page you can run code for activating the users by altering another column user_status from 0 to 1.

  3. After this you can run for another update for user_status column by

    global $wpdb;   
    
    $wpdb->update( 
        'wp_users', //table name     
         array( 'user_status' => 1, // integer   ),       
         array( 'ID' =>    $_GET['user'], //where clause
           'user_activation_key'=>$_GET['key'] //where clause
         ), 
         array( '%d', //value1    )
    );
    

Than you can allow users having status 1 to sign in.

Leave a Comment