0

The idea is to get rid of mandatory new account activation through email As is: register new user -> exit without following to email verification link -> try to log in -> Site says something like:

"Your account has to be activated before you can login. You can resend email with verification link by clicking here."

Desired to be: register new user -> exit without following to email verification link -> try to log in -> Site let you in. At my account page (mysite.com/my-account/) there is suggestion to activate account or resend email with activation link

2 Answers 2

0

You can use my WP Login Flow plugin to setup this up, or since it's open source use it as a reference for how to do it yourself.

https://github.com/tripflex/wp-login-flow

https://wordpress.org/plugins/wp-login-flow/

Specifically here's the register.php file: https://github.com/tripflex/wp-login-flow/blob/master/classes/register.php

0

Here is how you can do that:

Step 1: Modify User Registration Process

Add this code in your theme's functions.php to change the registration process:

(consider creating a child theme if you don't have one already, testing on your live theme is ok but in the end this code should live in a child theme so it does not get deleted when you update your theme.)

function wpb_custom_user_register($user_id) {
    // Set a custom user meta to indicate the account is not activated
    update_user_meta($user_id, 'has_to_be_activated', 0);
}
add_action('user_register', 'wpb_custom_user_register');

Step 2: Modify Login Behavior

Modify the login process to allow users to log in even if their account isn't activated:

function wpb_custom_user_login($user, $username, $password) {
    // Check if the user exists and password is correct
    $user = get_user_by('login', $username);
    if (!$user || !wp_check_password($password, $user->user_pass, $user->ID)) {
        return null; // or appropriate error handling
    }

    // Allow login without activation
    if (get_user_meta($user->ID, 'has_to_be_activated', true) == 0) {
        return $user;
    }

    return $user; // proceed with the normal login process
}
add_filter('authenticate', 'wpb_custom_user_login', 30, 3);

Important Notes: Theme Dependency: Remember, modifications in the functions.php file are theme-specific. If you change your theme, you'll lose these customizations.

Backup: Always backup your site before making changes to the functions.php file.

Child Theme: Consider using a child theme to avoid losing changes when the parent theme updates.

Security and Testing: Ensure that any changes you make are secure and thoroughly tested in a staging environment before applying them to your live site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.