• Resolved buging

    (@buging)


    Hi!

    I searched the forums for answers but I can’t seem to find a code that works. I’m trying to achieve the following:

    1. replace wp-login. basically, if a user accesses a page that requires a login, then the UM login page should be served (instead of wp-login)
    2. at the same time, the user should be redirected back to the page he/she was trying to access (instead of to profile or fixed URL) after a successful login.

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @buging

    You can try this code to redirect from wp-login to /login/ page:

    add_action('init', 'prevent_wp_login');
    function prevent_wp_login() {
        // WP tracks the current page - global the variable to access it
        global $pagenow;
        // Check if a $_GET['action'] is set, and if so, load it into $action variable
        $action = (isset($_GET['action'])) ? $_GET['action'] : '';
        // Check if we're on the login page, and ensure the action is not 'logout'
        if( $pagenow == 'wp-login.php' && ( ! $action || ( $action && ! in_array($action, array('logout', 'lostpassword', 'rp', 'resetpass'))))) {
            // Load the UM Login URL
            $page = um_get_core_page("login");
            // Redirect to the home page
            wp_redirect($page);
            // Stop execution to prevent the page loading for any reason
            exit();
        }
    }

    2. To redirect a user back to the previous page, your Login link should have the redirect_to parameter with previous page URL.
    e.g. <a href="yoursiteurl.com/login/?redirect_to=<current page URL>Login</a>

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @buging

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help. ??

    Regards,

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Redirect to previous page and replace default wp-login’ is closed to new replies.