WordPress用户只能查看自己的文章与评论的教程

不管什么需求都可能存在的,就比如WordPress用户只能查看自己的文章与评论,这个需求就是比较少,但是也有很多人希望有的,那么我们该怎么做呢?

把下面的代码复制到主题下面的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');
}

👋 感谢您的观看!

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享