diff --git a/packages/core-commands/src/admin-navigation-commands.js b/packages/core-commands/src/admin-navigation-commands.js index 4de403761f4cc4..a833ad8c9ad027 100644 --- a/packages/core-commands/src/admin-navigation-commands.js +++ b/packages/core-commands/src/admin-navigation-commands.js @@ -4,20 +4,23 @@ import { useCommand } from '@wordpress/commands'; import { __ } from '@wordpress/i18n'; import { plus, symbol } from '@wordpress/icons'; +import { useSelect } from '@wordpress/data'; +import { store as coreStore } from '@wordpress/core-data'; import { addQueryArgs, getPath } from '@wordpress/url'; import { privateApis as routerPrivateApis } from '@wordpress/router'; /** * Internal dependencies */ -import { useIsTemplatesAccessible } from './hooks'; import { unlock } from './lock-unlock'; const { useHistory } = unlock( routerPrivateApis ); export function useAdminNavigationCommands() { const history = useHistory(); - const isTemplatesAccessible = useIsTemplatesAccessible(); + const canCreateTemplate = useSelect( ( select ) => { + return select( coreStore ).canUser( 'create', 'templates' ); + }, [] ); const isSiteEditor = getPath( window.location.href )?.includes( 'site-editor.php' @@ -45,10 +48,10 @@ export function useAdminNavigationCommands() { icon: symbol, callback: ( { close } ) => { // The site editor and templates both check whether the user - // can read templates. We can leverage that here and this + // can create templates. We can leverage that here and this // command links to the classic dashboard manage patterns page // if the user can't access it. - if ( isTemplatesAccessible ) { + if ( canCreateTemplate ) { const args = { path: '/patterns', }; diff --git a/packages/core-commands/src/hooks.js b/packages/core-commands/src/hooks.js index 6d744e3223234d..0622a970680c11 100644 --- a/packages/core-commands/src/hooks.js +++ b/packages/core-commands/src/hooks.js @@ -4,13 +4,6 @@ import { store as coreStore } from '@wordpress/core-data'; import { useSelect } from '@wordpress/data'; -export function useIsTemplatesAccessible() { - return useSelect( - ( select ) => select( coreStore ).canUser( 'read', 'templates' ), - [] - ); -} - export function useIsBlockBasedTheme() { return useSelect( ( select ) => select( coreStore ).getCurrentTheme()?.is_block_theme, diff --git a/packages/core-commands/src/site-editor-navigation-commands.js b/packages/core-commands/src/site-editor-navigation-commands.js index 695ad00e567203..64e0082d5910a9 100644 --- a/packages/core-commands/src/site-editor-navigation-commands.js +++ b/packages/core-commands/src/site-editor-navigation-commands.js @@ -21,7 +21,7 @@ import { useDebounce } from '@wordpress/compose'; /** * Internal dependencies */ -import { useIsTemplatesAccessible, useIsBlockBasedTheme } from './hooks'; +import { useIsBlockBasedTheme } from './hooks'; import { unlock } from './lock-unlock'; import { orderEntityRecordsBySearch } from './utils/order-entity-records-by-search'; @@ -257,12 +257,14 @@ function useSiteEditorBasicNavigationCommands() { const isSiteEditor = getPath( window.location.href )?.includes( 'site-editor.php' ); - const isTemplatesAccessible = useIsTemplatesAccessible(); + const canCreateTemplate = useSelect( ( select ) => { + return select( coreStore ).canUser( 'create', 'templates' ); + }, [] ); const isBlockBasedTheme = useIsBlockBasedTheme(); const commands = useMemo( () => { const result = []; - if ( ! isTemplatesAccessible || ! isBlockBasedTheme ) { + if ( ! canCreateTemplate || ! isBlockBasedTheme ) { return result; } @@ -339,7 +341,7 @@ function useSiteEditorBasicNavigationCommands() { } ); return result; - }, [ history, isSiteEditor, isTemplatesAccessible, isBlockBasedTheme ] ); + }, [ history, isSiteEditor, canCreateTemplate, isBlockBasedTheme ] ); return { commands, diff --git a/packages/edit-post/src/components/header/more-menu/manage-patterns-menu-item.js b/packages/edit-post/src/components/header/more-menu/manage-patterns-menu-item.js index d12ffb88ae557d..abb009cbc288e8 100644 --- a/packages/edit-post/src/components/header/more-menu/manage-patterns-menu-item.js +++ b/packages/edit-post/src/components/header/more-menu/manage-patterns-menu-item.js @@ -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 ( diff --git a/packages/patterns/src/components/patterns-manage-button.js b/packages/patterns/src/components/patterns-manage-button.js index f2bd798a7b6fad..bab9cab11462ab 100644 --- a/packages/patterns/src/components/patterns-manage-button.js +++ b/packages/patterns/src/components/patterns-manage-button.js @@ -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', } ) diff --git a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js index a535eade291a09..c0138517400fb2 100644 --- a/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js +++ b/packages/reusable-blocks/src/components/reusable-blocks-menu-items/reusable-blocks-manage-button.js @@ -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', } )