Reputation: 1437
I am experiencing a strange issue.
I created a custom post type but for some reason it's not showing in the admin menu and when I am trying to access that page via url(edit.php?post_type=study_class) it says 'You donot have permission to access this page'
Here is the code
add_action('init', 'cptui_register_my_cpt_study_class');
function cptui_register_my_cpt_study_class() {
register_post_type('study_class', array(
'label' => 'Study Class',
'description' => '',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'study_class',
'capabilities' => array(
'edit_post' => 'edit_study_class',
'read_post' => 'read_study_class' ,
'delete_post' => 'delete_study_class',
'edit_posts' => 'edit_study_class' ,
'edit_others_posts' => 'edit_others_study_class',
'publish_posts' => 'publish_study_class' ,
'read_private_posts' => 'read_private_study_class',
'read' => 'read',
'delete_posts' => 'delete_study_class',
'delete_private_posts' => 'delete_private_study_class',
'delete_published_posts' => 'delete_published_study_class',
'delete_others_posts' => 'delete_others_study_class',
'edit_private_posts' => 'edit_private_study_class',
'edit_published_posts' => 'edit_published_study_class',
),
'map_meta_cap' => true,
'hierarchical' => false,
'rewrite' => array('slug' => 'study_class', 'with_front' => true),
'query_var' => true,
'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes','post-formats'),
'labels' => array (
'name' => 'Study Class',
'singular_name' => 'Study Class',
'menu_name' => 'Study Class',
'add_new' => 'Add New Study Class',
'add_new_item' => 'Add new Study Class',
'edit' => 'Edit',
'edit_item' => 'Edit Study Class',
'new_item' => 'New Study Class',
'view' => 'View Study Class',
'view_item' => 'View Study Class',
'search_items' => 'Search Study Class',
'not_found' => ' Study Class not found',
'not_found_in_trash' => ' Study Class not found in Trash',
'parent' => 'Parent Study Class',
)
) );
Any help is highly appreciated. Thanks in advance.
Upvotes: 0
Views: 1128
Reputation: 114
The problem on the capabilities, you do not have such capabilities so you can not see or edit the post type. Try to remove the capabilities and capability_type.
Upvotes: 0
Reputation: 4156
You need to remove capabilities
, capability_type
and map_meta_cap
in order to switch back to default Wordpress post capabilities.
What you was doing was first to set a custom capability type named study_class
- which isn't defined. Wordpress is using first the capability_type
to build the capabilities object, then override with the capabilities set with the capabilities
parameter. From the wordpress codex :
The 'capability_type' parameter is used as a base to construct capabilities unless they are explicitly set with the 'capabilities' parameter.
Then you were sending an array of capabilities relating to the same custom capability type - which is kind of a duplicate. And as extension, the capability names were wrong, because Wordpress is looking for plurials in some cases:
[cap] => stdClass Object
(
// Meta capabilities
[edit_post] => "edit_{$capability_type}"
[read_post] => "read_{$capability_type}"
[delete_post] => "delete_{$capability_type}"
// Primitive capabilities used outside of map_meta_cap():
[edit_posts] => "edit_{$capability_type}s"
[edit_others_posts] => "edit_others_{$capability_type}s"
[publish_posts] => "publish_{$capability_type}s"
[read_private_posts] => "read_private_{$capability_type}s"
// Primitive capabilities used within map_meta_cap():
[read] => "read",
[delete_posts] => "delete_{$capability_type}s"
[delete_private_posts] => "delete_private_{$capability_type}s"
[delete_published_posts] => "delete_published_{$capability_type}s"
[delete_others_posts] => "delete_others_{$capability_type}s"
[edit_private_posts] => "edit_private_{$capability_type}s"
[edit_published_posts] => "edit_published_{$capability_type}s"
[create_posts] => "edit_{$capability_type}s"
)
To have this working you would have need to create this capability type first.
Upvotes: 2