• Resolved studio481

    (@studio481)


    I got the Registration page set up. Anyone can register is toggled on. Bots (and savvy visitors) can just go to [mydomain]/wp-login.php?action=register and use the default WordPress registration and not fill out the fields I want them to on the the plugin constructed Registration page.

    If I turn off Anyone can Register, then the plugin generated Registration page says “Only administrators can add new users.” and the form is hidden.

    What am i missing? I would think the plugin would automatically redirect /wp-login.php?action=register to the plugin’s registration page, but it doesn’t. I have scoured the documentation and the support forum and cannot find recommendations on how to handle this dilemma. Is there a toggle I missed in the plugin settings? Is there another plugin that WPEverest recommends to close this registration back door?

    Please advise.

    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi there,

    There are no such options to redirect default WordPress login and registration page in our plugin. But you can add this piece of code in theme’s function.php.

    add_action(  'login_init', 'user_registration_login_init'  );
    function user_registration_login_init () {
         if( ! is_user_logged_in() ) {
            wp_redirect( '/my-account' );
            exit;
          }
    }

    Thanks & Regards.

    Thread Starter studio481

    (@studio481)

    Thank you for your reply and the code. Much appreciated!

    This code works fine, so now every user uses your login form, not the default.

    Is it possible to extend this function to this:

    1. If user not logged in redirect to your login page.
    2. If user is Admin, redirect to default WordPress Dashboard.
    3. Otherwise return to your account page (or even better the page they came from)

    Many thanks!

    Erik

    @erikvdhorst I assume you mean after they submit the login form (and successfully log in), because otherwise you don’t know if they’re an admin or not. The “login_init” hook fires when the login form is initialised, so to redirect the user after they submit the form and log in, you can use something like this in your active theme’s functions.php file:

    add_filter( 'login_redirect', 'prefix_login_redirect', 10, 3 );
    function prefix_login_redirect( $redirect_to, $request, $user ) {
        //If we are viewing the account page, redirect to it after logging in
        if( strpos( $redirect_to, 'account' ) !== false ) {
            //If user is an administrator, redirect to WordPress dashboard
            if( isset( $user->roles ) && is_array( $user->roles ) && in_array( 'administrator', $user->roles ) ) {
                return '/wp-admin/';
            }
            return esc_url( home_url( '/account/' ) );//Otherwise, redirect to account page
        }
        return $redirect_to;//Redirect to current page after logging in
    }

    Alternatively, you can check capabilities instead of roles on line 6 of my snippet if you’d rather:
    if( current_user_can('administrator') )

    Hi team!
    The plugin is perfect for me, I just want to know one thing that, if user is logged in and he tried to go to registration page by url or login page it should redirect it to account page or other custom page I want, because currently it shows the registration and login page to already logged in users too.Can you help me out with this.
    Thanks

    • This reply was modified 4 years, 9 months ago by khan321.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to REDIRECT /wp-login.php?action=register to the Plugin’s /registration page’ is closed to new replies.