对于多作者博客,可以设置 在WordPress后台的文章列表只显示该作者自己的文章,也可以设置 在WordPress后台只显示与当前用户的文章相关联的评论(管理员不限制),具体方法如下:
将下面的代码添加到当前主题的 functions.php 文件即可:
//后台只显示当前用户文章关联的<a href="https://www.wpdaxue.com/tag/%e8%af%84%e8%ae%ba" title="查看与【评论】相关的文章" target="_blank" rel="noopener">评论</a>
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');
} |
//后台只显示当前用户文章关联的<a href="https://www.wpdaxue.com/tag/%e8%af%84%e8%ae%ba" title="查看与【评论】相关的文章" target="_blank" rel="noopener">评论</a>
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');
}
注:如果你的WordPress所使用的数据库前缀不是默认的 wp_,请将第 5 、6 行中的 wp_ 修改为你的WordPress站点的数据库前缀。
该方法在 WP 3.5.1 测试有效。
或者也可以参考下面的方法:https://www.wpdaxue.com/question/11053.html#answer-11073
来源:
https://www.wpdaxue.com/get-comments-list-by-user.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_33214.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57