-
-
Save jpmarchand/366a7fa2be226cccc9cb to your computer and use it in GitHub Desktop.
Add a Login/Logout toggle item in WordPress navigation menu. Source: http://rezzz.com/add-login-and-logout-to-your-wordpress-menu/
This file contains 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 admins to WordPress Dashboard and other users to site's homepage after a successful login | |
* https://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect | |
* | |
* @param string $redirect_to URL to redirect to | |
* @param string $request URL the user is coming from | |
* @param object $user Logged user's data | |
* @return string | |
*/ | |
add_filter( 'login_redirect', 'customprefix_login_redirect', 10, 3 ); | |
function customprefix_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 $redirect_to; | |
} else { | |
return home_url(); | |
} | |
} else { | |
return $redirect_to; | |
} | |
} |
This file contains 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 site's homepage after logout | |
add_filter( 'logout_redirect', create_function( '$url,$query,$user', 'return home_url();' ), 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment