Do not allow users to create new posts and pages

I’m defining a new user role called Proofreader and as the name says, users of this group should be able to read and also edit the posts and pages. But I do not want them to create new ones.

With my custom post types I can set a capability create_post -> create_{cpt_name} and set it to false for this user group. In the backend they now don’t see the add button, but can still edit the posts. That’s exactly what I want. Unfortunately I was unable to find a way to set this capability for the predefined CPT of WordPress (Posts & Pages). Also the Members plugin seems to be unable to restrict user roles of creating new posts while letting them edit.

While researching, I found, that this seems to be a big issue of WordPress which is not solved yet. Is this true?

If not, I would be really thankful if anyone could help me out with this… It would really be a solution of a big problem of my website!

2 Answers
2

Use remove_cap for this.

function remove_proofreader_create_posts(){
    global $wp_roles;
    $wp_roles->remove_cap( 'proof_reader', 'create_posts' );
    $wp_roles->remove_cap( 'proof_reader', 'create_pages' );
}

NOTE: This is not a global function, but a method of the WP_Roles, WP_Role and WP_User classes. It must be called using an instance of one of these classes, as shown in the examples.

ALSO: You’ll want to call the function once, as in during plugin activation, not on a constant hook.

Reference: https://codex.wordpress.org/Function_Reference/remove_cap

Leave a Comment