-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Stabilize the useResourcePermissions hook #43268
Conversation
Thank you for going back to make this API stable. I support the idea! Do you know why I would expect to see the JSDoc for the stable now function included in the README file of the As for the dev note, it's something that should be compiled together with other changes to the package – new API for |
@gziolo I just added the README and Changelog entries, good call!
Good call as well, I can see other places where this would be useful. Let's pursue the refactor separately from this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, looks good from my perspective after the revisions were applied.
Good call as well, I can see other places where this would be useful. Let's pursue the refactor separately from this PR
Awesome, it would be great to tackle it in parallel to confirm that the stable API is flexible enough.
Size Change: +657 B (0%) Total Size: 1.24 MB
ℹ️ View Unchanged
|
Here's the PR where I explore the refactor: #43305 |
32b3412
to
7dddad6
Compare
7dddad6
to
a279889
Compare
We have now a few more places to update |
In other news, this is the last task that concludes the proposal from https://make.wordpress.org/core/2022/07/04/proposal-better-rest-api-handling-in-javascript/. The only task left is compiling a dev note covering all final changes and enriching the documentation with the new APIs after WordPress 6.1 is out. Everything here is built on top of existing public APIs, so that means we eventually need to decrease the visibility of low-level APIs in the Block Editor Handbook. Awesome work @adamziel 🚀 |
…useResourcePermissions
Thanks, @adamziel. I agree that the hook was ready for stabilization. The one issue I would like to see resolved, and it's not entirely related to this hook, is the one I mentioned in #35527 (comment). When using this hook, even if you only check for single permission, it will still make multiple calls to the same endpoint. While a few extra API calls aren't necessarily bad, numbers will add up as we continue adoption in the core. Examplevar el = wp.element.createElement;
var __ = wp.i18n.__;
var registerPlugin = wp.plugins.registerPlugin;
var PluginDocumentSettingPanel = wp.editPost.PluginDocumentSettingPanel;
var useResourcePermissions = wp.coreData.useResourcePermissions;
function MyDocumentSettingPlugin() {
// Replace tag ID.
const { canUpdate } = useResourcePermissions( 'tags', 20 );
if ( ! canUpdate ) {
return null;
}
return el(
PluginDocumentSettingPanel,
{
className: 'my-document-setting-plugin',
title: 'Permissions',
},
__( 'User has required Permissions' )
);
}
registerPlugin( 'my-document-setting-plugin', {
render: MyDocumentSettingPlugin,
} ); |
@Mamaduka good note! As you noticed, it is not specific to this hook - see this patch for |
Dev note proposed at https://make.wordpress.org/core/?p=99829&preview=1&_ppp=2b1db975ea |
What?
It's been two months since the
__experimentalUseResourcePermissions
hook was introduced in PR #38785. This PR stabilizes it.CC @gziolo @Mamaduka @kevin940726