0

I am having issue with my capability setup, so I created a custom post type named "Company", with the following args:

        'capability_type'        => array( 'company', 'companies' ),
        'capabilities'           => array(
            'edit_post'          => 'edit_company',
            'read_post'          => 'read_company',
            'delete_post'        => 'delete_company',
            'edit_posts'         => 'edit_companies',
            'edit_others_posts'  => 'edit_others_companies',
            'publish_posts'      => 'publish_companies',
            'read_private_posts' => 'read_private_companies',
            'create_posts'       => 'create_companies',
            'delete_posts'       => 'delete_companies',
        ),
        'map_meta_cap'           => false,

ideally, I want a role: "Service Provider" to have CRUD capability for this post type.

    remove_role( 'service_provider' ); // delete whatever is in record
    add_role(
        'service_provider',
        __( 'Service Provider' ),
        array(
            'edit_posts'            => false, // i do not want them to create built in post
            'read'                  => true,
            'edit_company'          => true,
            'read_company'          => true,
            'edit_companies'        => true,
            'publish_companies'     => true,
            'edit_others_companies' => false,
            'create_companies'      => false,
            'delete_companies'      => false,
            'read_private_posts'    => false,
        )
    );

but the settings above for that role does not work, if the capability 'edit_posts' => false it doesn't allow me to view the CPT listing in the dashboard for the custom post type "Company", (though it appears in the menu):

enter image description here

But if I set it to 'edit_posts' => true, the CPT "Company" behaves as expected but the built in "Post" is appearing in the menu and allows the user to interact with it.

enter image description here

Hope somebody can help me with this. Regards,

  • what capabilities do you have when you look the result of get_post_type_object("company") ? – Kaperto Aug 14 '18 at 9:31

Your Answer

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

Browse other questions tagged or ask your own question.