一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

WordPress后台显示相关用户文章相关联的评论

时间:2013-06-19 编辑:简简单单 来源:一聚教程网

将下面的代码添加到当前主题的 functions.php 文件即可:

 代码如下 复制代码

//后台只显示当前用户文章关联的评论
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站点的数据库前缀。

 

 

热门栏目