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
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
Share Improve this question edited Oct 28, 2019 at 19:42 Johnx asked Oct 28, 2019 at 19:29 JohnxJohnx 11 bronze badge 3 |1 Answer
Reset to default 0You 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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745048704a4608253.html
register_post_type
, or rather that's not what it means. You're telling it what capability it is, not what it isn't. I'm not sure it's possible to only edit and not create, editing vs adding in WP is very similar with very few differences between the two – Tom J Nowell ♦ Commented Oct 28, 2019 at 20:40