1

I'm trying to add new custom capability so I can hide custom post type from non admins. In my custom post type I have some custom taxonomies and then 2 submenus. The administrator can see the menu of the custom post type, the taxonomies and the submenus, but other users can only see the submenus. But when I try to apply the add_role on the activation hook the submenus are not shown. I also tried with add_cap and the same happens. I also tried to add capabilities in the custom post type and then just the taxonomies were shown. I don't know what I'm doing wrong. Any ideas?

EDIT: As requested in the comment, this is how I add the 2 submenus:

     add_action('admin_menu','bsp_plugin_menu');
     function bsp_plugin_menu(){
add_submenu_page('edit.php?post_type=badge', 'Add new student', 'Add new students', 'manage-options','add-new-students','bsp_add_new_students');
add_submenu_page('edit.php?post_type=badge', 'Show students', 'Show students', 'manage_options','show-students','bsp_students_show');   
}
  • Please share how you are adding the submenus (code excerpt). – ambroseya May 27 '15 at 14:56
  • I edited the question with requested code. @ambroseya – dea May 27 '15 at 15:08
0

So to answer my question... I don't know if it is the best approach: In the custom post type I added capabilities to which only admin has priviliges like so:

    'capabilities'=>array(
        'edit_post'=>'update_core',
        'read_post'=>'update_core',
        'delete_post'=>'update_core',
        'edit_posts'=>'update_core',
        'edit_others_posts'=>'update_core',
        'publish_posts'=>'update_core',
        'read_private_posts'=>'update_core'
    ),

And then I also did that for custom taxonomies like so:

    'capabilities'=>array(
    'manage_terms'=>'manage_options',
    'edit_terms'=>'manage_options',
    'delete_terms'=>'manage_options',
    'assign_terms'=>'manage_options',
    ),

So only admin can see it and manage it. For the submenu in the capability parameter I just entered the capability which administrator, editor and author have in common (publish_posts).

add_submenu_page('edit.php?post_type=badge', 'Add new student', 'Add new students', 'publish_posts','add-new-students','bsp_add_new_students');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.