Skip to content

Instantly share code, notes, and snippets.

@kimwhite
Forked from ideadude/my_login_redirect.php
Last active December 14, 2023 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimwhite/5b8c196800f311d4886347b6918297a1 to your computer and use it in GitHub Desktop.
Save kimwhite/5b8c196800f311d4886347b6918297a1 to your computer and use it in GitHub Desktop.
Redirect all WordPress users to a very specific page on login.
<?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