Answer the question
In order to leave comments, you need to log in
How to assign redirects in Wordpress after authorization for different roles?
I want to send the admin to the Admin panel, and other users, for example, to the page domen.ru/stranica
Answer the question
In order to leave comments, you need to log in
function wc_custom_user_redirect( $redirect, $user ) {
$role = $user->roles[0];
$dashboard = admin_url();
$myaccount = get_permalink( wc_get_page_id( 'myaccount' ) );
if( $role == 'administrator' ) {
//Redirect administrators to the dashboard
wp_redirect($dashboard);
exit;
} elseif ( $role == 'shop-manager' ) {
//Redirect shop managers to the dashboard
wp_redirect($dashboard);
exit;
} elseif ( $role == 'editor' ) {
//Redirect editors to the dashboard
wp_redirect($dashboard);
exit;
} elseif ( $role == 'author' ) {
//Redirect authors to the dashboard
wp_redirect($dashboard);
} elseif ( $role == 'customer' || $role == 'subscriber') {
wp_redirect(get_permalink(id));
exit;
} else {
wp_redirect(get_permalink(id));
exit;
}
}
add_filter( 'wp_login', 'wc_custom_user_redirect', 10, 2 );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question