将此代码添加到函数中。php。它检查用户是否是管理员,或者是否可以调节其他用户的帖子。
Reference is here from WP Forum:
/* ------------------------------------------------------------
* Ensure that non-admins can see and manage only their own comments
*/ ------------------------------------------------------------
function myplugin_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;
};
// ensure that editors and admins can moderate everything
if(!current_user_can(\'edit_others_posts\')) {
add_filter(\'comments_clauses\', \'myplugin_get_comment_list_by_user\');
}
然而,$wpdb是一个非常强大的工具,可以运行到您的数据库中。你可以使用下面的功能:它的工作方式与上面类似,检查用户是否可以编辑其他帖子或是管理员。否则它只返回他们的帖子。
Reference: From wpbeginner 函数posts\\u for\\u current\\u author($query){global$pagenow;
if( \'edit.php\' != $pagenow || !$query->is_admin )
return $query;
if( !current_user_can( \'edit_others_posts\' ) ) {
global $user_ID;
$query->set(\'author\', $user_ID );
}
return $query;
}
add_filter(\'pre_get_posts\', \'posts_for_current_author\');