Widgets: Introduce `before_sidebar` and `after_sidebar` arguments for `register_sidebar()`.
Props deepaklalwani, flixos90, christophherr, dgwyer, markoheijnen, morganestes, audrasjb. Fixes #19709. Built from https://develop.svn.wordpress.org/trunk@49203 git-svn-id: http://core.svn.wordpress.org/trunk@48965 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
272df00b17
commit
19545d255c
|
@ -13,7 +13,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.6-alpha-49202';
|
$wp_version = '5.6-alpha-49203';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
|
@ -219,28 +219,35 @@ function register_sidebars( $number = 1, $args = array() ) {
|
||||||
* called, it will be automatically enabled through the use of add_theme_support()
|
* called, it will be automatically enabled through the use of add_theme_support()
|
||||||
*
|
*
|
||||||
* @since 2.2.0
|
* @since 2.2.0
|
||||||
|
* @since 5.6.0 Added the `before_sidebar` and `after_sidebar` arguments.
|
||||||
*
|
*
|
||||||
* @global array $wp_registered_sidebars Registered sidebars.
|
* @global array $wp_registered_sidebars Registered sidebars.
|
||||||
*
|
*
|
||||||
* @param array|string $args {
|
* @param array|string $args {
|
||||||
* Optional. Array or string of arguments for the sidebar being registered.
|
* 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
|
* @type string $name The name or title of the sidebar displayed in the Widgets
|
||||||
* interface. Default 'Sidebar $instance'.
|
* interface. Default 'Sidebar $instance'.
|
||||||
* @type string $id The unique identifier by which the sidebar will be called.
|
* @type string $id The unique identifier by which the sidebar will be called.
|
||||||
* Default 'sidebar-$instance'.
|
* Default 'sidebar-$instance'.
|
||||||
* @type string $description Description of the sidebar, displayed in the Widgets interface.
|
* @type string $description Description of the sidebar, displayed in the Widgets interface.
|
||||||
* Default empty string.
|
* Default empty string.
|
||||||
* @type string $class Extra CSS class to assign to the sidebar in the Widgets interface.
|
* @type string $class Extra CSS class to assign to the sidebar in the Widgets interface.
|
||||||
* Default empty.
|
* Default empty.
|
||||||
* @type string $before_widget HTML content to prepend to each widget's HTML output when
|
* @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.
|
* 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
|
* @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.
|
* 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.
|
* @type string $before_title HTML content to prepend to the sidebar title when displayed.
|
||||||
* Default is an opening h2 element.
|
* Default is an opening h2 element.
|
||||||
* @type string $after_title HTML content to append to the sidebar title when displayed.
|
* @type string $after_title HTML content to append to the sidebar title when displayed.
|
||||||
* Default is a closing h2 element.
|
* Default is a closing h2 element.
|
||||||
|
* @type string $before_sidebar HTML content to prepend to the sidebar when displayed.
|
||||||
|
* 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.
|
* @return string Sidebar ID added to $wp_registered_sidebars global.
|
||||||
*/
|
*/
|
||||||
|
@ -253,14 +260,16 @@ function register_sidebar( $args = array() ) {
|
||||||
|
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
/* translators: %d: Sidebar number. */
|
/* translators: %d: Sidebar number. */
|
||||||
'name' => sprintf( __( 'Sidebar %d' ), $i ),
|
'name' => sprintf( __( 'Sidebar %d' ), $i ),
|
||||||
'id' => "sidebar-$i",
|
'id' => "sidebar-$i",
|
||||||
'description' => '',
|
'description' => '',
|
||||||
'class' => '',
|
'class' => '',
|
||||||
'before_widget' => '<li id="%1$s" class="widget %2$s">',
|
'before_widget' => '<li id="%1$s" class="widget %2$s">',
|
||||||
'after_widget' => "</li>\n",
|
'after_widget' => "</li>\n",
|
||||||
'before_title' => '<h2 class="widgettitle">',
|
'before_title' => '<h2 class="widgettitle">',
|
||||||
'after_title' => "</h2>\n",
|
'after_title' => "</h2>\n",
|
||||||
|
'before_sidebar' => '',
|
||||||
|
'after_sidebar' => '',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -691,6 +700,10 @@ function dynamic_sidebar( $index = 1 ) {
|
||||||
return apply_filters( 'dynamic_sidebar_has_widgets', false, $index );
|
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.
|
* Fires before widgets are rendered in a dynamic sidebar.
|
||||||
*
|
*
|
||||||
|
@ -704,7 +717,10 @@ function dynamic_sidebar( $index = 1 ) {
|
||||||
* Default true.
|
* Default true.
|
||||||
*/
|
*/
|
||||||
do_action( 'dynamic_sidebar_before', $index, true );
|
do_action( 'dynamic_sidebar_before', $index, true );
|
||||||
$sidebar = $wp_registered_sidebars[ $index ];
|
|
||||||
|
if ( ! empty( $sidebar['before_sidebar'] ) ) {
|
||||||
|
echo $sidebar['before_sidebar'];
|
||||||
|
}
|
||||||
|
|
||||||
$did_one = false;
|
$did_one = false;
|
||||||
foreach ( (array) $sidebars_widgets[ $index ] as $id ) {
|
foreach ( (array) $sidebars_widgets[ $index ] as $id ) {
|
||||||
|
@ -807,6 +823,10 @@ function dynamic_sidebar( $index = 1 ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! empty( $sidebar['after_sidebar'] ) ) {
|
||||||
|
echo $sidebar['after_sidebar'];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fires after widgets are rendered in a dynamic sidebar.
|
* Fires after widgets are rendered in a dynamic sidebar.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue