[wp-trac] [WordPress Trac] #33552: Facilitate plugins to override Customizer features
WordPress Trac
noreply at wordpress.org
Wed Aug 26 06:50:38 UTC 2015
#33552: Facilitate plugins to override Customizer features
-------------------------+-----------------
Reporter: westonruter | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: 4.4
Component: Customize | Version: 3.9
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------
This is splitting out from #33411, which was to fix an issue where
removing the `nav_menus` panel in the Customizer would result in a JS
error on init.
Nevertheless, removing the `nav_menus` panel on its own actually would not
have the desired effect. All of the Menu Customizer settings, sections,
and controls would still be loaded needlessly. In 4.3, the only way to
completely disable the nav menus in the Customizer is to unhook the
actions/filters that are added by `WP_Customize_Nav_Menus::__construct()`,
for instance with this plugin:
{{{#!php
<?php
add_action( 'customize_register', function( $wp_customize ) {
/** @var WP_Customize_Manager $wp_customize */
remove_action( 'customize_controls_enqueue_scripts', array(
$wp_customize->nav_menus, 'enqueue_scripts' ) );
remove_action( 'customize_register', array(
$wp_customize->nav_menus, 'customize_register' ), 11 );
remove_filter( 'customize_dynamic_setting_args', array(
$wp_customize->nav_menus, 'filter_dynamic_setting_args' ) );
remove_filter( 'customize_dynamic_setting_class', array(
$wp_customize->nav_menus, 'filter_dynamic_setting_class' ) );
remove_action( 'customize_controls_print_footer_scripts', array(
$wp_customize->nav_menus, 'print_templates' ) );
remove_action( 'customize_controls_print_footer_scripts', array(
$wp_customize->nav_menus, 'available_items_template' ) );
remove_action( 'customize_preview_init', array(
$wp_customize->nav_menus, 'customize_preview_init' ) );
}, 10 );
}}}
This is not developer friendly.
To truly remove the Nav Menus entirely, another extension mechanism is
needed to hook in earlier to be able to override which Customizer features
get loaded. This is useful for disabling features, but it is perhaps even
more useful for plugins to introduce new features, and even for feature
plugins to swap out Customizer components altogether. With that in mind,
we could have a `customize_manager_construct` action that fires at the top
of `WP_Customize_Manager::__construct()`. A plugin could then set the
`$wp_customize->widgets` and `$wp_customize->nav_menus` up front, and then
when the constructor continues it could prevent assigning these if they
were already assigned.
Sou could disable menus in the Customizer just with this plugin:
{{{#!php
<?php
add_action( 'customize_manager_construct', function( $wp_customize ) {
$wp_customize->nav_menus = false;
} );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/33552>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list