• I have 2 login links in my Open Studios website: one for member artists and another for administrators. Pie-register is working perfectly for member artists. Administrators login on admin-page and I want them to stay on admin-page after login. (The page uses “if user logged in” logic to present alternate content after login.) The code I am using to log admins in is:

    $redirect = esc_url(home_url(‘/admin-page/’)) ;
    $args = array(‘redirect’ => $redirect);
    wp_login_form($args);

    The redirect does not work with pie-register. The admin is redirected to the dashboard. I have tried adding the following filter to my functions.php:

    function my_login_redirect( $redirect_to, $request, $user ) {
    //is there a user to check?
    //global $user;
    if ( isset( $user->roles ) && is_array( $user->roles ) ) {
    //check for admins
    if ( in_array( ‘administrator’, $user->roles ) ) {
    // redirect them to the default place
    return home_url(‘/admin-page/’);
    } else {
    return $redirect_to;
    }
    } else {
    return $redirect_to;
    }
    }
    add_filter( ‘login_redirect’, ‘my_login_redirect’, 12, 3 );

    I’ve tried different priorities as well as uncommenting the global without success. Is there some filter I can use that will redirect administrators to admin-page upon login without interfering with pie-register?

    Note: Pie-register also overrides the logout redirect I give to wp_logout_url(). However, that is not a big issue for my site.

    https://wordpress.org/plugins/pie-register/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Redirect on login’ is closed to new replies.