2

I need to stop 'contributors' from editing the standard post type, but I want to allow them to edit a custom post type. My code so far:

remove_cap( 'contributor', 'edit_posts' );

Thanks!

UPDATE: Why the above answer isn't useful to me. I am looking for a coding solution not a plugin recommendation. I am also using a standard role 'contributor' not creating my own role. Thanks!

0
1

Add the capabilities to the role. Replace 'cpt' with the name of your custom post type:

$role = get_role( 'contributor' );
$role->add_cap( 'delete_published_cpt' );
$role->add_cap( 'delete_others_cpt' );
$role->add_cap( 'delete_cpt' );
$role->add_cap( 'edit_others_cpt' );
$role->add_cap( 'edit_published_cpt' );
$role->add_cap( 'edit_cpt' );
$role->add_cap( 'publish_cpt' );

But you shouldn't add or remove caps on every page load. That's why a plugin is better. You adjust caps on the plugin activation using register_activation_hook. And you can revert your changes using register_deactivation_hook because you have a conscience.

1
  • 1
    I would note that adding and removing caps changes the database, which is why you only need to call it once – Tom J Nowell Apr 27 '15 at 20:36

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.