Quirk redirect after login
-
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.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Quirk redirect after login’ is closed to new replies.