如果用户在管理页面中拥有“Contributor”权限可以查看等待审核的评论,但我需要禁用此选项。WordPress贡献者审核评论
在具有“查看评论等待审核”的用户角色中,它不存在任何内容。
如何为Contributor用户禁用/wp-admin/edit-comments.php?comment_status=moderated?
如果用户在管理页面中拥有“Contributor”权限可以查看等待审核的评论,但我需要禁用此选项。WordPress贡献者审核评论
在具有“查看评论等待审核”的用户角色中,它不存在任何内容。
如何为Contributor用户禁用/wp-admin/edit-comments.php?comment_status=moderated?
修改意见查询
这里有一个建议,调整为get_comments()
输入参数注释状态,与pre_get_comments
行动的帮助:
add_action('pre_get_comments', function(\WP_Comment_Query $query)
{
// Only target edit-comments.php
if(! did_action('load-edit-comments.php'))
return;
// Only target users that can't publish posts
if(current_user_can('publish_posts'))
return;
// Halt the query for pending comments
if('hold' === $query->query_vars['status'])
$query->query_vars['status'] = 'non-existent';
// Remove pending comments from the 'all' or '' status view
if(in_array($query->query_vars['status'], [ 'all', '' ], true))
$query->query_vars['status'] = 'approve';
});
,我们的目标只有edit-comments.php
页并将状态修改为approve
(如果为空)或'all'
(对于无法发布帖子的用户)。 在这里,我们将评论状态分配到一个不存在的状态,以删除挂起评论列表。
它可能有点混淆等待评论的所有各种状态值,例如,
hold, pending, moderated, '0'
取决于它是否是一个标签,注释查询变量,或者它是如何存储在数据库中,
修改意见数
所有评论这里算:
mean是Approved + Pending
评论数的总和。
当我们更改评论查询时,如上所述,这些评论状态计数不会改变。我们可能也想调整一下。
下面是一个例子,我们如何可以通过wp_count_comments
过滤器调整的评论数:
add_filter('wp_count_comments', 'wpse_count_comments', 10, 2);
function wpse_count_comments($counts, $post_id )
{
// Only target the backend
if(! is_admin())
return $counts;
// Only target users that can't publish posts
if(current_user_can('publish_posts'))
return $counts;
// Avoid infinite loop before calling wp_count_comments()
remove_filter(current_filter(), __FUNCTION__);
$counts = wp_count_comments($counts, $post_id );
add_filter(current_filter(), __FUNCTION__, 10, 2);
// Subract 'moderated' count from 'all' count
$counts->all = $counts->all - $counts->moderated;
// Set 'moderated' count to zero
$counts->moderated = 0;
return $counts;
}
这也将清除计数,不能发布帖子的用户,从这里的管理菜单:
修改注释状态链接
最后,我们可能要删除未决注释的状态链接,对于不能发布帖子的用户:
add_filter('comment_status_links', function($status)
{
if(! current_user_can('publish_posts'))
unset($status['moderated']);
return $status;
});
因此,这将成为:
希望它能帮助!
你可以使用JavaScript添加脚本只用于记录与贡献者的角色与DOM未经批准的类删除注释行用户绕过它。
检查,如果用户登录并贡献者:
if(is_user_logged_in() && current_user_can('contributor')) {
然后添加脚本在线或排队与follwing代码js文件:
$('#the-comment-list tr.unapproved').remove();
检查,如果该评论是在任何可见其他视图并将相应的类添加到脚本中,以便将它们随处移除
/*编辑*/
香草js脚本:
var elem = document.getElementById("the-comment-list");
for (var i = 0; i < elem.childNodes.length; i++) {
if (/\bunapproved/.test(elem.childNodes[i].className)) {
elem.childNodes[i].parentNode.removeChild(elem.childNodes[i]);
}
}
此功能没有配置贡献者看到图像,投稿人可以不适度的评论只看到等待审核的评论,谢谢=( – user3477026
function.php 功能frontfooter(){ 回声“” } 如果(is_user_logged_in()&& current_user_can。':$是不是一个功能 – user3477026
我尝试添加jQuery的管理,但不是一个好主意=( – user3477026
我发现这半的解决方案,从评论管理列表的代码隐藏评论,但它删除所有评论也主持评论,其确定现在=)
https://wordpress.stackexchange.com/questions/167250/prevent-contributor-to-show-comment-list
function filter_comments_by_contributor($all_comments) {
// get the current logged in user
$current_user = wp_get_current_user();
if (0 == $current_user->ID) {
// Not logged in.
return $all_comments;
} else {
// Logged in.
// check if the logged-in user is a contributor
if (in_array('contributor', (array) $current_user->roles)) {
// check if the user is on wp-admin backend,
$screen = get_current_screen();
if (! empty($screen) && 'edit-comments' == $screen->id) {
// get all posts by that contributor
$args = array(
'author' => $current_user->ID,
'posts_per_page' => - 1,
'fields' => 'ids'
);
$contributor_posts = get_posts($args);
// unset the comments given on posts other than his/her.
foreach ($all_comments as $key => $value) {
if (! in_array($value->comment_post_ID, $contributor_posts)) {
unset($all_comments[ $key ]);
}
}
}
return $all_comments;
} else {
return $all_comments;
}
}
}
if(is_user_logged_in() && !current_user_can('manage_options')) {
add_filter('the_comments', 'filter_comment_by_contributor');
}
我建议你使用user role editor会对一般用户的角色完整的控制和一些例外添加到特定的用户。
哇,完美!谢谢! – user3477026