From 79c00ca887d4c4f5d8a950297230e1bf60f2fc07 Mon Sep 17 00:00:00 2001 From: Riad Benguella <benguella@gmail.com> Date: Mon, 17 Jun 2024 10:15:12 +0200 Subject: [PATCH] Editor: Render editPost slots only in the post editor (same for site editor) (#62531) Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: jeherve <jeherve@git.wordpress.org> Co-authored-by: ndiego <ndiego@git.wordpress.org> --- packages/edit-post/src/deprecated.js | 32 ++++++++++++++++++++++++++++ packages/edit-site/src/deprecated.js | 14 ++++++++++++ 2 files changed, 46 insertions(+) diff --git a/packages/edit-post/src/deprecated.js b/packages/edit-post/src/deprecated.js index 8d24a51aeb3d89..0e736cb2459ea8 100644 --- a/packages/edit-post/src/deprecated.js +++ b/packages/edit-post/src/deprecated.js @@ -12,6 +12,7 @@ import { PluginSidebar as EditorPluginSidebar, PluginSidebarMoreMenuItem as EditorPluginSidebarMoreMenuItem, } from '@wordpress/editor'; +import { getPath } from '@wordpress/url'; import deprecated from '@wordpress/deprecated'; /** @@ -20,6 +21,10 @@ import deprecated from '@wordpress/deprecated'; import { unlock } from './lock-unlock'; const { PluginPostExcerpt } = unlock( editorPrivateApis ); +const isSiteEditor = getPath( window.location.href )?.includes( + 'site-editor.php' +); + const deprecateSlot = ( name ) => { deprecated( `wp.editPost.${ name }`, { since: '6.6', @@ -32,6 +37,9 @@ const deprecateSlot = ( name ) => { * @see PluginBlockSettingsMenuItem in @wordpress/editor package. */ export function PluginBlockSettingsMenuItem( props ) { + if ( isSiteEditor ) { + return null; + } deprecateSlot( 'PluginBlockSettingsMenuItem' ); return <EditorPluginBlockSettingsMenuItem { ...props } />; } @@ -40,6 +48,9 @@ export function PluginBlockSettingsMenuItem( props ) { * @see PluginDocumentSettingPanel in @wordpress/editor package. */ export function PluginDocumentSettingPanel( props ) { + if ( isSiteEditor ) { + return null; + } deprecateSlot( 'PluginDocumentSettingPanel' ); return <EditorPluginDocumentSettingPanel { ...props } />; } @@ -48,6 +59,9 @@ export function PluginDocumentSettingPanel( props ) { * @see PluginMoreMenuItem in @wordpress/editor package. */ export function PluginMoreMenuItem( props ) { + if ( isSiteEditor ) { + return null; + } deprecateSlot( 'PluginMoreMenuItem' ); return <EditorPluginMoreMenuItem { ...props } />; } @@ -56,6 +70,9 @@ export function PluginMoreMenuItem( props ) { * @see PluginPrePublishPanel in @wordpress/editor package. */ export function PluginPrePublishPanel( props ) { + if ( isSiteEditor ) { + return null; + } deprecateSlot( 'PluginPrePublishPanel' ); return <EditorPluginPrePublishPanel { ...props } />; } @@ -64,6 +81,9 @@ export function PluginPrePublishPanel( props ) { * @see PluginPostPublishPanel in @wordpress/editor package. */ export function PluginPostPublishPanel( props ) { + if ( isSiteEditor ) { + return null; + } deprecateSlot( 'PluginPostPublishPanel' ); return <EditorPluginPostPublishPanel { ...props } />; } @@ -72,6 +92,9 @@ export function PluginPostPublishPanel( props ) { * @see PluginPostStatusInfo in @wordpress/editor package. */ export function PluginPostStatusInfo( props ) { + if ( isSiteEditor ) { + return null; + } deprecateSlot( 'PluginPostStatusInfo' ); return <EditorPluginPostStatusInfo { ...props } />; } @@ -80,6 +103,9 @@ export function PluginPostStatusInfo( props ) { * @see PluginSidebar in @wordpress/editor package. */ export function PluginSidebar( props ) { + if ( isSiteEditor ) { + return null; + } deprecateSlot( 'PluginSidebar' ); return <EditorPluginSidebar { ...props } />; } @@ -88,6 +114,9 @@ export function PluginSidebar( props ) { * @see PluginSidebarMoreMenuItem in @wordpress/editor package. */ export function PluginSidebarMoreMenuItem( props ) { + if ( isSiteEditor ) { + return null; + } deprecateSlot( 'PluginSidebarMoreMenuItem' ); return <EditorPluginSidebarMoreMenuItem { ...props } />; } @@ -96,6 +125,9 @@ export function PluginSidebarMoreMenuItem( props ) { * @see PluginPostExcerpt in @wordpress/editor package. */ export function __experimentalPluginPostExcerpt() { + if ( isSiteEditor ) { + return null; + } deprecated( 'wp.editPost.__experimentalPluginPostExcerpt', { since: '6.6', hint: 'Core and custom panels can be access programmatically using their panel name.', diff --git a/packages/edit-site/src/deprecated.js b/packages/edit-site/src/deprecated.js index 446ac1860989a9..40c8a257ee7d4c 100644 --- a/packages/edit-site/src/deprecated.js +++ b/packages/edit-site/src/deprecated.js @@ -6,8 +6,13 @@ import { PluginSidebar as EditorPluginSidebar, PluginSidebarMoreMenuItem as EditorPluginSidebarMoreMenuItem, } from '@wordpress/editor'; +import { getPath } from '@wordpress/url'; import deprecated from '@wordpress/deprecated'; +const isSiteEditor = getPath( window.location.href )?.includes( + 'site-editor.php' +); + const deprecateSlot = ( name ) => { deprecated( `wp.editPost.${ name }`, { since: '6.6', @@ -20,6 +25,9 @@ const deprecateSlot = ( name ) => { * @see PluginMoreMenuItem in @wordpress/editor package. */ export function PluginMoreMenuItem( props ) { + if ( ! isSiteEditor ) { + return null; + } deprecateSlot( 'PluginMoreMenuItem' ); return <EditorPluginMoreMenuItem { ...props } />; } @@ -28,6 +36,9 @@ export function PluginMoreMenuItem( props ) { * @see PluginSidebar in @wordpress/editor package. */ export function PluginSidebar( props ) { + if ( ! isSiteEditor ) { + return null; + } deprecateSlot( 'PluginSidebar' ); return <EditorPluginSidebar { ...props } />; } @@ -36,6 +47,9 @@ export function PluginSidebar( props ) { * @see PluginSidebarMoreMenuItem in @wordpress/editor package. */ export function PluginSidebarMoreMenuItem( props ) { + if ( ! isSiteEditor ) { + return null; + } deprecateSlot( 'PluginSidebarMoreMenuItem' ); return <EditorPluginSidebarMoreMenuItem { ...props } />; }