WordPress – custom roles issue. Can’t see dashboard list for a custom post typr

  1. I have a custom post type named – Event
  2. I have a custom role named coordinator and another custom role named agent
  3. I want coordinators to be able to fully manage Events from admin area dashboard while agents to not.
  4. I managed to do this fine so far:
    a. Events link under plugin menu displays fine to Coordinators.
    b. Events link under plugin menu doesn’t display to Agents.
    c. Events link under plugin menu doesn’t display to Administrator.
    d. Administrators can add/edit/delete Events fine from admin area.

But
When a coordinator clicks on the Events link in admin dashboard under plugin menu, it displays “You do not have sufficient permissions to access this page.”.

But
If I give a direct URL to browser logged in as an coordinator to edit an event with post_id in Querystring, it works fine.
So somehow, a coordintator is not able to list all the events as a dashboard post listing page.

Read More

Thats how I created custom post type and its capabilities under register_post_type

'capability_type' => 'event',
'capabilities' => array(
    'publish_posts' => 'publish_events',
        			'edit_posts' => 'edit_events',
        			'edit_others_posts' => 'edit_others_events',
        			'delete_posts' => 'delete_events',
        			'delete_others_posts' => 'delete_others_events',
        			'read_private_posts' => 'read_private_events',
        			'edit_post' => 'edit_event',
        			'read_post' => 'read_event',
        			'delete_post' => 'delete_event',
        			'publish_post' => 'publish_event',	
    ),
    //'map_meta_cap' => true,    			
)

And this is how capabilities are added to the role (This is done under plugin’s activation hook because I think this gets added to database so no need to run this code on every page execution. Please correct if am wrong)

$role = get_role( 'coordinator' );
$role->add_cap( 'read' ); 			
$role->add_cap( 'edit_posts' ); 			
$role->add_cap( 'edit_others_posts' ); 			 			
$role->add_cap( 'edit_event' ); 
$role->add_cap( 'edit_events' ); 
$role->add_cap( 'edit_others_events' ); 
$role->add_cap( 'publish_events' ); 
$role->add_cap( 'read_event' ); 
$role->add_cap( 'read_private_events' ); 
$role->add_cap( 'delete_event' ); 			
$role->add_cap( 'delete_events' ); 			
$role->add_cap( 'delete_others_events' ); 

Please assist. Thanks for assistance in advance.

Regards

Related posts

Leave a Reply