Allowing custom role user to edit post assigned to them but don't let them create new custom type post

Please don't mark this as already asked question as I have searched all the questions and none of them gives a clear answer.

So I have created a custom role through Members plugin and I want the user with custom role 'Society Manager'to edit the custom post type post only and dont let them create new one. Admin should still be allowed to create new posts.

I have seen others using css/html and Jquery to remove the Add New button but it's not a good choice. The problem is I dont see create_posts option in Members plugin. So can anyone please help me solve this issue in detail? This is my custom post type code.


              register_post_type('society' , array(
                'show_in_rest' = true,
                'capability_type' = 'society',
                   'map_meta_cap' = true,  
                'capabilities' = array(
                    'create_posts' = 'do_not_allow',
                ),
                'supports' = array('title','thumbnail','author'),
                'rewrite' = array('slug' = 'societies'),
                'has_archive' = true,
                'public' = true,
                'labels' = array(
                    'name' = 'Societies',
                    'add_new_item' = 'Add New Society',
                    'edit_item' = 'Edit Society',
                    'all_items' = 'All Societies',
                    'singular_name' = 'Society'
                ),
                'menu_icon' = 'dashicons-buddicons-groups'
           ));

You can see there is no option to deny create_posts in members plugin

Topic members user-roles capabilities custom-post-types Wordpress

Category Web


You cannot find the capability because it does not exist. In WP out of the box, the paradigm is not post creation, but post publishing. Users can be adjusted to edit and create drafts and pending posts, but not publish.

Setting users to only edit however is not possible at the roles and capabilities level, and implementing that would be a significant amount of work on WP Core itself. For example, this would break autosaves and revision history if it was possible as is.

Additionally, the internal code paths for update posts vs creating posts are near identical. The important part being wether a post ID is specified when wp_insert_post is called.

It might be possible that you can intercept and prevent the posts creation during on of the post save hooks, but this is likely to have unanticipated knock on effects, as well as the UI still implying post creation is possible.

To summarise:

  • This isn't possible with vanilla WP
  • WP itself is built under the assumption it isn't possible
  • Making it possible is a significant amount of work involving WP Core ( possibly months or years of work )
  • You could kludge your way to it with filters, but the results will be awful with lots of difficult non-trivial bugs
  • The REST API and XMLRPC could bypass those

I strongly discourage against further pursuing this path, advise that it will be expensive in the extreme, and that the chances of failure are incredibly high. Find an alternative.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.