Created
April 14, 2014 17:33
-
-
Save dbarkley/10667936 to your computer and use it in GitHub Desktop.
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
// This goes in the themes functions.php | |
function fullwood_logout_url() { | |
// Gets the current user | |
$current_user = wp_get_current_user(); | |
// Gets their roles | |
$current_user_roles = $current_user->roles; | |
// Checks to see if they have the client role | |
if (in_array('client', $current_user_roles)) { | |
// Gets their username | |
$username = $current_user->user_login; | |
// Generate URL based on their username i.e www.example.com/username-login | |
$redirect_url = get_site_url() . "/" . $username . "-login"; | |
// Generates a logout url with redirect | |
return wp_logout_url($redirect_url); | |
} else { | |
// If not of role client, do a normal logout | |
return wp_logout_url(); | |
} | |
} | |
// This goes in the header template | |
<?php | |
if ( is_user_logged_in() ) { | |
<a href="<?php echo fullwood_logout_url(); ?>" title="Logout">Logout</a> | |
} ?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment