我试图找到一种方法/插件,使投稿人的帖子只能由特定的用户编辑器编辑或发布。
例如,如果我有一个名为Steve的撰稿人和一个名为Bob的编辑,那么Steve的帖子/草稿只能由分配给撰稿人的Bob审阅和发布。没有其他编辑(当然除了管理员)可以“触摸”史蒂夫的作品,只有鲍勃可以。
这可能吗?我尝试了插件成员,但我只能将参与者帖子的审阅和发布限制为用户角色,而不是特定用户。
我试图找到一种方法/插件,使投稿人的帖子只能由特定的用户编辑器编辑或发布。
例如,如果我有一个名为Steve的撰稿人和一个名为Bob的编辑,那么Steve的帖子/草稿只能由分配给撰稿人的Bob审阅和发布。没有其他编辑(当然除了管理员)可以“触摸”史蒂夫的作品,只有鲍勃可以。
这可能吗?我尝试了插件成员,但我只能将参与者帖子的审阅和发布限制为用户角色,而不是特定用户。
您没有说明如何保存编辑器->贡献者关联,我假设您将其存储在带有键的用户元字段中\'assigned_contrib\'
其中保存参与者用户id的数组。
首先,使用pre_get_posts
挂钩:
add_action(\'pre_get_posts\', \'hide_posts_to_editors\');
function hide_posts_to_editors( $query ) {
if ( is_admin() && ! current_user_can(\'administrator\') ) {
$self = wp_get_current_user();
$assigned_contributors = (array) get_user_meta($self->ID, \'assigned_contrib\', true);
$authors = array_merge($self->ID, $assigned_contributors);
$query->set( \'author\', implode(\',\', $authors) );
}
}
这样,编辑只能在自己写的管理帖子和指定编辑写的帖子中看到。但这并不能阻止知道帖子id的编辑通过在地址栏中手动插入id来编辑帖子。。。您可以使用load_{$page}
action hook 对于范围,在这种情况下(\'load-post.php\'
)
add_action(\'load-post.php\', \'no_editors_edit\', 1);
function no_editors_edit() {
if ( current_user_can(\'administrator\') ) return;
$post = isset($_GET[\'post\']) && ! empty($_GET[\'post\']) ? $_GET[\'post\'] : false;
if ( ! $post ) return;
$author = get_post_field(\'post_author\', $post);
$self = wp_get_current_user();
$assigned_contributors = (array) get_user_meta($self->ID, \'assigned_contrib\', true);
if ( ( $author != $self->ID ) && ! in_array($author, $assigned_contributors) ) {
wp_redirect( add_query_arg( array(\'edit_not_allowed\'=>1), admin_url() ) );
exit();
}
}
如果发生这种情况,请添加通知。。。add_action(\'admin_notices\', \'no_editors_edit_notice\');
no_editors_edit_notice() {
if ( isset($_GET[\'edit_not_allowed\'] && $_GET[\'edit_not_allowed\'] == 1) ) {
printf(\'<div class="error"><p>%s</p></div>\', __(\'You are allowed to edit only your posts and the ones by contributors assigned to you.\', \'your_text_domain\'));
}
}
我有一个选项卡切换主题,允许用户在添加新页面时选择3种编辑模式(HTML和视觉-这些是WP默认值和使用代码镜像的新语法模式)。我在从语法切换回HTML和可视化时遇到问题。选项卡切换似乎不稳定,编辑器没有恢复到正常的WP默认行为。我计划使用默认的switchEditors。切换到可湿性粉剂的功能,但我不知道我想给它提供什么参数。有人能给我举个例子,如何在自定义JS函数中使用这个函数(比如在主题中?)谢谢