-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
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.
| who: 'authors', |
| who: 'authors', |
gutenberg/packages/block-library/src/query/edit/inspector-controls/author-control.js
Line 15 in 08cf4a9
| who: 'authors', |
| authors: getUsers( { who: 'authors' } ), |
gutenberg/packages/core-data/README.md
Line 26 in 711ea0e
| 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