• niel

    (@nielfernandez)


    Hello I Good day all WordPress People I need Help I have project custom role named
    ‘sales’ using member plugins what I wish to do is when they log in they cannot access wp-admin I used plugins and its work but the user stay with the link https://www.domain.com/wp-admin and got message “You are not allowed to access dashboard”

    what I wish to achieve is set a redirect to users every time they visit my “domain.com/wp-admin” redirect to home page but I have button link to create them a post which user redirect to post. “Only domain.com/wp-admin this url user should not access not message but redirect” but the post they should can.

    Can you Please help me??

Viewing 4 replies - 1 through 4 (of 4 total)
  • To redirect base on user role check the following filter example.

    function my_login_redirect( $url, $request, $user ){
    
    	if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
    	
                    /*check your roles,customize according to you conditions*/
    		if( $user->has_cap( 'administrator') or $user->has_cap( 'author')) { 
    			$url = admin_url();
    		} 
    		else 
    		{
    			$url = home_url('/custom-page /');
    		}
    		
    	}
    	return $url;
    }
    
    add_filter('login_redirect', 'my_login_redirect', 10, 3 );

    for further information please refer Please go through this link

    I hope this will help you ??

    • This reply was modified 4 years, 5 months ago by sebinfernandez.
    • This reply was modified 4 years, 5 months ago by sebinfernandez.
    • This reply was modified 4 years, 5 months ago by bcworkz. Reason: code fixed
    Thread Starter niel

    (@nielfernandez)

    @sebinfernandez yes, This is work but still accessible “wp-admin” which should not anyway Thanks for trying to help me.

    Please check this Check this out

    Moderator bcworkz

    (@bcworkz)

    Hey @sebinfernandez, thanks for helping out in the forums! When you post code in the forums, please use the code button or demarcate code with backticks. When you don’t, the forum’s parser corrupts your code, making more difficult for others to copy and use it. I fixed your code in your initial reply here so it’s formatted correctly.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Set Redirect user by custom role wp-admin should not be access’ is closed to new replies.