Skip to content

Instantly share code, notes, and snippets.

@ajaypatelaj
Forked from viruthagiri/gist:1761124
Created February 8, 2012 05:45
Show Gist options
  • Save ajaypatelaj/1765863 to your computer and use it in GitHub Desktop.
Save ajaypatelaj/1765863 to your computer and use it in GitHub Desktop.
wordpress redirect on login based on roles
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;
}
<?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