Activation mail while custom registration in wordpress

When using a custom registration form in WordPress, you may want to send an activation email to new users after they register. Here's a step-by-step guide on how to achieve this:

Step 1: Create a custom registration form

You can use a plugin like Gravity Forms, Formidable Forms, or even a custom PHP code to create a custom registration form. For this example, let's assume you're using Gravity Forms.

Step 2: Set up the registration form

In Gravity Forms, create a new form and add the necessary fields (e.g., name, email, password, etc.). Make sure to set the "Registration" option to "Yes" under the "Form Settings" tab.

Step 3: Create a custom registration function

In your theme's functions.php file, add the following code to create a custom registration function:

function custom_registration_handler($user_id) {
    // Get the user's email address
    $user_email = get_userdata($user_id)->user_email;

    // Send the activation email
    $subject = 'Activate Your Account';
    $message = 'Hello, '. get_userdata($user_id)->display_name. '. Please click the link below to activate your account: '. wp_login_url(). '?action=activate&key='. $user_id;
    wp_mail($user_email, $subject, $message);
}
add_action('user_register', 'custom_registration_handler');

This code will be triggered when a new user registers using your custom form. It gets the user's email address and sends an activation email using the wp_mail function.

Step 4: Update the user's status

In the same functions.php file, add the following code to update the user's status to "active" after they activate their account:

function activate_user($user_id) {
    $user = get_userdata($user_id);
    $user->update_user_meta('status', 'active');
}
add_action('wp_login_failed', 'activate_user');

This code will be triggered when a user activates their account by clicking the link in the activation email. It updates the user's status to "active" using the update_user_meta function.

Step 5: Test the custom registration form

Create a test user using your custom registration form. You should receive an activation email with a link to activate your account. Click the link, and your account should be activated.

That's it! With these steps, you should now have a custom registration form that sends an activation email to new users and updates their status to "active" after they activate their account.