Changes between Initial Version and Version 1 of Ticket #33552, comment 6
- Timestamp:
- 10/20/2015 08:10:47 PM (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #33552, comment 6
initial v1 3 3 To me it seems the primary use case of this filter is to remove components from being added. For instance: 4 4 5 {{{ 5 {{{#!php 6 <?php 6 7 add_filter( 'customize_components_to_load', function( $components ) { 7 8 return array_filter( $components, function ( $component ) { … … 15 16 If I want to introduce a new component for “posts” then it seems I would need to do basically hack the filter to serve as an action: 16 17 17 {{{ 18 {{{#!php 19 <?php 18 20 add_filter( 'customize_components_to_load', function( $components, $wp_customize ) { 19 21 $wp_customize->posts = new My_Customize_Posts( $wp_customize ); … … 24 26 If I want to replace the current `widgets` implementation with a different one, I would have to do something like: 25 27 26 {{{ 28 {{{#!php 29 <?php 27 30 add_filter( 'customize_components_to_load', function( $components, $wp_customize ) { 28 31 // First remove widgets entirely so that it won't get constructed. … … 41 44 Maybe it would work better if `customize_components_to_load` was filtering a mapping of component name to class name. For instance: 42 45 43 {{{ 46 {{{#!php 47 <?php 44 48 $components = array( 45 49 'widgets' => 'WP_Customize_Widgets', … … 51 55 And then it could do: 52 56 53 {{{ 57 {{{#!php 58 <?php 54 59 foreach ( $components as $component => $class ) { 55 60 $this->$component = new $class( $this ); … … 59 64 This would, however, not play nicely with the `require`ing of the class file, so those should `require_once` statements should remain where they are at the top, or else changed to be something lower down like: 60 65 61 {{{ 66 {{{#!php 67 <?php 62 68 if ( isset( $components['widgets'] ) ) { 63 69 require_once( ABSPATH . WPINC . '/class-wp-customize-widgets.php' ); … … 70 76 What this implies is that `\WP_Customize_Widgets` and `\WP_Customize_Nav_Menus` can never be pluggable to be replaced with any other classes. If you want to use a different class for managing menus, then you'd have to do: 71 77 72 {{{ 78 {{{#!php 79 <?php 73 80 add_filter( 'customize_components_to_load', function( $components) { 74 81 require_once MY_PLUGIN_DIR . '/class-my-customize-nav-menus.php';