File size: 885 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import { useSelect } from '@wordpress/data';
import domReady from '@wordpress/dom-ready';
import { registerPlugin } from '@wordpress/plugins';
import { usePreviewingThemeSlug } from './hooks/use-previewing-theme';
import LivePreviewNoticePlugin from './live-preview-notice-plugin';
const LivePreviewPlugin = () => {
const siteEditorStore = useSelect( ( select ) => select( 'core/edit-site' ), [] );
const previewingThemeSlug = usePreviewingThemeSlug();
// Do nothing outside the Site Editor context.
if ( ! siteEditorStore ) {
return null;
}
// Don't render unless the user is previewing a theme.
if ( ! previewingThemeSlug ) {
return null;
}
return <LivePreviewNoticePlugin />;
};
const registerLivePreviewPlugin = () => {
registerPlugin( 'wpcom-live-preview', {
render: () => <LivePreviewPlugin />,
} );
};
domReady( () => {
registerLivePreviewPlugin();
} );
|