-
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
Fix user capabilities check for the Site Editor #61444
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: -7 B (0%) Total Size: 1.74 MB
ℹ️ View Unchanged
|
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.
Looks good to me 👍
packages/core-commands/src/hooks.js
Outdated
@@ -6,7 +6,7 @@ import { useSelect } from '@wordpress/data'; | |||
|
|||
export function useIsTemplatesAccessible() { | |||
return useSelect( | |||
( select ) => select( coreStore ).canUser( 'read', 'templates' ), | |||
( select ) => select( coreStore ).canUser( 'create', 'templates' ), |
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.
The name of the hook is not congruent with what it does. I understand that it's an internal hook so it's not that important but maybe the hook should be renamed?
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.
Indeed. For example, is useCanCreateTemplates
appropriate?
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.
Works for me or even remove the hook entirely. Not sure how useful is it to abstract it.
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.
remove the hook entirely
That makes sense. I would like to merge this PR after removing this hook and switching to an ad hoc approach.
Fixes #61419
What?
This PR correctly checks for non-admin user capabilities for commands and link buttons related to the site editor. This fixes an issue where unintended commands and links are displayed for non-admin users.
Why?
Previously, determining whether the site editor was accessible depended on having permission to "read" templates. However, my understanding is that in #60326, permission to read templates was added for users with
edit_post
permissions.This exposes commands and links that users cannot access even though they do not have
edit_theme_options
permission.How?
Related commands and links now check for "create" permission instead of "read" permission. This should now correctly determine whether users have the
edit_theme_options
permission as before.Testing Instructions
Open the post editor as an admin user and as an editor user and test the following.
Admin
Command
Link button
All links below link to the Site Editor's Patterns page.
Editor
Command
edit.php?post_type=wp_block
.Link button
All links below link to
edit.php?post_type=wp_block
.Note
While creating this PR, I also noticed that individual pages, individual templates, and individual template parts were exposed to non-admin users via the command palette. These are caused by the fact that there is no permission check in the first place, so I would like to fix it in a follow-up PR.