diff -r 34716fd837a4 -r be944660c56a wp/wp-includes/widgets.php --- a/wp/wp-includes/widgets.php Tue Dec 15 15:52:01 2020 +0100 +++ b/wp/wp-includes/widgets.php Wed Sep 21 18:19:35 2022 +0200 @@ -219,28 +219,37 @@ * called, it will be automatically enabled through the use of add_theme_support() * * @since 2.2.0 + * @since 5.6.0 Added the `before_sidebar` and `after_sidebar` arguments. * * @global array $wp_registered_sidebars Registered sidebars. * * @param array|string $args { * Optional. Array or string of arguments for the sidebar being registered. * - * @type string $name The name or title of the sidebar displayed in the Widgets - * interface. Default 'Sidebar $instance'. - * @type string $id The unique identifier by which the sidebar will be called. - * Default 'sidebar-$instance'. - * @type string $description Description of the sidebar, displayed in the Widgets interface. - * Default empty string. - * @type string $class Extra CSS class to assign to the sidebar in the Widgets interface. - * Default empty. - * @type string $before_widget HTML content to prepend to each widget's HTML output when - * assigned to this sidebar. Default is an opening list item element. - * @type string $after_widget HTML content to append to each widget's HTML output when - * assigned to this sidebar. Default is a closing list item element. - * @type string $before_title HTML content to prepend to the sidebar title when displayed. - * Default is an opening h2 element. - * @type string $after_title HTML content to append to the sidebar title when displayed. - * Default is a closing h2 element. + * @type string $name The name or title of the sidebar displayed in the Widgets + * interface. Default 'Sidebar $instance'. + * @type string $id The unique identifier by which the sidebar will be called. + * Default 'sidebar-$instance'. + * @type string $description Description of the sidebar, displayed in the Widgets interface. + * Default empty string. + * @type string $class Extra CSS class to assign to the sidebar in the Widgets interface. + * Default empty. + * @type string $before_widget HTML content to prepend to each widget's HTML output when assigned + * to this sidebar. Receives the widget's ID attribute as `%1$s` + * and class name as `%2$s`. Default is an opening list item element. + * @type string $after_widget HTML content to append to each widget's HTML output when assigned + * to this sidebar. Default is a closing list item element. + * @type string $before_title HTML content to prepend to the sidebar title when displayed. + * Default is an opening h2 element. + * @type string $after_title HTML content to append to the sidebar title when displayed. + * Default is a closing h2 element. + * @type string $before_sidebar HTML content to prepend to the sidebar when displayed. + * Receives the `$id` argument as `%1$s` and `$class` as `%2$s`. + * Outputs after the {@see 'dynamic_sidebar_before'} action. + * Default empty string. + * @type string $after_sidebar HTML content to append to the sidebar when displayed. + * Outputs before the {@see 'dynamic_sidebar_after'} action. + * Default empty string. * } * @return string Sidebar ID added to $wp_registered_sidebars global. */ @@ -253,14 +262,16 @@ $defaults = array( /* translators: %d: Sidebar number. */ - 'name' => sprintf( __( 'Sidebar %d' ), $i ), - 'id' => "sidebar-$i", - 'description' => '', - 'class' => '', - 'before_widget' => '
  • ', - 'after_widget' => "
  • \n", - 'before_title' => '

    ', - 'after_title' => "

    \n", + 'name' => sprintf( __( 'Sidebar %d' ), $i ), + 'id' => "sidebar-$i", + 'description' => '', + 'class' => '', + 'before_widget' => '
  • ', + 'after_widget' => "
  • \n", + 'before_title' => '

    ', + 'after_title' => "

    \n", + 'before_sidebar' => '', + 'after_sidebar' => '', ); /** @@ -346,6 +357,7 @@ * @since 2.2.0 * @since 5.3.0 Formalized the existing and already documented `...$params` parameter * by adding it to the function signature. + * @since 5.8.0 Added show_instance_in_rest option. * * @global array $wp_registered_widgets Uses stored registered widgets. * @global array $wp_registered_widget_controls Stores the registered widget controls (options). @@ -358,10 +370,12 @@ * @param array $options { * Optional. An array of supplementary widget options for the instance. * - * @type string $classname Class name for the widget's HTML container. Default is a shortened - * version of the output callback name. - * @type string $description Widget description for display in the widget administration - * panel and/or theme. + * @type string $classname Class name for the widget's HTML container. Default is a shortened + * version of the output callback name. + * @type string $description Widget description for display in the widget administration + * panel and/or theme. + * @type bool $show_instance_in_rest Whether to show the widget's instance settings in the REST API. + * Only available for WP_Widget based widgets. * } * @param mixed ...$params Optional additional parameters to pass to the callback function when it's called. */ @@ -691,6 +705,10 @@ return apply_filters( 'dynamic_sidebar_has_widgets', false, $index ); } + $sidebar = $wp_registered_sidebars[ $index ]; + + $sidebar['before_sidebar'] = sprintf( $sidebar['before_sidebar'], $sidebar['id'], $sidebar['class'] ); + /** * Fires before widgets are rendered in a dynamic sidebar. * @@ -704,7 +722,10 @@ * Default true. */ do_action( 'dynamic_sidebar_before', $index, true ); - $sidebar = $wp_registered_sidebars[ $index ]; + + if ( ! is_admin() && ! empty( $sidebar['before_sidebar'] ) ) { + echo $sidebar['before_sidebar']; + } $did_one = false; foreach ( (array) $sidebars_widgets[ $index ] as $id ) { @@ -735,8 +756,13 @@ $classname_ .= '_' . get_class( $cn ); } } - $classname_ = ltrim( $classname_, '_' ); - $params[0]['before_widget'] = sprintf( $params[0]['before_widget'], $id, $classname_ ); + $classname_ = ltrim( $classname_, '_' ); + + $params[0]['before_widget'] = sprintf( + $params[0]['before_widget'], + str_replace( '\\', '_', $id ), + $classname_ + ); /** * Filters the parameters passed to a widget's display callback. @@ -784,19 +810,19 @@ * * @since 3.0.0 * - * @param array $widget_id { + * @param array $widget { * An associative array of widget arguments. * * @type string $name Name of the widget. * @type string $id Widget ID. - * @type callable $callback When the hook is fired on the front end, $callback is an array - * containing the widget object. Fired on the back end, $callback - * is 'wp_widget_control', see $_callback. + * @type callable $callback When the hook is fired on the front end, `$callback` is an array + * containing the widget object. Fired on the back end, `$callback` + * is 'wp_widget_control', see `$_callback`. * @type array $params An associative array of multi-widget arguments. * @type string $classname CSS class applied to the widget container. * @type string $description The widget description. - * @type array $_callback When the hook is fired on the back end, $_callback is populated - * with an array containing the widget object, see $callback. + * @type array $_callback When the hook is fired on the back end, `$_callback` is populated + * with an array containing the widget object, see `$callback`. * } */ do_action( 'dynamic_sidebar', $wp_registered_widgets[ $id ] ); @@ -807,6 +833,10 @@ } } + if ( ! is_admin() && ! empty( $sidebar['after_sidebar'] ) ) { + echo $sidebar['after_sidebar']; + } + /** * Fires after widgets are rendered in a dynamic sidebar. * @@ -857,11 +887,15 @@ * * @global array $wp_registered_widgets * - * @param callable|false $callback Optional, Widget callback to check. Default false. - * @param int|false $widget_id Optional. Widget ID. Optional, but needed for checking. Default false. - * @param string|false $id_base Optional. The base ID of a widget created by extending WP_Widget. Default false. - * @param bool $skip_inactive Optional. Whether to check in 'wp_inactive_widgets'. Default true. - * @return string|false False if widget is not active or id of sidebar in which the widget is active. + * @param callable|false $callback Optional. Widget callback to check. Default false. + * @param string|false $widget_id Optional. Widget ID. Optional, but needed for checking. + * Default false. + * @param string|false $id_base Optional. The base ID of a widget created by extending WP_Widget. + * Default false. + * @param bool $skip_inactive Optional. Whether to check in 'wp_inactive_widgets'. + * Default true. + * @return string|false ID of the sidebar in which the widget is active, + * false if the widget is not active. */ function is_active_widget( $callback = false, $widget_id = false, $id_base = false, $skip_inactive = true ) { global $wp_registered_widgets; @@ -1262,7 +1296,7 @@ $sidebars_widgets = wp_map_sidebars_widgets( $sidebars_widgets ); // Find hidden/lost multi-widget instances. - $shown_widgets = call_user_func_array( 'array_merge', $sidebars_widgets ); + $shown_widgets = array_merge( ...array_values( $sidebars_widgets ) ); $lost_widgets = array_diff( $registered_widgets_ids, $shown_widgets ); foreach ( $lost_widgets as $key => $widget_id ) { @@ -1531,7 +1565,7 @@ echo '