Use the ‘wp_dropdown_users_args’ filter to set the “who” element in the passed array to an empty string to get all users. ('author'
or ''
are the only accepted values) You can set or unset other args elements as desired to get different results. The args are those accepted by get_users()
and WP_User_Query::prepare_query()
https://developer.wordpress.org/reference/classes/wp_user_query/prepare_query/
Hi,
I have copied a snippet from the WordPress site and it does not appear to work still
function wpdocs_add_subscribers_to_dropdown( $query_args ) {
$query_args['role__in'] = array( 'contributor', 'administrator', 'employer' );
$query_args['role__not_in'] = array( 'editor' );
unset( $query_args['who'] );
return $query_args;
}
add_filter( 'wp_dropdown_users_args', 'wpdocs_add_subscribers_to_dropdown' );
This is the code.
Regards,
ben
Hmmm… Looks like the code works for the classic editor and quick edit dialog, but not the block editor. It’s apparently using a different function I’m unfamiliar with 🙁 However, I suspect whatever it is cycles back to instantiating a WP_User_Query
class object. If so, the “pre_get_users” action (ref_array type) could be used to alter the query’s “query_vars” property, which is the array of arguments passed to the object’s constructor.
All sorts of user queries use this class, so you should make efforts to only alter the author dropdown query and no others. The “who” argument/query_var having ‘author’ as a value is a good indicator. Checking the get_current_screen()
return value would be good insurance.