-
-
Save kimwhite/5b8c196800f311d4886347b6918297a1 to your computer and use it in GitHub Desktop.
Redirect all WordPress users to a very specific page on login.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Redirect all users to a very specific page on login. | |
* This should work no matter what login form/etc you are using. | |
* If it doesn't work, maybe the 999 priority needs to be higher. | |
* If you want to respect the redirect_to param or earlier callbacks | |
* that overwrite it, uncomment the section at the top of the function. | |
* | |
* You can add this code to your site using the Code Snippets plugin or by | |
* placing the code into a custom plugin or your theme's functions.php. | |
*/ | |
function my_login_redirect( $redirect_to, $request, $user ) { | |
// If you'd like to honor previously set redirects, uncomment this section. | |
/* | |
if ( ! empty( $redirect_to ) ) { | |
return $redirect_to; | |
} | |
*/ | |
if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) { | |
if( $user->has_cap( 'administrator') or $user->has_cap( 'pmpro_membership_manager')) | |
$redirect_to = '/wp-admin/'; | |
} else { | |
$url = '/great/'; | |
} | |
} | |
return $redirect_to; | |
} | |
add_filter( 'login_redirect', 'my_login_redirect', 999 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment