[短代码]WordPress作者只能查看自己的评论

不想让所有人都能够看见自己的评论,可以用以下代码来设置权限。

//让作者在 WordPress 后台只能看到自己文章下的评论
function wpdx_get_comment_list_by_user($clauses) {
	if (is_admin()) {
		global $user_ID, $wpdb;
		$clauses['join'] = ", wp_posts";
		$clauses['where'] .= " AND wp_posts.post_author = ".$user_ID." AND wp_comments.comment_post_ID = wp_posts.ID";
	};
	return $clauses;
};
if(!current_user_can('edit_others_posts')) {
	add_filter('comments_clauses', 'wpdx_get_comment_list_by_user');
}

 

版权声明:
作者:月宅
链接:https://blog.moetwo.com/7263.html
来源:月宅酱的博客
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>