From 77e54d99cb7bf91cbec2e123b6c5609bec3637f7 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Thu, 13 Jun 2024 10:12:49 +0200 Subject: [PATCH] Editor: Render editPost slots only in the post editor (same for site editor) --- 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 8d24a51aeb3d8..0e736cb2459ea 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 ; } @@ -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 ; } @@ -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 ; } @@ -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 ; } @@ -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 ; } @@ -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 ; } @@ -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 ; } @@ -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 ; } @@ -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 446ac1860989a..40c8a257ee7d4 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 ; } @@ -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 ; } @@ -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 ; }