如何解决此错误?它工作正常,但错误显示给用户。如果我将WP_User_Search更改为WP_User_Query,它就不起作用。错误消失但它不再起作用了。
我正在尝试在编辑帖子时删除作者下拉列表并删除所有管理员名称。
// Remove Admins from Post Author Dropdown
add_filter('wp_dropdown_users', 'theme_post_author_override');
function theme_post_author_override($output)
{
global $post, $user_ID;
// return if this isn't the theme author override dropdown
if (!preg_match('/post_author_override/', $output)) return $output;
// return if we've already replaced the list
if (preg_match ('/post_author_override_replaced/', $output)) return $output;
// replaceme wp_dropdown_users
$admins = getRolesForAuthorList('administrator');
$output = wp_dropdown_users(array(
'exclude' => $admins,
'echo' => '0'
));
// put original back
$output = preg_replace('/post_author_override_replaced/', 'post_author_override', $output);
return $output;
}
function getRolesForAuthorList($role) {
$usersearch = '';
$userspage = '';
$wp_user_search = new WP_User_Search($usersearch, $userspage, $role);
return $wp_user_search->get_results();
}
// Remove Admins from Post Author Dropdown
答案 0 :(得分:0)
// Create the WP_User_Query object
$wp_user_query = new WP_User_Query(array( 'role' => 'Administrator' ));
// Get the results
$authors = $wp_user_query->get_results();