• Resolved Subrata Sarkar

    (@subrataemfluence)


    First of all I am a WordPress learner. So sorry if my code looks stupid!

    I have created a custom theme with a custom user role. I am not developing any plugin.

    In my fucntions.php file I have written the following code to create a User role. Users assigned to this role are supposed to login to the admin but only be able to access their Profile pages.

    
    add_action('init', 'yrc_cst_register_role_customer_service_rep');
        
    function yrc_cst_register_role_customer_service_rep() {
    
    	$wp_roles = new WP_Roles();
    
    	$wp_roles->remove_role('subscriber');
    	$wp_roles->remove_role('editor');
    	$wp_roles->remove_role('contributor');
    	$wp_roles->remove_role('author');
    
    	$service_rep_caps = array(
    	    'read'              => false,
    	    'create_posts'      => false,
    	    'edit_posts'        => false,
    	    'edit_others_posts' => false,
    	    'publish_posts'     => false,
    	    'manage_categories' => false,
    	    'manage_options'    => false,
    	);
    
    	add_role('customer_service', __('Customer Service'), $service_rep_caps);
    }
    

    I have removed all roles except Administrator, because no other role is required for this portal. Administrator will only create Users with **Customer Service** role.

    I have no third party plugin installed in the system.

    Users with the custom role are able to login to the system through a custom login page which is working OK. But whenever they are trying to access their Profile page the following error message comes up:

    Sorry, you are not allowed to access this page.

    Is there anything like 'edit_profile' => true?

    I must be doing something wrong but my limited knowledge is not enough to figure this out. Any suggestion would be highly appreciated.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘User with custom role cannot access wp-admin’ is closed to new replies.