How to include other roles than authors in the Author dropdown in the WordPress post editor

Darko Gjorgjijoski

If you are looking to include non-author roles in WordPress Author metabox dropdown then it requires some coding. By default WordPress includes only authors and probably admins in this list. I am going to write short tutorials for both the classic editor and the Gutenberg block editor.

Classic Editor

Including other roles in the Author metabox when using the Classic editor can be achieved as follows:

/**
 * Filter the Author metabox dropdown in the Classic Editor by role
 *
 * @param $args
 *
 * @return mixed
 */
function dg_dropdown_users_args( $args ) {
	if ( isset( $args['who'] ) ) {
		unset( $args['who'] );
		// define roles here.
		$args['role__in'] = array(
			'administrator',
			'author',
			'editor',
			'subscriber'
		);
	}
	return $args;
}
add_action( 'wp_dropdown_users_args', 'dg_dropdown_users_args', 10, 1 );

Gutenberg Block Editor

Including other roles in the Author metabox when using the Gutenberg Block editor can be achieved as follows:

 

/**
 * Filter the Author metabox dropdown in the Gutenberg editor by role
 *
 * @param array $prepared_args
 * @param WP_REST_Request $request
 *
 * @return array
 */
function dg_rest_user_query( $prepared_args, $request ) {
	if ( isset( $prepared_args['who'] ) && $prepared_args['who'] === 'authors' ) {
		unset( $prepared_args['who'] );
		// define roles here.
		$prepared_args['role__in'] = array(
			'administrator',
			'author',
			'editor',
			'subscriber'
		);
	}
	return $prepared_args;
}
add_filter( 'rest_user_query', 'dg_rest_user_query', 10, 2 );

1 comment

  • Thank you for sharing this solution. There is a small error in the second snippet as it should be $prepared_args[‘role_in’] instead of $args[‘role__in’]

Leave your comment


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Secured By miniOrange