08-30-2018, 05:03 PM
<?php
/**
* Redirecting users on login based on user role
*/
function my_login_redirect( $url, $request, $user ){
if( $user && is_object( $user ) && is_a( $user, 'User' ) ) {
if( $user->has_cap( 'administrator' ) ) {
$url = admin_url();
} else {
$url = home_url('/users-only/');
}
}
return $url;
}
add_filter('login_redirect', 'my_login_redirect', 10, 3 );
?>
Will that work for a redirect page?
/**
* Redirecting users on login based on user role
*/
function my_login_redirect( $url, $request, $user ){
if( $user && is_object( $user ) && is_a( $user, 'User' ) ) {
if( $user->has_cap( 'administrator' ) ) {
$url = admin_url();
} else {
$url = home_url('/users-only/');
}
}
return $url;
}
add_filter('login_redirect', 'my_login_redirect', 10, 3 );
?>
Will that work for a redirect page?