Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Render editPost slots only in the post editor (same for site editor) #62531

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading