Divi WordPress Theme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Quirk redirect after login

Discussion in 'Misc WordPress Requests' started by fibbo8, Jan 12, 2018.

  1. fibbo8

    Guest

    Quirk redirect after login, by fibbo8

    Hy!

    I’m creating a page in a local installation.
    I’ve inserted a page with a link to wp-login.

    I’d wished to have a redirect to that page, after a user had logged in as a subscriber.
    So in function.php I’ve insert this piece of code:

    function loginRedirect( $redirect_to, $request, $user ) {
    if ( is_a( $user, 'WP_User' ) && $user->has_cap( 'edit_posts' ) === false ) {
    return get_bloginfo( 'siteurl' );
    }
    return $request;}
    add_filter( 'login_redirect', 'loginRedirect', 10, 3 );

    But with this code operating, after the login the user is redirect to the home page.
    I’ve tried to change the code, using the wp_get_referer function:

    function loginRedirect( $redirect_to, $request, $user ) {
    if ( is_a( $user, 'WP_User' ) && $user->has_cap( 'edit_posts' ) === false ) {
    return get_bloginfo( 'siteurl' );
    }
    return wp_safe_redirect( wp_get_referer() );}
    add_filter( 'login_redirect', 'loginRedirect', 10, 3 );

    In this case the link in the page that point to “wp-login.php” redirect directly to the current page and the user haven’t the possibility to log-in.

    Quirk redirect after login
     
    #1

Share This Page

Monarch Social Sharing Plugin