Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated who argument from user query #39986

Open
grappler opened this issue Apr 1, 2022 · 4 comments
Open

Replace deprecated who argument from user query #39986

grappler opened this issue Apr 1, 2022 · 4 comments
Labels
Needs Technical Feedback Needs testing from a developer perspective. [Package] Block library /packages/block-library [Package] Editor /packages/editor REST API Interaction Related to REST API [Type] Enhancement A suggestion for improvement.

Comments

@grappler
Copy link
Member

grappler commented Apr 1, 2022

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

@grappler grappler changed the title Replace deprecated who: authors from user quers Replace deprecated who argument from user query Apr 1, 2022
@ndiego ndiego added the Needs Technical Feedback Needs testing from a developer perspective. label Apr 4, 2022
@ocean90 ocean90 added REST API Interaction Related to REST API [Package] Editor /packages/editor [Package] Block library /packages/block-library labels Apr 4, 2022
@ocean90
Copy link
Member

ocean90 commented Apr 4, 2022

Noting that the current request already generates a X-WP-DeprecatedParam header for this:

X-WP-DeprecatedParam: WP_User_Query (since 5.9.0; <code>who</code> is deprecated. Use <code>capability</code> instead.)

@TimothyBJacobs @spacedmonkey @youknowriad Do you have some ideas how we can detect whether who or capability should be used?

@TimothyBJacobs
Copy link
Member

I'm not sure what the progress is on the client having knowledge of the REST API schemas, cc @youknowriad. But the best way would be to look at the schema for the endpoint and check for the presence of the capability property in the GET args.

@grappler
Copy link
Member Author

The only reason that I can see why we would need to check for the support is to be able to run the Gutenberg plugin on WordPress 5.8. Depending on the time it takes for a patch, WordPress 6.0 will have been released.

It might make more sense to increase the minimum required WP version.

* Requires at least: 5.8

@ocean90
Copy link
Member

ocean90 commented Sep 1, 2022

As of #41306 the plugin now requires 5.9 so I guess we can switch the query to use capability now.

@jordesign jordesign added the [Type] Enhancement A suggestion for improvement. label Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Technical Feedback Needs testing from a developer perspective. [Package] Block library /packages/block-library [Package] Editor /packages/editor REST API Interaction Related to REST API [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

5 participants