admin管理员组文章数量:1122832
Hoping someone can offer some code snippet I can use to block other Admins or Editors from editing MY posts.....I use only the Text Editor, but when other users go into my Posts using the Visual Editor, it messes up some of the HTML and code that I've added and I have to spend a lot of time in the Text Editor fixing it.
I don't care if they edit other users' Posts, I just don't want them messing with mine because it causes me too much work. And yes, I've tried - and failed - to train them to simply stay out....the sometimes just don't even look to see who the author is before the go in to edit a Post and don't realize they've screwed it up until I notice it.
Hoping someone can offer some code snippet I can use to block other Admins or Editors from editing MY posts.....I use only the Text Editor, but when other users go into my Posts using the Visual Editor, it messes up some of the HTML and code that I've added and I have to spend a lot of time in the Text Editor fixing it.
I don't care if they edit other users' Posts, I just don't want them messing with mine because it causes me too much work. And yes, I've tried - and failed - to train them to simply stay out....the sometimes just don't even look to see who the author is before the go in to edit a Post and don't realize they've screwed it up until I notice it.
Share Improve this question asked Sep 28, 2021 at 21:22 TrishaTrisha 4282 silver badges11 bronze badges 4- what are you doing that requires lots of custom HTML? – Tom J Nowell ♦ Commented Sep 28, 2021 at 23:28
- Hi Tom, it really isn't anything out of the ordinary, but if I create specifically styled lists (either OL or UL) in the Text Editor, then if someone views it in the Visual Editor, WP both wraps and inserts additional OL or UL tags with a declared style of "list-item-type:none" that overrides my styles....I'm not sure if it's caused by core WP or the Classic Editor plugin, but it's been happening with the last 3 versions.....it happens also if I insert an inline ad between LI items, then WP decides to close the UL, open a new one with different styles, etc. It totally whacks out my lists..... – Trisha Commented Sep 29, 2021 at 22:50
- that is highly unusual and not normal WordPress behaviour. I would also strongly recommend using either the block editor, or the classic editor, but not both. Opening a post written in the block editor using the classic editor can mangle and break blocks. I think you should ask how to fix your problem instead, you've fallen into the X Y trap of asking how to implement a solution to your problem, rather than how to fix the original problem – Tom J Nowell ♦ Commented Sep 30, 2021 at 10:06
- Thanks Tom, we don't use the Block Editor at all. On this site, all users are long-time WP users who unanimously dislike the block editor, despite my encouragement to learn it. SO we use the Classic Editor plugin to maintain the WP experience they know and like. No one uses the Block Editor, but they do use the Visual Editor (vs Text Editor) Tab of the Classic Editor experience. That is what causes the problem. – Trisha Commented Sep 30, 2021 at 18:37
1 Answer
Reset to default 0You can visit - How to assign specific users the capability to edit specific pages / posts / custom post types
OR
First of all: grant full access to projects post type (Example).
At the user profile add allowed posts' id.
Then use the below filter to restrict access if post id isn't allowed.
function allow_user_to_edit_cpt_filter( $capauser, $capask, $param){
global $wpdb;
$allowed_posts_id_for_current_user = array( '29', '30' ); // you need to get these ids yourself
$post = get_post( $param[2] );
// If current post isn't allowed then delete edit and delete capabilities
if( !in_array( $post->ID, $allowed_post_type_ids ) ){
if( ( $param[0] == "edit_projects") || ( $param[0] == "delete_projects" ) ) { // Change to yours capabilities
foreach( (array) $capask as $capasuppr) {
if ( array_key_exists($capasuppr, $capauser) ) {
$capauser[$capasuppr] = 0;
}
}
}
}
return $capauser;
}
add_filter('user_has_cap', 'allow_user_to_edit_cpt_filter', 100, 3 );
Copy answer from How to assign specific users the capability to edit specific pages / posts / custom post types
本文标签: permissionsHow to disable admineditor access to specific user39s posts
版权声明:本文标题:permissions - How to disable admineditor access to specific user's posts 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736289123a1928239.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论