I have written a WordPress theme which uses the customizer a lot. I would like to de-register the widgets panel (I have my reasons). Currently, I'm doing this:
/**
* Our class for altering the WP theme customizer.
*/
class LXB_AF_Customize {
public function __construct() {
[...]
add_action( 'customize_register', array( $this, 'remove_items' ), 980 );
[...]
}
[...]
// We're gonna output widgets elsewhere, so we don't need the core widgets panel.
function remove_items( $wp_customize ) {
[...]
@$wp_customize -> remove_panel( 'widgets' );
}
}
Which is instantiated in the global scope via:
/**
* Setup the Theme Customizer settings and controls.
*/
function lxb_af_customizer_init() {
new LXB_AF_Customize();
}
add_action( 'init' , 'lxb_af_customizer_init' );
This triggers a doing_it_wrong error from core, here: https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-customize-manager.php#L1212
That message suggests that I instead use customize_loaded_components
:
https://developer.wordpress.org/reference/hooks/customize_loaded_components/
However, as noted on that docs page, customize_loaded_components
does not seem to work when invoked from a theme. I can only get it to work from a plugin. In my situation, I don't want to require any particular plugin to be active, in order to use my theme.
Any suggestions?
unregister_sidebar()
any widget areas that have been created, will this take care of it? I know this hides the Widget menu option under Themes, just not sure about how it affects the Customizer.