-
-
Save ajaypatelaj/1765863 to your computer and use it in GitHub Desktop.
wordpress redirect on login based on roles
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
function fs_login($user, $pass) { | |
$uname = $user; | |
$pass1 = $pass; | |
$credentials = array( | |
'user_login' => $user, | |
'user_password' => $pass, | |
'remember' => true | |
); | |
$user = wp_signon($credentials, false); | |
if( $user->ID ){ | |
update_user_meta($user->ID, '_last_loggedin', $_SERVER['REMOTE_ADDR']); | |
foreach($user->roles as $role){ | |
if($role == "Stringer" ){ | |
// redirect to stringer page | |
}else if($role == "Media" ){ | |
// redirect to media page | |
}else{ | |
// redirect to general page | |
} | |
} | |
return null; | |
} |
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 | |
function redirect_by_role () { | |
global $current_user, $wp_roles; | |
if( current_user_can ( 'manage_options' ) ) { | |
return 'http://yourdomain.com/wp-admin/'; | |
} else if ( current_user_can ( 'activate_plugins' ) ) { | |
return 'http://yourdomain.com/account/'; | |
} else { | |
return 'http://yourdomain.com/'; | |
} | |
} | |
add_filter('login_redirect', 'plugin_admin_redirect'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment