From 7fd6ab93c30879360510373b088b51244c9a2cc1 Mon Sep 17 00:00:00 2001 From: westi Date: Thu, 15 Sep 2011 09:41:17 +0000 Subject: [PATCH] Fix Notices in default Widgets when called using the_widget(). Fixes #16761 props mfields and SergeyBiryukov git-svn-id: http://svn.automattic.com/wordpress/trunk@18676 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/default-widgets.php | 38 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/wp-includes/default-widgets.php b/wp-includes/default-widgets.php index d9b932a8e1..e91b91dfb4 100644 --- a/wp-includes/default-widgets.php +++ b/wp-includes/default-widgets.php @@ -177,7 +177,7 @@ class WP_Widget_Search extends WP_Widget { function widget( $args, $instance ) { extract($args); - $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); echo $before_widget; if ( $title ) @@ -220,8 +220,8 @@ class WP_Widget_Archives extends WP_Widget { function widget( $args, $instance ) { extract($args); - $c = $instance['count'] ? '1' : '0'; - $d = $instance['dropdown'] ? '1' : '0'; + $c = ! empty( $instance['count'] ) ? '1' : '0'; + $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; $title = apply_filters('widget_title', empty($instance['title']) ? __('Archives') : $instance['title'], $instance, $this->id_base); echo $before_widget; @@ -375,11 +375,11 @@ class WP_Widget_Text extends WP_Widget { function widget( $args, $instance ) { extract($args); - $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); - $text = apply_filters( 'widget_text', $instance['text'], $instance ); + $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); + $text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance ); echo $before_widget; if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?> -
+
id_base); - $c = $instance['count'] ? '1' : '0'; - $h = $instance['hierarchical'] ? '1' : '0'; - $d = $instance['dropdown'] ? '1' : '0'; + $c = ! empty( $instance['count'] ) ? '1' : '0'; + $h = ! empty( $instance['hierarchical'] ) ? '1' : '0'; + $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; echo $before_widget; if ( $title ) @@ -525,8 +525,8 @@ class WP_Widget_Recent_Posts extends WP_Widget { if ( !is_array($cache) ) $cache = array(); - if ( isset($cache[$args['widget_id']]) ) { - echo $cache[$args['widget_id']]; + if ( isset( $args['widget_id'] ) && isset( $cache[ $args['widget_id'] ] ) ) { + echo $cache[ $args['widget_id'] ]; return; } @@ -534,7 +534,7 @@ class WP_Widget_Recent_Posts extends WP_Widget { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base); - if ( ! $number = absint( $instance['number'] ) ) + if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) ) $number = 10; $r = new WP_Query(array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true)); @@ -628,8 +628,8 @@ class WP_Widget_Recent_Comments extends WP_Widget { if ( ! is_array( $cache ) ) $cache = array(); - if ( isset( $cache[$args['widget_id']] ) ) { - echo $cache[$args['widget_id']]; + if ( isset( $args['widget_id'] ) && isset( $cache[ $args['widget_id'] ] ) ) { + echo $cache[ $args['widget_id'] ]; return; } @@ -637,7 +637,7 @@ class WP_Widget_Recent_Comments extends WP_Widget { $output = ''; $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title']); - if ( ! $number = absint( $instance['number'] ) ) + if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) ) $number = 5; $comments = get_comments( array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) ); @@ -705,7 +705,7 @@ class WP_Widget_RSS extends WP_Widget { extract($args, EXTR_SKIP); - $url = $instance['url']; + $url = ! empty( $instance['url'] ) ? $instance['url'] : ''; while ( stristr($url, 'http') != $url ) $url = substr($url, 1); @@ -751,7 +751,7 @@ class WP_Widget_RSS extends WP_Widget { } function update($new_instance, $old_instance) { - $testurl = ( isset($new_instance['url']) && ($new_instance['url'] != $old_instance['url']) ); + $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) ); return wp_widget_rss_process( $new_instance, $testurl ); } @@ -1059,12 +1059,12 @@ class WP_Widget_Tag_Cloud extends WP_Widget { function widget($args, $instance) { // Get menu - $nav_menu = wp_get_nav_menu_object( $instance['nav_menu'] ); + $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false; if ( !$nav_menu ) return; - $instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); + $instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); echo $args['before_widget'];