2

I am trying to create a role that can create and submit to a CPT only. When I take away edit_post from the role, it revokes the ability to create and edit any of the assigned and registered CPTs as well. I have registered and assigned the edit_CPTs capability to the role as well. So basically, I have this:

edit_cpt
edit_cpts

and I have taken away

edit_posts

But once I remove edit_posts the role cannot even see the CPTs in the dashboard interface. Any help would be greatly appreciated.

3

You need to register the CPT with your custom capability, then assign that specific cap to the user.

When passing the arguments to register_post_type, set capability_type to your new capability, so the check turns into 'edit_cpts' instead of 'edit_post'.

By setting 'capability_type' => [ 'cpt', 'cpts' ], 'cpt' will map to 'post' for standard capability checks, so where you'd usually check for 'edit_post' you'll now check for 'edit_cpt'.

When you completely remove the primitive 'edit_posts' cap from users/roles as you've done, you'll need to add in your new one with WP_Role::add_cap() and check for it with current_user_can( 'edit_cpts' ).

  • Downvote. The problem with this solution is that it removes default capabilities for admin and editor roles. – Dev Dec 13 '17 at 9:11

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.