Skip to content

Commit

Permalink
Editor: Render editPost slots only in the post editor (same for site …
Browse files Browse the repository at this point in the history
…editor) (#62531)

Co-authored-by: youknowriad <[email protected]>
Co-authored-by: ellatrix <[email protected]>
Co-authored-by: jeherve <[email protected]>
Co-authored-by: ndiego <[email protected]>
  • Loading branch information
5 people committed Jun 18, 2024
1 parent 69d7fba commit 79c00ca
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/edit-post/src/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
PluginSidebar as EditorPluginSidebar,
PluginSidebarMoreMenuItem as EditorPluginSidebarMoreMenuItem,
} from '@wordpress/editor';
import { getPath } from '@wordpress/url';
import deprecated from '@wordpress/deprecated';

/**
Expand All @@ -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',
Expand All @@ -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 } />;
}
Expand All @@ -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 } />;
}
Expand All @@ -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 } />;
}
Expand All @@ -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 } />;
}
Expand All @@ -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 } />;
}
Expand All @@ -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 } />;
}
Expand All @@ -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 } />;
}
Expand All @@ -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 } />;
}
Expand All @@ -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.',
Expand Down
14 changes: 14 additions & 0 deletions packages/edit-site/src/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 } />;
}
Expand All @@ -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 } />;
}
Expand All @@ -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 } />;
}
Expand Down

0 comments on commit 79c00ca

Please sign in to comment.