WordPress后台文章列表添加作者筛选
方法一:文章列表添加作者筛选,所有用户可见
把下面该代码应放在你的主题的functions.php文件中或者通过某些插件来添加。
//WordPress后台文章列表添加作者筛选
add_action('restrict_manage_posts', function($post_type){
if(post_type_supports($post_type, 'author')){
wp_dropdown_users([
'name' => 'author',
'who' => 'authors',
'show_option_all' => '所有作者',
'hide_if_only_one_author' => true,
'selected' => $_REQUEST['author'] ?? 0
]);
}
});
方法二:文章列表添加作者筛选,只对管理员和编辑角色可见
add_action('restrict_manage_posts', function($post_type){
// 检查当前用户是否有管理员或编辑权限
if(!current_user_can('edit_others_posts')) {
return;
}
if(post_type_supports($post_type, 'author')){
wp_dropdown_users([
'name' => 'author',
'who' => 'authors',
'show_option_all' => '所有作者',
'hide_if_only_one_author' => true,
'selected' => $_REQUEST['author'] ?? 0
]);
}
});