Moderator
t-p
(@t-p)
Thank You! That is exatcly what I was looking for.
For the first impressions it is not working. When the user is simple user, it does not redirects to registration form. I have to see, maybe other plugins are blocking gateway or something….
Is there something similar for that what you gave to me? Maybe I can try something else later. Thank You!
Hi l0we2trave1,
In case if the plugin is not working for you. You can try this code:
function ps_redirect_user_by_role() {
$current_user = wp_get_current_user();
$role_name = $current_user->roles[0];
if ( 'subscriber' === $role_name ) {
wp_redirect( 'http://yoursite.com/page1' );//URL where you want to redirect
}
if('administrator' === $role_name){
wp_redirect( 'http://yoursite.com/page2' );
}
//same for other roles just check the role and redirect accordingly
}
add_action( 'admin_init', 'ps_redirect_user_by_role' );
Just paste it in your child theme’s functions.php file and it will do the trick for you. I have mentioned in the code how you can add redirection for other roles and where to enter the URL in the code.
Hopefully, it will help you.
Thanks
Hi, I used code snippets plugin to insert your code.
It shows me error :
The code snippet you are trying to save produced a fatal error on line 12:
syntax error, unexpected ‘admin_init’ (T_STRING), expecting ‘,’ or ‘)’
12 line ->
add_action( ‘admin_init’, ‘ps_redirect_user_by_role’ );