As a WordPress developer, sometimes we might need to create a custom post type and set a Subscriber as the Post Author.
For an example, I created a Subscriber.
Add this snippet to functions.php or somewhere else in your plugin file.
// Show all users in 'author' drop down on editor
add_filter( 'wp_dropdown_users_args', function( $query_args, $r ) {
$query_args['who'] = '';
return $query_args;
}, 10, 2 );
The result is that ALL users now appear (including subscribers) in wherever the Post Author should normally appear, in this example — the ‘Quick Editor’.
You could customise this further, to only appear for certain post types, by using the $post global variable to only apply the filter in certain scenarios.
// Show all users in 'author' drop down on editor
add_filter( 'wp_dropdown_users_args', function( $query_args, $r ) {
global $post;
if ( is_object( $post ) && $post->post_type == 'my_custom_post_type_here'){
$query_args['who'] = '';
}
return $query_args; // return needs to sit outside the conditional
}, 10, 2 );
The filter leverages WP_User_Query parameters.
If you want to limit to some roles (including custom roles), do this instead.
// Show AUTHORS and VENDORS in 'author' drop down on editor
add_filter( 'wp_dropdown_users_args', function( $query_args, $r ) {
global $post;
var_dump($query_args);
if ( is_object( $post ) && $post->post_type == 'bill_advert' ){
$query_args['who'] = ''; // reset the query
$query_args['role__in'] = array('Administrator','Editor','Author','Vendor');
}
return $query_args;
}, 10, 2 );