1

I'm encountering funny behaviour with a custom post of mine that I'm working with in a plugin of mine. Here are the arguments of the custom post:

array(
    'label' => [omitted],
    'labels' => [omitted],
    'public' => false,
    'show_ui' => true,
    'menu_position' => 21,
    'menu_icon' => 'dashicons-editor-help',
    'supports' => array('title','editor','comments'),
    'capability_type' => array('custom-post','custom-posts'),
    'show_in_rest' => false,
    'show_in_menu' => 'my-plugin' // Able to create posts with restricted user role if I remove this line.
)

Note that this custom post type is put inside of a menu, which requires a capability of edit_custom-posts to be able to access.

add_menu_page('My Plugin Module', 'My Plugin Module', 'edit_custom-posts', 'my-plugin','','dashicons-admin-network',21);

As I want to allow only site Administrators, as well as a custom user role (let's call them Plugin Admins), to be able to manage these custom post types completely. To this end, I've added the following capabilities to them:

$cap['edit_custom-post'] = true;
$cap['read_custom-post'] = true;
$cap['delete_custom-post'] = true;
$cap['edit_custom-posts'] = true;
$cap['edit_others_custom-posts'] = true;
$cap['publish_custom-posts'] = true;
$cap['read_private_custom-posts'] = true;
$cap['edit_published_custom-posts'] = true;
$cap['delete_published_custom-posts'] = true;

Everything works the way I want it to: Administrators and Plugin Admins have no problem accessing, editing and creating new custom posts, if I do not put the custom post under the my-plugin menu. When I do, Administrators still can create new custom posts, but Plugin Admins can do everything except create new custom posts. Instead, they will get a Sorry, you are not allowed to access this page error.

Anyone have any insight into why this is happening? What permission does the Administrator have that the Plugin Admins do not?

0

I couldn't find an answer to this question with User Roles Editor, but I have worked around this problem by showing different admin panels for different users. When Plugin Admin logs in, the custom post type is not put under a menu, so they can create new custom posts. When the Administrator logs in, the custom post type will be put under a menu.

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.