Untitled
/** * Template Option Panel */ const { useMemo } = wp.element; const { ToggleControl } = wp.components; const { PluginDocumentSettingPanel } = wp.editPost || {}; const { registerPlugin } = wp.plugins; const { __ } = wp.i18n; const { select, useSelect, useDispatch } = wp.data; const { templateOptionsPostTypes, templateOptionsMetaKeys: { no_header_nav_key, no_footer_nav_key, no_network_nav_key, simplified_footer_key, } } = BLACKSTONE_EDITOR; /** * Output the template options sidebar panel */ function TemplateOptions() { const { editPost } = useDispatch( 'core/editor' ); if (!PluginDocumentSettingPanel) { return null; } const currentTemplate = useSelect( ( select ) => select( 'core/editor' ).getEditedPostAttribute( 'template' ) ); const meta = useSelect( ( select ) => select( 'core/editor' ).getEditedPostAttribute( 'meta' ) ); const noHeaderNavValue = useMemo( () => { if (meta != null) { return meta[ no_header_nav_key ] || ''; } }, [meta] ); const noFooterNavValue = useMemo( () => { if (meta != null) { return meta[ no_footer_nav_key ] || ''; } }, [meta] ); // Check if the current site is 'bmacx' const isBmacxSite = window.location.hostname === 'bmacx'; // Adjust this condition based on how you identify the 'bmacx' site // Set the default based on legacy page template. let noHeaderNavDefault = 'templates/page-no-header-navigation.php' === currentTemplate || 'templates/page-no-header-footer-navigation.php' === currentTemplate; let noFooterNavDefault = 'templates/page-no-header-footer-navigation.php' === currentTemplate; if (noHeaderNavDefault) { editPost({ meta: { ...meta, [ no_header_nav_key ]: 1, }, template: '', }); } if (noFooterNavDefault) { editPost({ meta: { ...meta, [ no_footer_nav_key ]: 1, }, template: '', }); } return ( <PluginDocumentSettingPanel name="blackstone-template-options-panel" title={ __( 'Template Options', 'blackstone' ) } > {/* Display only No Header and No Footer options for bmacx site */} {isBmacxSite ? ( <> <ToggleControl checked={ noHeaderNavValue } onChange={ (nextValue) => { editPost({ meta: { ...meta, [ no_header_nav_key ]: nextValue, }, }); }} label={ __( 'No Header Navigation', 'blackstone' ) } /> <ToggleControl checked={ noFooterNavValue } onChange={ (nextValue) => { editPost({ meta: { ...meta, [ no_footer_nav_key ]: nextValue, }, }); }} label={ __( 'No Footer Navigation', 'blackstone' ) } /> </> ) : ( <> <ToggleControl checked={ noHeaderNavValue } onChange={ (nextValue) => { editPost({ meta: { ...meta, [ no_header_nav_key ]: nextValue, }, }); }} label={ __( 'No Header Navigation', 'blackstone' ) } /> <ToggleControl checked={ noFooterNavValue } onChange={ (nextValue) => { editPost({ meta: { ...meta, [ no_footer_nav_key ]: nextValue, }); }); }} label={ __( 'No Footer Navigation', 'blackstone' ) } /> <ToggleControl checked={ noNetworkNavValue } onChange={ (nextValue) => { editPost({ meta: { ...meta, [ no_network_nav_key ]: nextValue, }); }); }} label={ __( 'No Top Global Navigation', 'blackstone' ) } /> <ToggleControl checked={ simplifiedFooterValue } onChange={ (nextValue) => { editPost({ meta: { ...meta, [ simplified_footer_key ]: nextValue, }); }); }} label={ __( 'Display Simplified Footer', 'blackstone' ) } /> </> )} </PluginDocumentSettingPanel> ); } if ( wp.editPost && templateOptionsPostTypes.includes( window.pagenow ) ) { registerPlugin( 'blackstone-template-options', { render: TemplateOptions, icon: null, } ); }
Leave a Comment