我有以下代码可以工作和隐藏(来自非作者)所有页面和帖子在标准WordPress“编辑器”角色登录时显示并尝试在仪表板中查看它们 . 这样,编辑只能看到他们所作的帖子/页面 .
function posts_for_current_author($query) {
if ( !current_user_can( 'update_core' ) ){ //is not admin
global $user_level;
if($query->is_admin) {
global $user_ID;
$query->set('author', $user_ID);
unset($user_ID);
}
unset($user_level);
return $query;
}
}
add_filter('pre_get_posts', 'posts_for_current_author');
我一直在尝试修改此代码以仅隐藏页面而不隐藏帖子 - 但没有成功 .
下面的代码更改会导致编辑器看到所有帖子和页面
if ( !current_user_can( 'update_core' ) && $query->is_page ){ //is not admin is page
我做错了什么?
PS:我知道它现在是什么标准编辑器角色 - 这只是任何自定义角色的一个例子 .
编辑:我找到了一个解决方案,但它并不漂亮:
if ( !current_user_can( 'update_core' ) && $_GET['post_type']=="page"){
如果有人知道更好的方式,我会很感激 . 请注意,我不需要它是超级安全的 .