Untitled
unknown
plain_text
10 months ago
2.1 kB
7
Indexable
/**
* Core plugin functionality.
*
* @package BmacxCore
*/
namespace BmacxCore\Core;
use function BlackstoneCore\Utility\get_current_site;
/**
* Default setup routine
*
* @return void
*/
function setup() {
$n = function( $function ) {
return __NAMESPACE__ . "\\$function";
};
add_action( 'enqueue_block_editor_assets', $n( 'customize_gutenberg_template_options' ) );
do_action( 'bmacx_core_loaded' );
}
/**
* Customize Gutenberg Template Options for bmacx Site
*/
function customize_gutenberg_template_options() {
$current_site = get_current_site();
$current_theme = wp_get_theme()->get( 'Name' );
// Check if we are on bmacx site and using the Blackstone V2 theme
if ( $current_site === 'bmacx' && $current_theme === 'Blackstone V2' ) {
// Enqueue the script that removes unwanted options
wp_enqueue_script(
'bmacx-template-options',
plugin_dir_url( __FILE__ ) . 'bmacx-template-options.js',
[ 'wp-data', 'wp-edit-post', 'wp-hooks' ],
null,
true
);
}
}
wp.data.subscribe(function () {
// Ensure that the meta box is available and loaded
const editor = wp.data.select('core/editor');
const meta = editor.getEditedPostAttribute('meta');
// Define the keys we want to show: 'No Header Navigation' and 'No Footer Navigation'
const allowedOptions = ['no_header_nav_key', 'no_footer_nav_key'];
// Hide the unnecessary template options if they are present
document.querySelectorAll('.components-panel__body .components-base-control').forEach(function (element) {
const controlLabel = element.querySelector('.components-base-control__label')?.textContent;
// If the control is not in the allowed options, hide it
if (controlLabel && !allowedOptions.some(option => controlLabel.includes(option))) {
element.style.display = 'none';
}
});
});
bmacx-template-options.jsEditor is loading...
Leave a Comment