From a2d25968a140e7d4f2f75ec50b683463f0259378 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Thu, 19 Dec 2024 14:33:23 +0000 Subject: [PATCH] cehck for permissions --- .../edit-post/src/components/layout/index.js | 5 +++++ .../editor/src/components/provider/index.js | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/edit-post/src/components/layout/index.js b/packages/edit-post/src/components/layout/index.js index b0a2b3f7d76b81..2582f39476c528 100644 --- a/packages/edit-post/src/components/layout/index.js +++ b/packages/edit-post/src/components/layout/index.js @@ -400,6 +400,10 @@ function Layout( { kind: 'postType', name: 'wp_template', } ); + const canDiscoverTemplate = canUser( 'read', { + kind: 'root', + name: 'site', + } ); const { isZoomOut } = unlock( select( blockEditorStore ) ); const { getEditorMode, getRenderingMode } = select( editorStore ); const isRenderingPostOnly = getRenderingMode() === 'post-only'; @@ -421,6 +425,7 @@ function Layout( { supportsTemplateMode && isViewable && canViewTemplate && + canDiscoverTemplate && ! isEditingTemplate ? getTemplateId( currentPostType, currentPostId ) : null, diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index 11f02279ac6ebd..389435c5bf4c29 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -163,6 +163,7 @@ export const ExperimentalEditorProvider = withRegistryProvider( BlockEditorProviderComponent = ExperimentalBlockEditorProvider, __unstableTemplate: template, } ) => { + const hasTemplate = !! template; const { editorSettings, selection, @@ -193,11 +194,8 @@ export const ExperimentalEditorProvider = withRegistryProvider( hasLoadedPostObject: _hasLoadedPostObject, editorSettings: getEditorSettings(), isReady: __unstableIsEditorReady(), - mode: template ? getRenderingMode() : 'post-only', - defaultMode: - template && postTypeObject?.default_rendering_mode - ? postTypeObject?.default_rendering_mode - : 'post-only', + mode: getRenderingMode(), + defaultMode: postTypeObject?.default_rendering_mode, selection: getEditorSelection(), postTypeEntities: post.type === 'wp_template' @@ -205,7 +203,7 @@ export const ExperimentalEditorProvider = withRegistryProvider( : null, }; }, - [ template, post.type ] + [ post.type ] ); const shouldRenderTemplate = !! template && mode !== 'post-only'; @@ -329,14 +327,19 @@ export const ExperimentalEditorProvider = withRegistryProvider( // Sets the right rendering mode when loading the editor. useEffect( () => { - setRenderingMode( defaultMode ); - }, [ defaultMode, setRenderingMode ] ); + setRenderingMode( hasTemplate ? defaultMode : 'post-only' ); + }, [ hasTemplate, defaultMode, setRenderingMode ] ); useHideBlocksFromInserter( post.type, mode ); // Register the editor commands. useCommands(); + console.log( { + notRender: ! isReady || ! mode || ! hasLoadedPostObject, + settings: ! settings.isPreviewMode, + } ); + if ( ! isReady || ! mode || ! hasLoadedPostObject ) { return null; }