我想允许贡献者只编辑他们自己发布的一些页面。
如果我想允许他们编辑所有已发布的帖子,我可以使用以下内容。如何过滤它,只允许某些pageid?
//to add capability to user
$user = new WP_User( $user_id );
$user->add_cap( \'edit_published_posts\');
我想允许贡献者只编辑他们自己发布的一些页面。
如果我想允许他们编辑所有已发布的帖子,我可以使用以下内容。如何过滤它,只允许某些pageid?
//to add capability to user
$user = new WP_User( $user_id );
$user->add_cap( \'edit_published_posts\');
您可以使用user_has_cap
筛选以动态检查和授予功能。
add_filter(\'user_has_cap\', \'contributor_can_edit_published_posts\', 10, 4);
function contributor_can_edit_published_posts($allcaps, $caps, $args, $user) {
global $post;
// Do we have a post?
if ( ! $post ) {
return $allcaps;
}
// Is the user a contributor?
if ( ! isset( $allcaps[\'contributor\'] ) || true !== $allcaps[\'contributor\'] ) {
return $allcaps;
}
// Is the user the author of the post
if ( $post->post_author != $user->ID ) {
return $allcaps;
}
// Is the contributor allowed to edit this post?
if ( ! in_array( $post->ID, array(1,2,3,4,5) ) ) {
return $allcaps;
}
// Can the user edit published posts already? Allow, if not
if ( ! isset( $allcaps[\'edit_published_posts\'] ) && true !== $allcaps[\'edit_published_posts\'] ) {
$allcaps[\'edit_published_posts\'] = true;
}
return $allcaps;
}
当我今天早上登录我的网站时,我注意到我的用户不能发布任何内容。我是管理员,也是网站上唯一的用户。在帖子和页面上,而不是“发布”,我有“提交以供审阅”按钮,如果单击该按钮,页面将为空,并显示“抱歉,您不允许修改此帖子”。我的所有插件都被禁用了,甚至在缓存重置之后,我也有同样的问题。你能帮帮我吗?编辑:谢谢你的回答,我终于解决了所有问题我找到了答案!在网上漫游之后,我发现了这个页面:https://wpindexfixer.tools.managedwphosting.nl/wpindexfixer/下面是我