Open grappler opened 2 years ago
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?
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.
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. https://github.com/WordPress/gutenberg/blob/956a836ce8fcdd61b186cf1c2d1047b48126898d/gutenberg.php#L6
As of #41306 the plugin now requires 5.9 so I guess we can switch the query to use capability
now.
What problem does this address?
In WordPress 5.9 the
who
argument has been deprecated. Trac TicketGutenberg is still using the
who
argument and recommending it to be used. https://github.com/WordPress/gutenberg/blob/08cf4a96d1f14fcdf4c55886ba237fb294f9c465/packages/editor/src/components/post-author/constants.js#L2 https://github.com/WordPress/gutenberg/blob/23f11a18726bf69717595451ab3250cb67b426f6/packages/block-library/src/avatar/user-control.js#L11 https://github.com/WordPress/gutenberg/blob/08cf4a96d1f14fcdf4c55886ba237fb294f9c465/packages/block-library/src/query/edit/inspector-controls/author-control.js#L15 https://github.com/WordPress/gutenberg/blob/760815a731805fa05f6cbb234660b254ad1ca6c9/packages/block-library/src/post-author/edit.js#L43 https://github.com/WordPress/gutenberg/blob/711ea0eda4e3b4d28b9e0d70723ec04622dec278/packages/core-data/README.md?plain=1#L26What 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 withwho: 'authors'
.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 thegetAuthors
function was deprecated https://github.com/WordPress/gutenberg/pull/33725Related Issues: https://github.com/WordPress/gutenberg/issues/39035 & https://github.com/WordPress/gutenberg/issues/17364