admin管理员组文章数量:1125544
I would like to display only authors own posts in dashboard all posts section. As of now it displays everything.
I found some code here which is written by @t31os Its working correctly.
function posts_for_current_author($query) {
global $user_level;
if($query->is_admin && $user_level < 5) {
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');
But user_level is deprecated. So can anyone modify the code for new version? Thanks
I would like to display only authors own posts in dashboard all posts section. As of now it displays everything.
I found some code here which is written by @t31os Its working correctly.
function posts_for_current_author($query) {
global $user_level;
if($query->is_admin && $user_level < 5) {
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');
But user_level is deprecated. So can anyone modify the code for new version? Thanks
Share Improve this question asked Dec 31, 2011 at 17:53 PrivateUserPrivateUser 3,46910 gold badges54 silver badges85 bronze badges 7 | Show 2 more comments1 Answer
Reset to default 5The following worked for me to show only the current user's posts in the admin
add_action( 'load-edit.php', 'posts_for_current_author' );
function posts_for_current_author() {
global $user_ID;
/*if current user is an 'administrator' do nothing*/
//if ( current_user_can( 'add_users' ) ) return;
/*if current user is an 'administrator' or 'editor' do nothing*/
if ( current_user_can( 'edit_others_pages' ) ) return;
if ( ! isset( $_GET['author'] ) ) {
wp_redirect( add_query_arg( 'author', $user_ID ) );
exit;
}
}
It can be edited pretty easily if the restriction should only happen for users in a particular role.
本文标签: deprecationDisplay only author posts in dashboard all posts panel
版权声明:本文标题:deprecation - Display only author posts in dashboard all posts panel 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736626973a1945694.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$user_level
is deprecated, you might be able to check for it's role(s) then instead. – hakre Commented Dec 31, 2011 at 18:36$user_level
with the appropriate role, see Roles and Capabilities: User Levels which level relates to which role. – hakre Commented Dec 31, 2011 at 19:20