Skip to content

Replace deprecated who argument from user query #39986

@grappler

Description

@grappler

What problem does this address?

In WordPress 5.9 the who argument has been deprecated. Trac Ticket

Gutenberg is still using the who argument and recommending it to be used.




authors: getUsers( { who: 'authors' } ),

return select( 'core' ).getUsers( { who: 'authors' } );

What is your proposed solution?

My suggestion would be to use the capability argument. The following code snippet fetches the edit_post capability for the current post type. This code is only compatible with WordPress 5.9. Either Gutenberg will need to increase the minimum supported version or include a check and a fallback with who: 'authors'.

const AUTHORS_QUERY = {
	per_page: 50,
	_fields: 'id,name',
	context: 'edit', // Allows non-admins to perform requests.
};
const currentPostType = wp.data.select('core/editor').getCurrentPostType();
const editPostCap = wp.data.select('core').getPostType( currentPostType ).capabilities.edit_post;
wp.data.select('core').getUsers( { ...AUTHORS_QUERY, capability: [ editPostCap ] } );

So that everyone does not have to figure out the edit_post capability, it might be best to create a helper function. Though in WordPress 5.9 the getAuthors function was deprecated #33725

Related Issues: #39035 & #17364

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions