Skip to content

Fix user capabilities check for the Site Editor #61444

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

Merged
merged 3 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core-commands/src/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

[]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function ManagePatternsMenuItem() {
// The site editor and templates both check whether the user has
// edit_theme_options capabilities. We can leverage that here and not
// display the manage patterns link if the user can't access it.
return canUser( 'read', 'templates' ) ? patternsUrl : defaultUrl;
return canUser( 'create', 'templates' ) ? patternsUrl : defaultUrl;
}, [] );

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/patterns/src/components/patterns-manage-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function PatternsManageButton( { clientId } ) {
// The site editor and templates both check whether the user
// has edit_theme_options capabilities. We can leverage that here
// and omit the manage patterns link if the user can't access it.
managePatternsUrl: canUser( 'read', 'templates' )
managePatternsUrl: canUser( 'create', 'templates' )
? addQueryArgs( 'site-editor.php', {
path: '/patterns',
} )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function ReusableBlocksManageButton( { clientId } ) {
// The site editor and templates both check whether the user
// has edit_theme_options capabilities. We can leverage that here
// and omit the manage patterns link if the user can't access it.
managePatternsUrl: canUser( 'read', 'templates' )
managePatternsUrl: canUser( 'create', 'templates' )
? addQueryArgs( 'site-editor.php', {
path: '/patterns',
} )
Expand Down