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 <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>
  • Loading branch information
5 people authored Jun 17, 2024
1 parent 9c1b097 commit bb92727
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

1 comment on commit bb92727

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in bb92727.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9544256337
📝 Reported issues:

Please sign in to comment.