P
P
Pantene7422017-02-24 16:10:25
CMS
Pantene742, 2017-02-24 16:10:25

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

1 answer(s)
D
Dmitry Karaka, 2017-02-24
@Pantene742


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 question

Ask a Question

731 491 924 answers to any question