From 46ff957961e2bcd74f75eab5d9d5042db76627df Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 15 Oct 2017 21:43:47 +0000 Subject: [PATCH] Widgets: Move empty title checks out of the `apply_filters( 'widget_title' )` calls for clarity. See #42226. Built from https://develop.svn.wordpress.org/trunk@41867 git-svn-id: http://core.svn.wordpress.org/trunk@41701 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/version.php | 2 +- wp-includes/widgets/class-wp-nav-menu-widget.php | 12 ++++++++---- wp-includes/widgets/class-wp-widget-archives.php | 9 ++++++--- wp-includes/widgets/class-wp-widget-calendar.php | 4 +++- wp-includes/widgets/class-wp-widget-categories.php | 5 ++++- wp-includes/widgets/class-wp-widget-meta.php | 6 +++++- wp-includes/widgets/class-wp-widget-pages.php | 3 ++- wp-includes/widgets/class-wp-widget-rss.php | 5 +++-- wp-includes/widgets/class-wp-widget-search.php | 4 +++- wp-includes/widgets/class-wp-widget-tag-cloud.php | 11 ++++++----- wp-includes/widgets/class-wp-widget-text.php | 4 +++- 11 files changed, 44 insertions(+), 21 deletions(-) diff --git a/wp-includes/version.php b/wp-includes/version.php index d968a09e16..4586bacb22 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-beta2-41866'; +$wp_version = '4.9-beta2-41867'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-includes/widgets/class-wp-nav-menu-widget.php b/wp-includes/widgets/class-wp-nav-menu-widget.php index 1674fa8606..86d8fce2fc 100644 --- a/wp-includes/widgets/class-wp-nav-menu-widget.php +++ b/wp-includes/widgets/class-wp-nav-menu-widget.php @@ -42,16 +42,20 @@ class WP_Nav_Menu_Widget extends WP_Widget { // Get menu $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false; - if ( !$nav_menu ) + if ( ! $nav_menu ) { return; + } + + $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ - $instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); + $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); echo $args['before_widget']; - if ( !empty($instance['title']) ) - echo $args['before_title'] . $instance['title'] . $args['after_title']; + if ( $title ) { + echo $args['before_title'] . $title . $args['after_title']; + } $nav_menu_args = array( 'fallback_cb' => '', diff --git a/wp-includes/widgets/class-wp-widget-archives.php b/wp-includes/widgets/class-wp-widget-archives.php index 08c693d613..dac336ecd3 100644 --- a/wp-includes/widgets/class-wp-widget-archives.php +++ b/wp-includes/widgets/class-wp-widget-archives.php @@ -40,13 +40,16 @@ class WP_Widget_Archives extends WP_Widget { * @param array $instance Settings for the current Archives widget instance. */ public function widget( $args, $instance ) { + $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'Archives' ); + + /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ + $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); + $c = ! empty( $instance['count'] ) ? '1' : '0'; $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; - /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ - $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Archives' ) : $instance['title'], $instance, $this->id_base ); - echo $args['before_widget']; + if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; } diff --git a/wp-includes/widgets/class-wp-widget-calendar.php b/wp-includes/widgets/class-wp-widget-calendar.php index 6c59ad1b80..fbd965166d 100644 --- a/wp-includes/widgets/class-wp-widget-calendar.php +++ b/wp-includes/widgets/class-wp-widget-calendar.php @@ -49,8 +49,10 @@ class WP_Widget_Calendar extends WP_Widget { * @param array $instance The settings for the particular instance of the widget. */ public function widget( $args, $instance ) { + $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; + /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ - $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); + $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); echo $args['before_widget']; if ( $title ) { diff --git a/wp-includes/widgets/class-wp-widget-categories.php b/wp-includes/widgets/class-wp-widget-categories.php index 18b8ca849e..35845918c6 100644 --- a/wp-includes/widgets/class-wp-widget-categories.php +++ b/wp-includes/widgets/class-wp-widget-categories.php @@ -44,14 +44,17 @@ class WP_Widget_Categories extends WP_Widget { public function widget( $args, $instance ) { static $first_dropdown = true; + $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'Categories' ); + /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ - $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base ); + $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); $c = ! empty( $instance['count'] ) ? '1' : '0'; $h = ! empty( $instance['hierarchical'] ) ? '1' : '0'; $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; echo $args['before_widget']; + if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; } diff --git a/wp-includes/widgets/class-wp-widget-meta.php b/wp-includes/widgets/class-wp-widget-meta.php index 31220c2428..673976ee54 100644 --- a/wp-includes/widgets/class-wp-widget-meta.php +++ b/wp-includes/widgets/class-wp-widget-meta.php @@ -42,10 +42,13 @@ class WP_Widget_Meta extends WP_Widget { * @param array $instance Settings for the current Meta widget instance. */ public function widget( $args, $instance ) { + $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'Meta' ); + /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ - $title = apply_filters( 'widget_title', empty($instance['title']) ? __( 'Meta' ) : $instance['title'], $instance, $this->id_base ); + $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); echo $args['before_widget']; + if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; } @@ -75,6 +78,7 @@ class WP_Widget_Meta extends WP_Widget { ?> id_base ); + $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby']; $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude']; diff --git a/wp-includes/widgets/class-wp-widget-rss.php b/wp-includes/widgets/class-wp-widget-rss.php index 1a3b88777f..b0a93c8c46 100644 --- a/wp-includes/widgets/class-wp-widget-rss.php +++ b/wp-includes/widgets/class-wp-widget-rss.php @@ -68,8 +68,9 @@ class WP_Widget_RSS extends WP_Widget { $link = substr($link, 1); } - if ( empty($title) ) - $title = empty($desc) ? __('Unknown Feed') : $desc; + if ( empty( $title ) ) { + $title = ! empty( $desc ) ? $desc : __( 'Unknown Feed' ); + } /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); diff --git a/wp-includes/widgets/class-wp-widget-search.php b/wp-includes/widgets/class-wp-widget-search.php index 4ab4098903..b1a5b40356 100644 --- a/wp-includes/widgets/class-wp-widget-search.php +++ b/wp-includes/widgets/class-wp-widget-search.php @@ -40,8 +40,10 @@ class WP_Widget_Search extends WP_Widget { * @param array $instance Settings for the current Search widget instance. */ public function widget( $args, $instance ) { + $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; + /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ - $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); + $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); echo $args['before_widget']; if ( $title ) { diff --git a/wp-includes/widgets/class-wp-widget-tag-cloud.php b/wp-includes/widgets/class-wp-widget-tag-cloud.php index 765d67a7e8..8b486202fc 100644 --- a/wp-includes/widgets/class-wp-widget-tag-cloud.php +++ b/wp-includes/widgets/class-wp-widget-tag-cloud.php @@ -39,14 +39,15 @@ class WP_Widget_Tag_Cloud extends WP_Widget { * @param array $instance Settings for the current Tag Cloud widget instance. */ public function widget( $args, $instance ) { - $current_taxonomy = $this->_get_current_taxonomy($instance); - if ( !empty($instance['title']) ) { + $current_taxonomy = $this->_get_current_taxonomy( $instance ); + + if ( ! empty( $instance['title'] ) ) { $title = $instance['title']; } else { - if ( 'post_tag' == $current_taxonomy ) { - $title = __('Tags'); + if ( 'post_tag' === $current_taxonomy ) { + $title = __( 'Tags' ); } else { - $tax = get_taxonomy($current_taxonomy); + $tax = get_taxonomy( $current_taxonomy ); $title = $tax->labels->name; } } diff --git a/wp-includes/widgets/class-wp-widget-text.php b/wp-includes/widgets/class-wp-widget-text.php index c5ebdd41e2..d4fe281f2d 100644 --- a/wp-includes/widgets/class-wp-widget-text.php +++ b/wp-includes/widgets/class-wp-widget-text.php @@ -192,8 +192,10 @@ class WP_Widget_Text extends WP_Widget { public function widget( $args, $instance ) { global $post; + $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; + /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ - $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); + $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); $text = ! empty( $instance['text'] ) ? $instance['text'] : ''; $is_visual_text_widget = ( ! empty( $instance['visual'] ) && ! empty( $instance['filter'] ) );