admin管理员组文章数量:1122832
I am using a ACF field on the user profile.php
to assign a post id to a user. The users need to be able to receive the capability to edit this post, but only this post. They should not be allowed to edit any other posts, or see them in the admin.
I cannot do this by simply assigning them as the post author, as there are multiple users per post.
I tried using map_meta_cap
but cannot get it to work.
function my_map_meta_cap( $caps, $cap, $user_id, $args ){
if( user_can($user_id, 'koppel_recht') ) {
return $caps;
}
$currentuser = 'user_' . $user_id;
$koppel = get_field('gekoppeld_register', $currentuser);
if ( 'edit_registers' == $cap || 'edit_others_registers' == $cap ) {
if ( $args[0] != $koppel) {
return [ 'do_not_allow' ];
}
else {
return $caps;
}
}
return $caps;
}
add_filter( 'map_meta_cap', 'my_map_meta_cap', 10, 4 );
koppel_recht is the capability for roles that are allowed to see all the posts in this post type.
本文标签: custom fieldOnly allow users (that are not admins) to edit a specific post
版权声明:本文标题:custom field - Only allow users (that are not admins) to edit a specific post 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736311836a1934881.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论