Widgets: Pass `$instance` to widget argument filters:

* `widget_archives_dropdown_args`
* `widget_archives_args`
* `widget_categories_dropdown_args`
* `widget_categories_args`
* `widget_meta_poweredby`
* `widget_pages_args`
* `widget_comments_args`
* `widget_posts_args`
* `widget_tag_cloud_args`

See [33971] for `widget_links_args` and [34662] for `widget_nav_menu_args`.

Props Takahashi_Fumiki.
Fixes #38017.
Built from https://develop.svn.wordpress.org/trunk@41685


git-svn-id: http://core.svn.wordpress.org/trunk@41519 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2017-10-02 22:02:47 +00:00
parent a42b9cebde
commit 253541556e
9 changed files with 35 additions and 17 deletions

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.9-alpha-41684';
$wp_version = '4.9-alpha-41685';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -61,16 +61,18 @@ class WP_Widget_Archives extends WP_Widget {
* Filters the arguments for the Archives widget drop-down.
*
* @since 2.8.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @see wp_get_archives()
*
* @param array $args An array of Archives widget drop-down arguments.
* @param array $args An array of Archives widget drop-down arguments.
* @param array $instance Settings for the current Archives widget instance.
*/
$dropdown_args = apply_filters( 'widget_archives_dropdown_args', array(
'type' => 'monthly',
'format' => 'option',
'show_post_count' => $c
) );
), $instance );
switch ( $dropdown_args['type'] ) {
case 'yearly':
@ -102,15 +104,17 @@ class WP_Widget_Archives extends WP_Widget {
* Filters the arguments for the Archives widget.
*
* @since 2.8.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @see wp_get_archives()
*
* @param array $args An array of Archives option arguments.
* @param array $args An array of Archives option arguments.
* @param array $instance Array of settings for the current widget.
*/
wp_get_archives( apply_filters( 'widget_archives_args', array(
'type' => 'monthly',
'show_post_count' => $c
) ) );
), $instance ) );
?>
</ul>
<?php

View File

@ -76,12 +76,14 @@ class WP_Widget_Categories extends WP_Widget {
* Filters the arguments for the Categories widget drop-down.
*
* @since 2.8.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @see wp_dropdown_categories()
*
* @param array $cat_args An array of Categories widget drop-down arguments.
* @param array $instance Array of settings for the current widget.
*/
wp_dropdown_categories( apply_filters( 'widget_categories_dropdown_args', $cat_args ) );
wp_dropdown_categories( apply_filters( 'widget_categories_dropdown_args', $cat_args, $instance ) );
echo '</form>';
?>
@ -111,10 +113,12 @@ class WP_Widget_Categories extends WP_Widget {
* Filters the arguments for the Categories widget.
*
* @since 2.8.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @param array $cat_args An array of Categories widget options.
* @param array $instance Array of settings for the current widget.
*/
wp_list_categories( apply_filters( 'widget_categories_args', $cat_args ) );
wp_list_categories( apply_filters( 'widget_categories_args', $cat_args, $instance ) );
?>
</ul>
<?php

View File

@ -70,7 +70,7 @@ class WP_Widget_Links extends WP_Widget {
* Filters the arguments for the Links widget.
*
* @since 2.6.0
* @since 4.4.0 The `$instance` parameter was added.
* @since 4.4.0 Added the `$instance` parameter.
*
* @see wp_list_bookmarks()
*

View File

@ -60,14 +60,16 @@ class WP_Widget_Meta extends WP_Widget {
* Filters the "Powered by WordPress" text in the Meta widget.
*
* @since 3.6.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @param string $title_text Default title text for the WordPress.org link.
* @param array $instance Array of settings for the current widget.
*/
echo apply_filters( 'widget_meta_poweredby', sprintf( '<li><a href="%s" title="%s">%s</a></li>',
esc_url( __( 'https://wordpress.org/' ) ),
esc_attr__( 'Powered by WordPress, state-of-the-art semantic personal publishing platform.' ),
_x( 'WordPress.org', 'meta widget link text' )
) );
), $instance );
wp_meta();
?>

View File

@ -47,7 +47,7 @@ class WP_Widget_Pages extends WP_Widget {
* @since 2.6.0
*
* @param string $title The widget title. Default 'Pages'.
* @param array $instance An array of the widget's settings.
* @param array $instance Array of settings for the current widget.
* @param mixed $id_base The widget ID.
*/
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base );
@ -62,17 +62,19 @@ class WP_Widget_Pages extends WP_Widget {
* Filters the arguments for the Pages widget.
*
* @since 2.8.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @see wp_list_pages()
*
* @param array $args An array of arguments to retrieve the pages list.
* @param array $args An array of arguments to retrieve the pages list.
* @param array $instance Array of settings for the current widget.
*/
$out = wp_list_pages( apply_filters( 'widget_pages_args', array(
'title_li' => '',
'echo' => 0,
'sort_column' => $sortby,
'exclude' => $exclude
) ) );
), $instance ) );
if ( ! empty( $out ) ) {
echo $args['before_widget'];

View File

@ -85,16 +85,18 @@ class WP_Widget_Recent_Comments extends WP_Widget {
* Filters the arguments for the Recent Comments widget.
*
* @since 3.4.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @see WP_Comment_Query::query() for information on accepted arguments.
*
* @param array $comment_args An array of arguments used to retrieve the recent comments.
* @param array $instance Array of settings for the current widget.
*/
$comments = get_comments( apply_filters( 'widget_comments_args', array(
'number' => $number,
'status' => 'approve',
'post_status' => 'publish'
) ) );
), $instance ) );
$output .= $args['before_widget'];
if ( $title ) {

View File

@ -59,17 +59,19 @@ class WP_Widget_Recent_Posts extends WP_Widget {
* Filters the arguments for the Recent Posts widget.
*
* @since 3.4.0
* @since 4.9.0 Added the `$instance` parameter.
*
* @see WP_Query::get_posts()
*
* @param array $args An array of arguments used to retrieve the recent posts.
* @param array $args An array of arguments used to retrieve the recent posts.
* @param array $instance Array of settings for the current widget.
*/
$r = new WP_Query( apply_filters( 'widget_posts_args', array(
'posts_per_page' => $number,
'no_found_rows' => true,
'post_status' => 'publish',
'ignore_sticky_posts' => true
) ) );
), $instance ) );
if ($r->have_posts()) :
?>

View File

@ -58,16 +58,18 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
*
* @since 2.8.0
* @since 3.0.0 Added taxonomy drop-down.
* @since 4.9.0 Added the `$instance` parameter.
*
* @see wp_tag_cloud()
*
* @param array $args Args used for the tag cloud widget.
* @param array $args Args used for the tag cloud widget.
* @param array $instance Array of settings for the current widget.
*/
$tag_cloud = wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array(
'taxonomy' => $current_taxonomy,
'echo' => false,
'show_count' => $show_count,
) ) );
), $instance ) );
if ( empty( $tag_cloud ) ) {
return;