关键词:
【中文标题】WordPress 贡献者审核评论【英文标题】:WordPress Contributor Moderation Comments 【发布时间】:2017-06-13 14:23:51 【问题描述】:如果用户在管理页面中拥有“贡献者”权限,则可以查看等待审核的 cmets,但我需要禁用此功能。
在具有“View cmets Awaiting Moderation”的用户角色中,它不存在任何内容。
如何为贡献者用户禁用 /wp-admin/edit-cmets.php?comment_status=moderated?
【问题讨论】:
【参考方案1】:修改 cmets 查询
这里有一个建议,在 pre_get_comments
操作的帮助下调整 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'
(对于无法发布帖子的用户)。
这里我们将评论状态分配为不存在状态以删除待处理的 cmets 列表。
pending cmets 的所有各种状态值可能会有点混乱,例如
hold, pending, moderated, '0'
取决于它是标签、评论查询变量还是它在数据库中的存储方式,
修改 cmets 计数
所有 cmets 都在这里计算:
表示Approved + Pending
cmets 计数的总和。
当我们像上面一样更改评论查询时,这些评论状态计数不会改变。我们可能也想调整它。
这是一个示例,我们如何通过 wp_count_comments
过滤器调整 cmets 计数:
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;
这也将从此处的管理菜单中删除无法发布帖子的用户的计数:
修改评论状态链接
最后,对于无法发布帖子的用户,我们可能希望删除 pending cmets 的状态链接:
add_filter( 'comment_status_links', function( $status )
if( ! current_user_can( 'publish_posts' ) )
unset( $status['moderated'] );
return $status;
);
所以会变成:
希望对你有帮助!
【讨论】:
哇,完美!谢谢!【参考方案2】:您可以使用 javascript 绕过它,仅为具有贡献者角色的登录用户添加脚本,从 dom 中删除具有未批准类的评论行。
检查用户是否已登录并且是贡献者:
if( is_user_logged_in() && current_user_can('contributor'))
然后使用以下代码添加内联脚本或将 js 文件排入队列:
$('#the-comment-list tr.unapproved').remove();
检查 cmets 在任何其他视图中是否可见,并将相应的类添加到脚本中以从任何地方删除它们
/* 编辑 */
原版 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]);
【讨论】:
贡献者未配置此功能查看图片,贡献者无法审核 cmets 只能看到等待审核的 cmets,谢谢 =( function.php function frontfooter() echo ""; if( is_user_logged_in() && current_user_can('contributor')) add_action('admin_footer', 'frontfooter'); 返回:$ 不是函数 好的,它的工作很完美,但是如果我打开一个页面,会显示 cmets 并在 1 毫秒后被删除,慢动作可以捕获所有评论。 肯定有一种方法可以在后端实现这一点,而不会显示未经批准的 cmets,但我想这可能是一个临时解决方案,直到您找到更好的解决方案。 ;)【参考方案3】:我找到了这个半解决方案,这段代码从评论审核列表中隐藏了评论,但它删除了所有评论和审核的评论,现在还可以 =)
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' );
【讨论】:
【参考方案4】:我建议您使用user role editor 来全面控制用户角色,并为特定用户添加一些例外。
【讨论】:
Facebook 评论审核工具
】Facebook评论审核工具【英文标题】:Facebookcommentmoderationtool【发布时间】:2011-12-0912:07:54【问题描述】:我刚刚添加了facebookcmets插件,我看到了用户的第一条评论。但是如果我去http://developers.facebook.com/tools/comments没有任何最近... 查看详情
php[wordpress]禁用wordpress评论(代码片段)
优化 WordPress 插件“更好的 WordPress 最近评论”中的慢查询
】优化WordPress插件“更好的WordPress最近评论”中的慢查询【英文标题】:OptimizeslowqueryinWordPressplugin"BetterWordPressRecentComments"【发布时间】:2015-12-3103:36:44【问题描述】:我正在优化针对MySQL的查询,我的慢查询日志显示Word... 查看详情
需要有关 SQL 查询以进行评论审核的帮助
】需要有关SQL查询以进行评论审核的帮助【英文标题】:NeedhelpwithSQLqueryforcommentsmoderation【发布时间】:2011-10-1114:13:03【问题描述】:我正在开发一个cmets审核系统作为我网站的一部分,因此我可以在cmets发布之前查看它们的列表... 查看详情
完全禁用wordpress评论
Allyouneedtodoiscreateachildtheme,andcreateanewcomments.phpfileinsidethatchildtheme.Theninsertthiscodeintothecomments.phpfileyoujustcreated;<?phpreturnfalse;?> 查看详情
wordpress主题开发:评论框
...件,(如多说、畅言、友言等等)1、下载多说插件:https://wordpress.org/plugins/duoshuo/,把插件解压到在wp目录/wp-content/plugins下或在WordPress后台“安装插件”中 查看详情
已审核的宝石 添加关于销毁的评论
】已审核的宝石添加关于销毁的评论【英文标题】:AuditedGemAddCommentonDestroy【发布时间】:2021-11-1919:58:37【问题描述】:我已实施Audited,一切正常。我唯一不知道的是如何在删除记录时添加“audit_comment”。我可以在更新或创建... 查看详情
将来自 Linkedin 帖子的评论整合回 Wordpress
】将来自Linkedin帖子的评论整合回Wordpress【英文标题】:IntegratingcommentsfromLinkedinpostsbackintoWordpress【发布时间】:2019-09-0706:55:40【问题描述】:我一直在为我的wordpress博客网站寻找一个好的和完美的评论系统。我也在wordpress网站... 查看详情
WordPress:列出没有评论的帖子
】WordPress:列出没有评论的帖子【英文标题】:WordPress:Listpostswithnocomments【发布时间】:2011-06-1707:34:06【问题描述】:我有一个简单的页面,我想显示尚未评论的帖子列表。我该怎么做?我认为这是我可以添加到query_posts的一些... 查看详情
评论框放错地方wordpress
】评论框放错地方wordpress【英文标题】:Thecommentboxplacedinthewrongplacewordpress【发布时间】:2021-05-0609:19:29【问题描述】:我想在wordpress中添加一个带有此功能的新短代码,主题是平坦的,并在手风琴的所需位置显示评论框,但是... 查看详情
Facebook 评论审核、appid 或 Facebook 页面?
】Facebook评论审核、appid或Facebook页面?【英文标题】:Facebookcommentsmoderation,appidorfacebookpage?【发布时间】:2011-07-2214:56:51【问题描述】:我希望将Facebookcmets添加到我们网站的某些页面。我知道我可以通过在这里使用生成器为我想... 查看详情
检查是否有评论wordpress
<?phpif(get_comments_number()==0){//posthasnocomments}else{//posthascomments}?> 查看详情
php完全禁用wordpress评论(代码片段)
phpfacebook对wordpress的评论(代码片段)
带有年、月、日、帖子和评论计数的 Wordpress 存档列表
】带有年、月、日、帖子和评论计数的Wordpress存档列表【英文标题】:Wordpressarchivelistwithyear,month,days,postsandcommentcounts【发布时间】:2013-05-0420:56:21【问题描述】:我愿意实现这样的Wordpress存档列表:20135月(2)04-我喜欢Wordpress(3cm... 查看详情
在 wordpress 主页上显示评论
】在wordpress主页上显示评论【英文标题】:Showcommentsonwordpresshomepage【发布时间】:2011-09-0611:51:58【问题描述】:所以我已将以下代码插入到模板循环中(在正确的位置),但它没有输出任何cmets。有什么线索吗?<?php$withcomments... 查看详情
从 WordPress 中删除所有评论数据
】从WordPress中删除所有评论数据【英文标题】:DeletingallcommentdatafromWordPress【发布时间】:2011-08-1900:02:04【问题描述】:我已经使用SQL命令从我的WordPress站点中删除了所有cmets,wp_cmets和wp_commentmeta都是空的。这已经删除了所有的c... 查看详情
循环获取 Wordpress 页面的“最新评论日期”
】循环获取Wordpress页面的“最新评论日期”【英文标题】:Get"latestcommentdate"ofaWordpresspageinaloop【发布时间】:2022-01-0103:54:04【问题描述】:有没有一种简单的方法可以获取wordpress页面的“最新评论日期”?对于页面本身... 查看详情