diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-includes/class-wp-customize-widgets.php --- a/wp/wp-includes/class-wp-customize-widgets.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-includes/class-wp-customize-widgets.php Tue Dec 15 13:49:49 2020 +0100 @@ -94,7 +94,7 @@ * * @since 3.9.0 * - * @param WP_Customize_Manager $manager Customize manager bootstrap instance. + * @param WP_Customize_Manager $manager Customizer bootstrap instance. */ public function __construct( $manager ) { $this->manager = $manager; @@ -173,8 +173,6 @@ * * @since 4.2.0 * - * @staticvar array $cache - * * @param string $setting_id Setting ID. * @return string|void Setting type. */ @@ -225,7 +223,7 @@ * * @param false|array $args The arguments to the WP_Customize_Setting constructor. * @param string $setting_id ID for dynamic setting, usually coming from `$_POST['customized']`. - * @return false|array Setting arguments, false otherwise. + * @return array|false Setting arguments, false otherwise. */ public function filter_customize_dynamic_setting_args( $args, $setting_id ) { if ( $this->get_setting_type( $setting_id ) ) { @@ -276,11 +274,11 @@ add_filter( 'customize_value_old_sidebars_widgets_data', array( $this, 'filter_customize_value_old_sidebars_widgets_data' ) ); $this->manager->set_post_value( 'old_sidebars_widgets_data', $this->old_sidebars_widgets ); // Override any value cached in changeset. - // retrieve_widgets() looks at the global $sidebars_widgets + // retrieve_widgets() looks at the global $sidebars_widgets. $sidebars_widgets = $this->old_sidebars_widgets; $sidebars_widgets = retrieve_widgets( 'customize' ); add_filter( 'option_sidebars_widgets', array( $this, 'filter_option_sidebars_widgets_for_theme_switch' ), 1 ); - // reset global cache var used by wp_get_sidebars_widgets() + // Reset global cache var used by wp_get_sidebars_widgets(). unset( $GLOBALS['_wp_sidebars_widgets'] ); } @@ -333,10 +331,10 @@ */ public function customize_controls_init() { /** This action is documented in wp-admin/includes/ajax-actions.php */ - do_action( 'load-widgets.php' ); + do_action( 'load-widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores /** This action is documented in wp-admin/includes/ajax-actions.php */ - do_action( 'widgets.php' ); + do_action( 'widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores /** This action is documented in wp-admin/widgets.php */ do_action( 'sidebar_admin_setup' ); @@ -450,7 +448,7 @@ $section_args = array( 'title' => $wp_registered_sidebars[ $sidebar_id ]['name'], 'description' => $wp_registered_sidebars[ $sidebar_id ]['description'], - 'priority' => array_search( $sidebar_id, array_keys( $wp_registered_sidebars ) ), + 'priority' => array_search( $sidebar_id, array_keys( $wp_registered_sidebars ), true ), 'panel' => 'widgets', 'sidebar_id' => $sidebar_id, ); @@ -567,7 +565,7 @@ * * @since 3.9.0 * - * @global $wp_registered_widget_controls + * @global array $wp_registered_widget_controls * * @param string $widget_id Widget ID. * @return bool Whether or not the widget is a "wide" widget. @@ -577,7 +575,7 @@ $parsed_widget_id = $this->parse_widget_id( $widget_id ); $width = $wp_registered_widget_controls[ $widget_id ]['width']; - $is_core = in_array( $parsed_widget_id['id_base'], $this->core_widget_id_bases ); + $is_core = in_array( $parsed_widget_id['id_base'], $this->core_widget_id_bases, true ); $is_wide = ( $width > 250 && ! $is_core ); /** @@ -609,7 +607,7 @@ $parsed['id_base'] = $matches[1]; $parsed['number'] = intval( $matches[2] ); } else { - // likely an old single widget + // Likely an old single widget. $parsed['id_base'] = $widget_id; } return $parsed; @@ -621,7 +619,7 @@ * @since 3.9.0 * * @param string $setting_id Widget setting ID. - * @return WP_Error|array Array containing a widget's id_base and number components, + * @return array|WP_Error Array containing a widget's id_base and number components, * or a WP_Error object. */ public function parse_widget_setting_id( $setting_id ) { @@ -643,7 +641,7 @@ */ public function print_styles() { /** This action is documented in wp-admin/admin-header.php */ - do_action( 'admin_print_styles-widgets.php' ); + do_action( 'admin_print_styles-widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores /** This action is documented in wp-admin/admin-header.php */ do_action( 'admin_print_styles' ); @@ -657,7 +655,7 @@ */ public function print_scripts() { /** This action is documented in wp-admin/admin-header.php */ - do_action( 'admin_print_scripts-widgets.php' ); + do_action( 'admin_print_scripts-widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores /** This action is documented in wp-admin/admin-header.php */ do_action( 'admin_print_scripts' ); @@ -732,7 +730,7 @@ 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 */ + /* 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.', @@ -756,7 +754,7 @@ } else { $no_areas_shown_message = html_entity_decode( sprintf( - /* translators: %s: the total number of widget areas registered */ + /* 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.', @@ -772,7 +770,7 @@ $settings = array( 'registeredSidebars' => array_values( $wp_registered_sidebars ), 'registeredWidgets' => $wp_registered_widgets, - 'availableWidgets' => $available_widgets, // @todo Merge this with registered_widgets + 'availableWidgets' => $available_widgets, // @todo Merge this with registered_widgets. 'l10n' => array( 'saveBtnLabel' => __( 'Apply' ), 'saveBtnTooltip' => __( 'Save and preview changes before publishing them.' ), @@ -787,7 +785,7 @@ 'reorderModeOn' => __( 'Reorder mode enabled' ), 'reorderModeOff' => __( 'Reorder mode closed' ), 'reorderLabelOn' => esc_attr__( 'Reorder widgets' ), - /* translators: %d: the number of widgets found */ + /* translators: %d: The number of widgets found. */ 'widgetsFound' => __( 'Number of widgets found: %d' ), 'noWidgetsFound' => __( 'No widgets found.' ), ), @@ -799,7 +797,7 @@ ); foreach ( $settings['registeredWidgets'] as &$registered_widget ) { - unset( $registered_widget['callback'] ); // may not be JSON-serializeable + unset( $registered_widget['callback'] ); // May not be JSON-serializeable. } $wp_scripts->add_data( @@ -825,8 +823,8 @@

manager->get_panel( 'widgets' )->title ) ); + /* translators: ▸ is the unicode right-pointing triangle. %s: Section title in the Customizer. */ + printf( __( 'Customizing ▸ %s' ), esc_html( $this->manager->get_panel( 'widgets' )->title ) ); ?> @@ -860,13 +858,13 @@ */ public function print_footer_scripts() { /** This action is documented in wp-admin/admin-footer.php */ - do_action( 'admin_print_footer_scripts-widgets.php' ); + do_action( 'admin_print_footer_scripts-widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores /** This action is documented in wp-admin/admin-footer.php */ do_action( 'admin_print_footer_scripts' ); /** This action is documented in wp-admin/admin-footer.php */ - do_action( 'admin_footer-widgets.php' ); + do_action( 'admin_footer-widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores } /** @@ -936,7 +934,6 @@ * * @global array $wp_registered_widgets * @global array $wp_registered_widget_controls - * @staticvar array $available_widgets * * @see wp_list_widgets() * @@ -949,14 +946,14 @@ } global $wp_registered_widgets, $wp_registered_widget_controls; - require_once ABSPATH . 'wp-admin/includes/widgets.php'; // for next_widget_id_number() + require_once ABSPATH . 'wp-admin/includes/widgets.php'; // For next_widget_id_number(). $sort = $wp_registered_widgets; usort( $sort, array( $this, '_sort_name_callback' ) ); $done = array(); foreach ( $sort as $widget ) { - if ( in_array( $widget['callback'], $done, true ) ) { // We already showed this multi-widget + if ( in_array( $widget['callback'], $done, true ) ) { // We already showed this multi-widget. continue; } @@ -968,7 +965,7 @@ } $available_widget = $widget; - unset( $available_widget['callback'] ); // not serializable to JSON + unset( $available_widget['callback'] ); // Not serializable to JSON. $args = array( 'widget_id' => $widget['id'], @@ -1007,7 +1004,7 @@ 'temp_id' => isset( $args['_temp_id'] ) ? $args['_temp_id'] : null, 'is_multi' => $is_multi_widget, 'control_tpl' => $control_tpl, - 'multi_number' => ( $args['_add'] === 'multi' ) ? $args['_multi_num'] : false, + 'multi_number' => ( 'multi' === $args['_add'] ) ? $args['_multi_num'] : false, 'is_disabled' => $is_disabled, 'id_base' => $id_base, 'transport' => $this->is_widget_selective_refreshable( $id_base ) ? 'postMessage' : 'refresh', @@ -1050,7 +1047,7 @@ $args[0]['before_widget_content'] = '
'; $args[0]['after_widget_content'] = '
'; ob_start(); - call_user_func_array( 'wp_widget_control', $args ); + wp_widget_control( ...$args ); $control_tpl = ob_get_clean(); return $control_tpl; } @@ -1103,8 +1100,8 @@ * * @since 4.2.0 * - * @param array $nonces Array of nonces. - * @return array $nonces Array of nonces. + * @param array $nonces Array of nonces. + * @return array Array of nonces. */ public function refresh_nonces( $nonces ) { $nonces['update-widget'] = wp_create_nonce( 'update-widget' ); @@ -1173,24 +1170,30 @@ global $wp_registered_sidebars, $wp_registered_widgets; $switched_locale = switch_to_locale( get_user_locale() ); - $l10n = array( + + $l10n = array( 'widgetTooltip' => __( 'Shift-click to edit this widget.' ), ); + if ( $switched_locale ) { restore_previous_locale(); } + $rendered_sidebars = array_filter( $this->rendered_sidebars ); + $rendered_widgets = array_filter( $this->rendered_widgets ); + // Prepare Customizer settings to pass to JavaScript. $settings = array( - 'renderedSidebars' => array_fill_keys( array_unique( $this->rendered_sidebars ), true ), - 'renderedWidgets' => array_fill_keys( array_keys( $this->rendered_widgets ), true ), + 'renderedSidebars' => array_fill_keys( array_keys( $rendered_sidebars ), true ), + 'renderedWidgets' => array_fill_keys( array_keys( $rendered_widgets ), true ), 'registeredSidebars' => array_values( $wp_registered_sidebars ), 'registeredWidgets' => $wp_registered_widgets, 'l10n' => $l10n, 'selectiveRefreshableWidgets' => $this->get_selective_refreshable_widgets(), ); + foreach ( $settings['registeredWidgets'] as &$registered_widget ) { - unset( $registered_widget['callback'] ); // may not be JSON-serializeable + unset( $registered_widget['callback'] ); // May not be JSON-serializeable. } ?> @@ -1220,7 +1223,7 @@ * @return bool Whether the widget is rendered. */ public function is_widget_rendered( $widget_id ) { - return in_array( $widget_id, $this->rendered_widgets ); + return ! empty( $this->rendered_widgets[ $widget_id ] ); } /** @@ -1232,7 +1235,7 @@ * @return bool Whether the sidebar is rendered. */ public function is_sidebar_rendered( $sidebar_id ) { - return in_array( $sidebar_id, $this->rendered_sidebars ); + return ! empty( $this->rendered_sidebars[ $sidebar_id ] ); } /** @@ -1250,8 +1253,9 @@ */ public function tally_sidebars_via_is_active_sidebar_calls( $is_active, $sidebar_id ) { if ( is_registered_sidebar( $sidebar_id ) ) { - $this->rendered_sidebars[] = $sidebar_id; + $this->rendered_sidebars[ $sidebar_id ] = true; } + /* * We may need to force this to true, and also force-true the value * for 'dynamic_sidebar_has_widgets' if we want to ensure that there @@ -1275,7 +1279,7 @@ */ public function tally_sidebars_via_dynamic_sidebar_calls( $has_widgets, $sidebar_id ) { if ( is_registered_sidebar( $sidebar_id ) ) { - $this->rendered_sidebars[] = $sidebar_id; + $this->rendered_sidebars[ $sidebar_id ] = true; } /* @@ -1313,7 +1317,7 @@ * @return array|void Sanitized widget instance. */ public function sanitize_widget_instance( $value ) { - if ( $value === array() ) { + if ( array() === $value ) { return $value; } @@ -1391,8 +1395,8 @@ * @global array $wp_registered_widget_updates * @global array $wp_registered_widget_controls * - * @param string $widget_id Widget ID. - * @return WP_Error|array Array containing the updated widget information. + * @param string $widget_id Widget ID. + * @return array|WP_Error Array containing the updated widget information. * A WP_Error object, otherwise. */ public function call_widget_update( $widget_id ) { @@ -1438,11 +1442,13 @@ $value = array(); $value[ $parsed_id['number'] ] = $instance; $key = 'widget-' . $parsed_id['id_base']; - $_REQUEST[ $key ] = $_POST[ $key ] = wp_slash( $value ); + $_REQUEST[ $key ] = wp_slash( $value ); + $_POST[ $key ] = $_REQUEST[ $key ]; $added_input_vars[] = $key; } else { foreach ( $instance as $key => $value ) { - $_REQUEST[ $key ] = $_POST[ $key ] = wp_slash( $value ); + $_REQUEST[ $key ] = wp_slash( $value ); + $_POST[ $key ] = $_REQUEST[ $key ]; $added_input_vars[] = $key; } } @@ -1458,7 +1464,7 @@ } } - // Clean up any input vars that were manually added + // Clean up any input vars that were manually added. foreach ( $added_input_vars as $key ) { unset( $_POST[ $key ] ); unset( $_REQUEST[ $key ] ); @@ -1536,10 +1542,10 @@ } /** This action is documented in wp-admin/includes/ajax-actions.php */ - do_action( 'load-widgets.php' ); + do_action( 'load-widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores /** This action is documented in wp-admin/includes/ajax-actions.php */ - do_action( 'widgets.php' ); + do_action( 'widgets.php' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores /** This action is documented in wp-admin/widgets.php */ do_action( 'sidebar_admin_setup' ); @@ -1685,7 +1691,7 @@ * List of the tag names seen for before_widget strings. * * This is used in the {@see 'filter_wp_kses_allowed_html'} filter to ensure that the - * data-* attributes can be whitelisted. + * data-* attributes can be allowed. * * @since 4.5.0 * @var array @@ -1738,7 +1744,7 @@ * The current request's sidebar_instance_number context. * * @since 4.5.0 - * @var int + * @var int|null */ protected $context_sidebar_instance_number; @@ -1790,7 +1796,7 @@ * Current sidebar being rendered. * * @since 4.5.0 - * @var string + * @var string|null */ protected $rendering_widget_id; @@ -1798,7 +1804,7 @@ * Current widget being rendered. * * @since 4.5.0 - * @var string + * @var string|null */ protected $rendering_sidebar_id; @@ -1856,8 +1862,9 @@ // Render the widget. ob_start(); - dynamic_sidebar( $this->rendering_sidebar_id = $context['sidebar_id'] ); - $container = ob_get_clean(); + $this->rendering_sidebar_id = $context['sidebar_id']; + dynamic_sidebar( $this->rendering_sidebar_id ); + $container = ob_get_clean(); // Reset variables for next partial render. remove_filter( 'sidebars_widgets', $filter_callback, 1000 ); @@ -1870,7 +1877,7 @@ } // - // Option Update Capturing + // Option Update Capturing. // /** @@ -1968,7 +1975,7 @@ */ public function capture_filter_pre_update_option( $new_value, $option_name, $old_value ) { if ( $this->is_option_capture_ignored( $option_name ) ) { - return; + return $new_value; } if ( ! isset( $this->_captured_options[ $option_name ] ) ) {