diff -r c7c34916027a -r 177826044cd9 wp/wp-includes/class-wp-customize-widgets.php --- a/wp/wp-includes/class-wp-customize-widgets.php Mon Oct 14 18:06:33 2019 +0200 +++ b/wp/wp-includes/class-wp-customize-widgets.php Mon Oct 14 18:28:13 2019 +0200 @@ -100,32 +100,32 @@ $this->manager = $manager; // See https://github.com/xwp/wp-customize-snapshots/blob/962586659688a5b1fd9ae93618b7ce2d4e7a421c/php/class-customize-snapshot-manager.php#L420-L449 - add_filter( 'customize_dynamic_setting_args', array( $this, 'filter_customize_dynamic_setting_args' ), 10, 2 ); - add_action( 'widgets_init', array( $this, 'register_settings' ), 95 ); - add_action( 'customize_register', array( $this, 'schedule_customize_register' ), 1 ); + add_filter( 'customize_dynamic_setting_args', array( $this, 'filter_customize_dynamic_setting_args' ), 10, 2 ); + add_action( 'widgets_init', array( $this, 'register_settings' ), 95 ); + add_action( 'customize_register', array( $this, 'schedule_customize_register' ), 1 ); // Skip remaining hooks when the user can't manage widgets anyway. if ( ! current_user_can( 'edit_theme_options' ) ) { return; } - add_action( 'wp_loaded', array( $this, 'override_sidebars_widgets_for_theme_switch' ) ); - add_action( 'customize_controls_init', array( $this, 'customize_controls_init' ) ); - add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); - add_action( 'customize_controls_print_styles', array( $this, 'print_styles' ) ); - add_action( 'customize_controls_print_scripts', array( $this, 'print_scripts' ) ); + add_action( 'wp_loaded', array( $this, 'override_sidebars_widgets_for_theme_switch' ) ); + add_action( 'customize_controls_init', array( $this, 'customize_controls_init' ) ); + add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); + add_action( 'customize_controls_print_styles', array( $this, 'print_styles' ) ); + add_action( 'customize_controls_print_scripts', array( $this, 'print_scripts' ) ); add_action( 'customize_controls_print_footer_scripts', array( $this, 'print_footer_scripts' ) ); add_action( 'customize_controls_print_footer_scripts', array( $this, 'output_widget_control_templates' ) ); - add_action( 'customize_preview_init', array( $this, 'customize_preview_init' ) ); - add_filter( 'customize_refresh_nonces', array( $this, 'refresh_nonces' ) ); + add_action( 'customize_preview_init', array( $this, 'customize_preview_init' ) ); + add_filter( 'customize_refresh_nonces', array( $this, 'refresh_nonces' ) ); - add_action( 'dynamic_sidebar', array( $this, 'tally_rendered_widgets' ) ); - add_filter( 'is_active_sidebar', array( $this, 'tally_sidebars_via_is_active_sidebar_calls' ), 10, 2 ); - add_filter( 'dynamic_sidebar_has_widgets', array( $this, 'tally_sidebars_via_dynamic_sidebar_calls' ), 10, 2 ); + add_action( 'dynamic_sidebar', array( $this, 'tally_rendered_widgets' ) ); + add_filter( 'is_active_sidebar', array( $this, 'tally_sidebars_via_is_active_sidebar_calls' ), 10, 2 ); + add_filter( 'dynamic_sidebar_has_widgets', array( $this, 'tally_sidebars_via_dynamic_sidebar_calls' ), 10, 2 ); // Selective Refresh. - add_filter( 'customize_dynamic_partial_args', array( $this, 'customize_dynamic_partial_args' ), 10, 2 ); - add_action( 'customize_preview_init', array( $this, 'selective_refresh_init' ) ); + add_filter( 'customize_dynamic_partial_args', array( $this, 'customize_dynamic_partial_args' ), 10, 2 ); + add_action( 'customize_preview_init', array( $this, 'selective_refresh_init' ) ); } /** @@ -198,7 +198,7 @@ * @since 4.2.0 */ public function register_settings() { - $widget_setting_ids = array(); + $widget_setting_ids = array(); $incoming_setting_ids = array_keys( $this->manager->unsanitized_post_values() ); foreach ( $incoming_setting_ids as $setting_id ) { if ( ! is_null( $this->get_setting_type( $setting_id ) ) ) { @@ -319,7 +319,7 @@ * @return array */ public function filter_option_sidebars_widgets_for_theme_switch( $sidebars_widgets ) { - $sidebars_widgets = $GLOBALS['sidebars_widgets']; + $sidebars_widgets = $GLOBALS['sidebars_widgets']; $sidebars_widgets['array_version'] = 3; return $sidebars_widgets; } @@ -399,22 +399,28 @@ * theme_mod when the theme is switched. */ if ( ! $this->manager->is_theme_active() ) { - $setting_id = 'old_sidebars_widgets_data'; - $setting_args = $this->get_setting_args( $setting_id, array( - 'type' => 'global_variable', - 'dirty' => true, - ) ); + $setting_id = 'old_sidebars_widgets_data'; + $setting_args = $this->get_setting_args( + $setting_id, + array( + 'type' => 'global_variable', + 'dirty' => true, + ) + ); $this->manager->add_setting( $setting_id, $setting_args ); } - $this->manager->add_panel( 'widgets', array( - 'type' => 'widgets', - 'title' => __( 'Widgets' ), - 'description' => __( 'Widgets are independent sections of content that can be placed into widgetized areas provided by your theme (commonly called sidebars).' ), - 'priority' => 110, - 'active_callback' => array( $this, 'is_panel_active' ), - 'auto_expand_sole_section' => true, - ) ); + $this->manager->add_panel( + 'widgets', + array( + 'type' => 'widgets', + 'title' => __( 'Widgets' ), + 'description' => __( 'Widgets are independent sections of content that can be placed into widgetized areas provided by your theme (commonly called sidebars).' ), + 'priority' => 110, + 'active_callback' => array( $this, 'is_panel_active' ), + 'auto_expand_sole_section' => true, + ) + ); foreach ( $sidebars_widgets as $sidebar_id => $sidebar_widget_ids ) { if ( empty( $sidebar_widget_ids ) ) { @@ -442,11 +448,11 @@ if ( $is_active_sidebar ) { $section_args = array( - 'title' => $wp_registered_sidebars[ $sidebar_id ]['name'], + 'title' => $wp_registered_sidebars[ $sidebar_id ]['name'], 'description' => $wp_registered_sidebars[ $sidebar_id ]['description'], - 'priority' => array_search( $sidebar_id, array_keys( $wp_registered_sidebars ) ), - 'panel' => 'widgets', - 'sidebar_id' => $sidebar_id, + 'priority' => array_search( $sidebar_id, array_keys( $wp_registered_sidebars ) ), + 'panel' => 'widgets', + 'sidebar_id' => $sidebar_id, ); /** @@ -463,11 +469,15 @@ $section = new WP_Customize_Sidebar_Section( $this->manager, $section_id, $section_args ); $this->manager->add_section( $section ); - $control = new WP_Widget_Area_Customize_Control( $this->manager, $setting_id, array( - 'section' => $section_id, - 'sidebar_id' => $sidebar_id, - 'priority' => count( $sidebar_widget_ids ), // place 'Add Widget' and 'Reorder' buttons at end. - ) ); + $control = new WP_Widget_Area_Customize_Control( + $this->manager, + $setting_id, + array( + 'section' => $section_id, + 'sidebar_id' => $sidebar_id, + 'priority' => count( $sidebar_widget_ids ), // place 'Add Widget' and 'Reorder' buttons at end. + ) + ); $new_setting_ids[] = $setting_id; $this->manager->add_control( $control ); @@ -478,25 +488,29 @@ foreach ( $sidebar_widget_ids as $i => $widget_id ) { // Skip widgets that may have gone away due to a plugin being deactivated. - if ( ! $is_active_sidebar || ! isset( $wp_registered_widgets[$widget_id] ) ) { + if ( ! $is_active_sidebar || ! isset( $wp_registered_widgets[ $widget_id ] ) ) { continue; } - $registered_widget = $wp_registered_widgets[$widget_id]; + $registered_widget = $wp_registered_widgets[ $widget_id ]; $setting_id = $this->get_setting_id( $widget_id ); - $id_base = $wp_registered_widget_controls[$widget_id]['id_base']; + $id_base = $wp_registered_widget_controls[ $widget_id ]['id_base']; - $control = new WP_Widget_Form_Customize_Control( $this->manager, $setting_id, array( - 'label' => $registered_widget['name'], - 'section' => $section_id, - 'sidebar_id' => $sidebar_id, - 'widget_id' => $widget_id, - 'widget_id_base' => $id_base, - 'priority' => $i, - 'width' => $wp_registered_widget_controls[$widget_id]['width'], - 'height' => $wp_registered_widget_controls[$widget_id]['height'], - 'is_wide' => $this->is_wide_widget( $widget_id ), - ) ); + $control = new WP_Widget_Form_Customize_Control( + $this->manager, + $setting_id, + array( + 'label' => $registered_widget['name'], + 'section' => $section_id, + 'sidebar_id' => $sidebar_id, + 'widget_id' => $widget_id, + 'widget_id_base' => $id_base, + 'priority' => $i, + 'width' => $wp_registered_widget_controls[ $widget_id ]['width'], + 'height' => $wp_registered_widget_controls[ $widget_id ]['height'], + 'is_wide' => $this->is_wide_widget( $widget_id ), + ) + ); $this->manager->add_control( $control ); } } @@ -562,7 +576,7 @@ global $wp_registered_widget_controls; $parsed_widget_id = $this->parse_widget_id( $widget_id ); - $width = $wp_registered_widget_controls[$widget_id]['width']; + $width = $wp_registered_widget_controls[ $widget_id ]['width']; $is_core = in_array( $parsed_widget_id['id_base'], $this->core_widget_id_bases ); $is_wide = ( $width > 250 && ! $is_core ); @@ -587,7 +601,7 @@ */ public function parse_widget_id( $widget_id ) { $parsed = array( - 'number' => null, + 'number' => null, 'id_base' => null, ); @@ -708,50 +722,62 @@ * Gather all strings in PHP that may be needed by JS on the client. * Once JS i18n is implemented (in #20491), this can be removed. */ - $some_non_rendered_areas_messages = array(); + $some_non_rendered_areas_messages = array(); $some_non_rendered_areas_messages[1] = html_entity_decode( __( 'Your theme has 1 other widget area, but this particular page doesn’t display it.' ), ENT_QUOTES, get_bloginfo( 'charset' ) ); - $registered_sidebar_count = count( $wp_registered_sidebars ); + $registered_sidebar_count = count( $wp_registered_sidebars ); for ( $non_rendered_count = 2; $non_rendered_count < $registered_sidebar_count; $non_rendered_count++ ) { - $some_non_rendered_areas_messages[ $non_rendered_count ] = html_entity_decode( sprintf( - /* translators: %s: the number of other widget areas registered but not rendered */ - _n( - 'Your theme has %s other widget area, but this particular page doesn’t display it.', - 'Your theme has %s other widget areas, but this particular page doesn’t display them.', - $non_rendered_count + $some_non_rendered_areas_messages[ $non_rendered_count ] = html_entity_decode( + sprintf( + /* translators: %s: the number of other widget areas registered but not rendered */ + _n( + 'Your theme has %s other widget area, but this particular page doesn’t display it.', + 'Your theme has %s other widget areas, but this particular page doesn’t display them.', + $non_rendered_count + ), + number_format_i18n( $non_rendered_count ) ), - number_format_i18n( $non_rendered_count ) - ), ENT_QUOTES, get_bloginfo( 'charset' ) ); + ENT_QUOTES, + get_bloginfo( 'charset' ) + ); } if ( 1 === $registered_sidebar_count ) { - $no_areas_shown_message = html_entity_decode( sprintf( - __( 'Your theme has 1 widget area, but this particular page doesn’t display it.' ) - ), ENT_QUOTES, get_bloginfo( 'charset' ) ); + $no_areas_shown_message = html_entity_decode( + sprintf( + __( 'Your theme has 1 widget area, but this particular page doesn’t display it.' ) + ), + ENT_QUOTES, + get_bloginfo( 'charset' ) + ); } else { - $no_areas_shown_message = html_entity_decode( sprintf( - /* translators: %s: the total number of widget areas registered */ - _n( - 'Your theme has %s widget area, but this particular page doesn’t display it.', - 'Your theme has %s widget areas, but this particular page doesn’t display them.', - $registered_sidebar_count + $no_areas_shown_message = html_entity_decode( + sprintf( + /* translators: %s: the total number of widget areas registered */ + _n( + 'Your theme has %s widget area, but this particular page doesn’t display it.', + 'Your theme has %s widget areas, but this particular page doesn’t display them.', + $registered_sidebar_count + ), + number_format_i18n( $registered_sidebar_count ) ), - number_format_i18n( $registered_sidebar_count ) - ), ENT_QUOTES, get_bloginfo( 'charset' ) ); + ENT_QUOTES, + get_bloginfo( 'charset' ) + ); } $settings = array( - 'registeredSidebars' => array_values( $wp_registered_sidebars ), - 'registeredWidgets' => $wp_registered_widgets, - 'availableWidgets' => $available_widgets, // @todo Merge this with registered_widgets - 'l10n' => array( + 'registeredSidebars' => array_values( $wp_registered_sidebars ), + 'registeredWidgets' => $wp_registered_widgets, + 'availableWidgets' => $available_widgets, // @todo Merge this with registered_widgets + 'l10n' => array( 'saveBtnLabel' => __( 'Apply' ), 'saveBtnTooltip' => __( 'Save and preview changes before publishing them.' ), 'removeBtnLabel' => __( 'Remove' ), - 'removeBtnTooltip' => __( 'Trash widget by moving it to the inactive widgets sidebar.' ), + 'removeBtnTooltip' => __( 'Keep widget settings and move it to the inactive widgets' ), 'error' => __( 'An error has occurred. Please reload the page and try again.' ), 'widgetMovedUp' => __( 'Widget moved up' ), 'widgetMovedDown' => __( 'Widget moved down' ), @@ -765,7 +791,7 @@ 'widgetsFound' => __( 'Number of widgets found: %d' ), 'noWidgetsFound' => __( 'No widgets found.' ), ), - 'tpl' => array( + 'tpl' => array( 'widgetReorderNav' => $widget_reorder_nav_tpl, 'moveWidgetArea' => $move_widget_area_tpl, ), @@ -797,23 +823,25 @@