]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/default-widgets.php
WordPress 4.3
[autoinstalls/wordpress.git] / wp-includes / default-widgets.php
index d54dbc732c8fcbfd470097832ef395d21a78d563..22e61e532c0ff7621c40e1578f906f88830d52be 100644 (file)
@@ -18,6 +18,10 @@ class WP_Widget_Pages extends WP_Widget {
                parent::__construct('pages', __('Pages'), $widget_ops);
        }
 
                parent::__construct('pages', __('Pages'), $widget_ops);
        }
 
+       /**
+        * @param array $args
+        * @param array $instance
+        */
        public function widget( $args, $instance ) {
 
                /**
        public function widget( $args, $instance ) {
 
                /**
@@ -67,6 +71,11 @@ class WP_Widget_Pages extends WP_Widget {
                }
        }
 
                }
        }
 
+       /**
+        * @param array $new_instance
+        * @param array $old_instance
+        * @return array
+        */
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $instance['title'] = strip_tags($new_instance['title']);
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $instance['title'] = strip_tags($new_instance['title']);
@@ -81,6 +90,9 @@ class WP_Widget_Pages extends WP_Widget {
                return $instance;
        }
 
                return $instance;
        }
 
+       /**
+        * @param array $instance
+        */
        public function form( $instance ) {
                //Defaults
                $instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') );
        public function form( $instance ) {
                //Defaults
                $instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') );
@@ -118,8 +130,11 @@ class WP_Widget_Links extends WP_Widget {
                parent::__construct('links', __('Links'), $widget_ops);
        }
 
                parent::__construct('links', __('Links'), $widget_ops);
        }
 
+       /**
+        * @param array $args
+        * @param array $instance
+        */
        public function widget( $args, $instance ) {
        public function widget( $args, $instance ) {
-
                $show_description = isset($instance['description']) ? $instance['description'] : false;
                $show_name = isset($instance['name']) ? $instance['name'] : false;
                $show_rating = isset($instance['rating']) ? $instance['rating'] : false;
                $show_description = isset($instance['description']) ? $instance['description'] : false;
                $show_name = isset($instance['name']) ? $instance['name'] : false;
                $show_rating = isset($instance['rating']) ? $instance['rating'] : false;
@@ -151,6 +166,11 @@ class WP_Widget_Links extends WP_Widget {
                ) ) );
        }
 
                ) ) );
        }
 
+       /**
+        * @param array $new_instance
+        * @param array $old_instance
+        * @return array
+        */
        public function update( $new_instance, $old_instance ) {
                $new_instance = (array) $new_instance;
                $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );
        public function update( $new_instance, $old_instance ) {
                $new_instance = (array) $new_instance;
                $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );
@@ -169,6 +189,9 @@ class WP_Widget_Links extends WP_Widget {
                return $instance;
        }
 
                return $instance;
        }
 
+       /**
+        * @param array $instance
+        */
        public function form( $instance ) {
 
                //Defaults
        public function form( $instance ) {
 
                //Defaults
@@ -227,8 +250,11 @@ class WP_Widget_Search extends WP_Widget {
                parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops );
        }
 
                parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops );
        }
 
+       /**
+        * @param array $args
+        * @param array $instance
+        */
        public function widget( $args, $instance ) {
        public function widget( $args, $instance ) {
-
                /** This filter is documented in wp-includes/default-widgets.php */
                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
 
                /** This filter is documented in wp-includes/default-widgets.php */
                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
 
@@ -243,6 +269,9 @@ class WP_Widget_Search extends WP_Widget {
                echo $args['after_widget'];
        }
 
                echo $args['after_widget'];
        }
 
+       /**
+        * @param array $instance
+        */
        public function form( $instance ) {
                $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
                $title = $instance['title'];
        public function form( $instance ) {
                $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
                $title = $instance['title'];
@@ -251,6 +280,11 @@ class WP_Widget_Search extends WP_Widget {
 <?php
        }
 
 <?php
        }
 
+       /**
+        * @param array $new_instance
+        * @param array $old_instance
+        * @return array
+        */
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
@@ -272,6 +306,10 @@ class WP_Widget_Archives extends WP_Widget {
                parent::__construct('archives', __('Archives'), $widget_ops);
        }
 
                parent::__construct('archives', __('Archives'), $widget_ops);
        }
 
+       /**
+        * @param array $args
+        * @param array $instance
+        */
        public function widget( $args, $instance ) {
                $c = ! empty( $instance['count'] ) ? '1' : '0';
                $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
        public function widget( $args, $instance ) {
                $c = ! empty( $instance['count'] ) ? '1' : '0';
                $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
@@ -285,10 +323,10 @@ class WP_Widget_Archives extends WP_Widget {
                }
 
                if ( $d ) {
                }
 
                if ( $d ) {
+                       $dropdown_id = "{$this->id_base}-dropdown-{$this->number}";
 ?>
 ?>
-               <select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
-                       <option value=""><?php echo esc_attr( __( 'Select Month' ) ); ?></option>
-
+               <label class="screen-reader-text" for="<?php echo esc_attr( $dropdown_id ); ?>"><?php echo $title; ?></label>
+               <select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
                        <?php
                        /**
                         * Filter the arguments for the Archives widget drop-down.
                        <?php
                        /**
                         * Filter the arguments for the Archives widget drop-down.
@@ -299,12 +337,34 @@ class WP_Widget_Archives extends WP_Widget {
                         *
                         * @param array $args An array of Archives widget drop-down arguments.
                         */
                         *
                         * @param array $args An array of Archives widget drop-down arguments.
                         */
-                       wp_get_archives( apply_filters( 'widget_archives_dropdown_args', array(
+                       $dropdown_args = apply_filters( 'widget_archives_dropdown_args', array(
                                'type'            => 'monthly',
                                'format'          => 'option',
                                'show_post_count' => $c
                                'type'            => 'monthly',
                                'format'          => 'option',
                                'show_post_count' => $c
-                       ) ) );
-?>
+                       ) );
+
+                       switch ( $dropdown_args['type'] ) {
+                               case 'yearly':
+                                       $label = __( 'Select Year' );
+                                       break;
+                               case 'monthly':
+                                       $label = __( 'Select Month' );
+                                       break;
+                               case 'daily':
+                                       $label = __( 'Select Day' );
+                                       break;
+                               case 'weekly':
+                                       $label = __( 'Select Week' );
+                                       break;
+                               default:
+                                       $label = __( 'Select Post' );
+                                       break;
+                       }
+                       ?>
+
+                       <option value=""><?php echo esc_attr( $label ); ?></option>
+                       <?php wp_get_archives( $dropdown_args ); ?>
+
                </select>
 <?php
                } else {
                </select>
 <?php
                } else {
@@ -332,6 +392,11 @@ class WP_Widget_Archives extends WP_Widget {
                echo $args['after_widget'];
        }
 
                echo $args['after_widget'];
        }
 
+       /**
+        * @param array $new_instance
+        * @param array $old_instance
+        * @return array
+        */
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
@@ -342,6 +407,9 @@ class WP_Widget_Archives extends WP_Widget {
                return $instance;
        }
 
                return $instance;
        }
 
+       /**
+        * @param array $instance
+        */
        public function form( $instance ) {
                $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
                $title = strip_tags($instance['title']);
        public function form( $instance ) {
                $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
                $title = strip_tags($instance['title']);
@@ -372,8 +440,11 @@ class WP_Widget_Meta extends WP_Widget {
                parent::__construct('meta', __('Meta'), $widget_ops);
        }
 
                parent::__construct('meta', __('Meta'), $widget_ops);
        }
 
+       /**
+        * @param array $args
+        * @param array $instance
+        */
        public function widget( $args, $instance ) {
        public function widget( $args, $instance ) {
-
                /** This filter is documented in wp-includes/default-widgets.php */
                $title = apply_filters( 'widget_title', empty($instance['title']) ? __( 'Meta' ) : $instance['title'], $instance, $this->id_base );
 
                /** This filter is documented in wp-includes/default-widgets.php */
                $title = apply_filters( 'widget_title', empty($instance['title']) ? __( 'Meta' ) : $instance['title'], $instance, $this->id_base );
 
@@ -408,6 +479,11 @@ class WP_Widget_Meta extends WP_Widget {
                echo $args['after_widget'];
        }
 
                echo $args['after_widget'];
        }
 
+       /**
+        * @param array $new_instance
+        * @param array $old_instance
+        * @return array
+        */
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $instance['title'] = strip_tags($new_instance['title']);
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $instance['title'] = strip_tags($new_instance['title']);
@@ -415,6 +491,9 @@ class WP_Widget_Meta extends WP_Widget {
                return $instance;
        }
 
                return $instance;
        }
 
+       /**
+        * @param array $instance
+        */
        public function form( $instance ) {
                $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
                $title = strip_tags($instance['title']);
        public function form( $instance ) {
                $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
                $title = strip_tags($instance['title']);
@@ -436,8 +515,11 @@ class WP_Widget_Calendar extends WP_Widget {
                parent::__construct('calendar', __('Calendar'), $widget_ops);
        }
 
                parent::__construct('calendar', __('Calendar'), $widget_ops);
        }
 
+       /**
+        * @param array $args
+        * @param array $instance
+        */
        public function widget( $args, $instance ) {
        public function widget( $args, $instance ) {
-
                /** This filter is documented in wp-includes/default-widgets.php */
                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
 
                /** This filter is documented in wp-includes/default-widgets.php */
                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
 
@@ -451,6 +533,11 @@ class WP_Widget_Calendar extends WP_Widget {
                echo $args['after_widget'];
        }
 
                echo $args['after_widget'];
        }
 
+       /**
+        * @param array $new_instance
+        * @param array $old_instance
+        * @return array
+        */
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $instance['title'] = strip_tags($new_instance['title']);
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $instance['title'] = strip_tags($new_instance['title']);
@@ -458,6 +545,9 @@ class WP_Widget_Calendar extends WP_Widget {
                return $instance;
        }
 
                return $instance;
        }
 
+       /**
+        * @param array $instance
+        */
        public function form( $instance ) {
                $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
                $title = strip_tags($instance['title']);
        public function form( $instance ) {
                $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
                $title = strip_tags($instance['title']);
@@ -481,8 +571,11 @@ class WP_Widget_Text extends WP_Widget {
                parent::__construct('text', __('Text'), $widget_ops, $control_ops);
        }
 
                parent::__construct('text', __('Text'), $widget_ops, $control_ops);
        }
 
+       /**
+        * @param array $args
+        * @param array $instance
+        */
        public function widget( $args, $instance ) {
        public function widget( $args, $instance ) {
-
                /** This filter is documented in wp-includes/default-widgets.php */
                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
 
                /** This filter is documented in wp-includes/default-widgets.php */
                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
 
@@ -504,6 +597,11 @@ class WP_Widget_Text extends WP_Widget {
                echo $args['after_widget'];
        }
 
                echo $args['after_widget'];
        }
 
+       /**
+        * @param array $new_instance
+        * @param array $old_instance
+        * @return array
+        */
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $instance['title'] = strip_tags($new_instance['title']);
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $instance['title'] = strip_tags($new_instance['title']);
@@ -511,10 +609,13 @@ class WP_Widget_Text extends WP_Widget {
                        $instance['text'] =  $new_instance['text'];
                else
                        $instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
                        $instance['text'] =  $new_instance['text'];
                else
                        $instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
-               $instance['filter'] = isset($new_instance['filter']);
+               $instance['filter'] = ! empty( $new_instance['filter'] );
                return $instance;
        }
 
                return $instance;
        }
 
+       /**
+        * @param array $instance
+        */
        public function form( $instance ) {
                $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
                $title = strip_tags($instance['title']);
        public function form( $instance ) {
                $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
                $title = strip_tags($instance['title']);
@@ -523,7 +624,8 @@ class WP_Widget_Text extends WP_Widget {
                <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
                <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
 
                <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
                <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
 
-               <textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea>
+               <p><label for="<?php echo $this->get_field_id( 'text' ); ?>"><?php _e( 'Content:' ); ?></label>
+               <textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea></p>
 
                <p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked(isset($instance['filter']) ? $instance['filter'] : 0); ?> />&nbsp;<label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p>
 <?php
 
                <p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked(isset($instance['filter']) ? $instance['filter'] : 0); ?> />&nbsp;<label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p>
 <?php
@@ -542,7 +644,14 @@ class WP_Widget_Categories extends WP_Widget {
                parent::__construct('categories', __('Categories'), $widget_ops);
        }
 
                parent::__construct('categories', __('Categories'), $widget_ops);
        }
 
+       /**
+        * @staticvar bool $first_dropdown
+        *
+        * @param array $args
+        * @param array $instance
+        */
        public function widget( $args, $instance ) {
        public function widget( $args, $instance ) {
+               static $first_dropdown = true;
 
                /** This filter is documented in wp-includes/default-widgets.php */
                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base );
 
                /** This filter is documented in wp-includes/default-widgets.php */
                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base );
@@ -556,10 +665,20 @@ class WP_Widget_Categories extends WP_Widget {
                        echo $args['before_title'] . $title . $args['after_title'];
                }
 
                        echo $args['before_title'] . $title . $args['after_title'];
                }
 
-               $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
+               $cat_args = array(
+                       'orderby'      => 'name',
+                       'show_count'   => $c,
+                       'hierarchical' => $h
+               );
 
                if ( $d ) {
 
                if ( $d ) {
-                       $cat_args['show_option_none'] = __('Select Category');
+                       $dropdown_id = ( $first_dropdown ) ? 'cat' : "{$this->id_base}-dropdown-{$this->number}";
+                       $first_dropdown = false;
+
+                       echo '<label class="screen-reader-text" for="' . esc_attr( $dropdown_id ) . '">' . $title . '</label>';
+
+                       $cat_args['show_option_none'] = __( 'Select Category' );
+                       $cat_args['id'] = $dropdown_id;
 
                        /**
                         * Filter the arguments for the Categories widget drop-down.
 
                        /**
                         * Filter the arguments for the Categories widget drop-down.
@@ -575,13 +694,15 @@ class WP_Widget_Categories extends WP_Widget {
 
 <script type='text/javascript'>
 /* <![CDATA[ */
 
 <script type='text/javascript'>
 /* <![CDATA[ */
-       var dropdown = document.getElementById("cat");
+(function() {
+       var dropdown = document.getElementById( "<?php echo esc_js( $dropdown_id ); ?>" );
        function onCatChange() {
        function onCatChange() {
-               if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
-                       location.href = "<?php echo home_url(); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
+               if ( dropdown.options[ dropdown.selectedIndex ].value > 0 ) {
+                       location.href = "<?php echo home_url(); ?>/?cat=" + dropdown.options[ dropdown.selectedIndex ].value;
                }
        }
        dropdown.onchange = onCatChange;
                }
        }
        dropdown.onchange = onCatChange;
+})();
 /* ]]> */
 </script>
 
 /* ]]> */
 </script>
 
@@ -608,6 +729,11 @@ class WP_Widget_Categories extends WP_Widget {
                echo $args['after_widget'];
        }
 
                echo $args['after_widget'];
        }
 
+       /**
+        * @param array $new_instance
+        * @param array $old_instance
+        * @return array
+        */
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $instance['title'] = strip_tags($new_instance['title']);
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $instance['title'] = strip_tags($new_instance['title']);
@@ -618,6 +744,9 @@ class WP_Widget_Categories extends WP_Widget {
                return $instance;
        }
 
                return $instance;
        }
 
+       /**
+        * @param array $instance
+        */
        public function form( $instance ) {
                //Defaults
                $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
        public function form( $instance ) {
                //Defaults
                $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
@@ -659,7 +788,11 @@ class WP_Widget_Recent_Posts extends WP_Widget {
                add_action( 'switch_theme', array($this, 'flush_widget_cache') );
        }
 
                add_action( 'switch_theme', array($this, 'flush_widget_cache') );
        }
 
-       public function widget($args, $instance) {
+       /**
+        * @param array $args
+        * @param array $instance
+        */
+       public function widget( $args, $instance ) {
                $cache = array();
                if ( ! $this->is_preview() ) {
                        $cache = wp_cache_get( 'widget_recent_posts', 'widget' );
                $cache = array();
                if ( ! $this->is_preview() ) {
                        $cache = wp_cache_get( 'widget_recent_posts', 'widget' );
@@ -737,6 +870,11 @@ class WP_Widget_Recent_Posts extends WP_Widget {
                }
        }
 
                }
        }
 
+       /**
+        * @param array $new_instance
+        * @param array $old_instance
+        * @return array
+        */
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $instance['title'] = strip_tags($new_instance['title']);
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $instance['title'] = strip_tags($new_instance['title']);
@@ -751,10 +889,16 @@ class WP_Widget_Recent_Posts extends WP_Widget {
                return $instance;
        }
 
                return $instance;
        }
 
+       /**
+        * @access public
+        */
        public function flush_widget_cache() {
                wp_cache_delete('widget_recent_posts', 'widget');
        }
 
        public function flush_widget_cache() {
                wp_cache_delete('widget_recent_posts', 'widget');
        }
 
+       /**
+        * @param array $instance
+        */
        public function form( $instance ) {
                $title     = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
                $number    = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
        public function form( $instance ) {
                $title     = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
                $number    = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
@@ -792,8 +936,10 @@ class WP_Widget_Recent_Comments extends WP_Widget {
                add_action( 'transition_comment_status', array($this, 'flush_widget_cache') );
        }
 
                add_action( 'transition_comment_status', array($this, 'flush_widget_cache') );
        }
 
+       /**
+        * @access public
+        */
        public function recent_comments_style() {
        public function recent_comments_style() {
-
                /**
                 * Filter the Recent Comments default widget styles.
                 *
                /**
                 * Filter the Recent Comments default widget styles.
                 *
@@ -810,10 +956,20 @@ class WP_Widget_Recent_Comments extends WP_Widget {
 <?php
        }
 
 <?php
        }
 
+       /**
+        * @access public
+        */
        public function flush_widget_cache() {
                wp_cache_delete('widget_recent_comments', 'widget');
        }
 
        public function flush_widget_cache() {
                wp_cache_delete('widget_recent_comments', 'widget');
        }
 
+       /**
+        * @global array  $comments
+        * @global object $comment
+        *
+        * @param array $args
+        * @param array $instance
+        */
        public function widget( $args, $instance ) {
                global $comments, $comment;
 
        public function widget( $args, $instance ) {
                global $comments, $comment;
 
@@ -849,7 +1005,7 @@ class WP_Widget_Recent_Comments extends WP_Widget {
                 *
                 * @since 3.4.0
                 *
                 *
                 * @since 3.4.0
                 *
-                * @see get_comments()
+                * @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 $comment_args An array of arguments used to retrieve the recent comments.
                 */
@@ -865,7 +1021,7 @@ class WP_Widget_Recent_Comments extends WP_Widget {
                }
 
                $output .= '<ul id="recentcomments">';
                }
 
                $output .= '<ul id="recentcomments">';
-               if ( $comments ) {
+               if ( is_array( $comments ) && $comments ) {
                        // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
                        $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );
                        _prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false );
                        // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
                        $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );
                        _prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false );
@@ -891,6 +1047,11 @@ class WP_Widget_Recent_Comments extends WP_Widget {
                }
        }
 
                }
        }
 
+       /**
+        * @param array $new_instance
+        * @param array $old_instance
+        * @return array
+        */
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $instance['title'] = strip_tags($new_instance['title']);
        public function update( $new_instance, $old_instance ) {
                $instance = $old_instance;
                $instance['title'] = strip_tags($new_instance['title']);
@@ -904,6 +1065,9 @@ class WP_Widget_Recent_Comments extends WP_Widget {
                return $instance;
        }
 
                return $instance;
        }
 
+       /**
+        * @param array $instance
+        */
        public function form( $instance ) {
                $title  = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
                $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
        public function form( $instance ) {
                $title  = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
                $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
@@ -930,8 +1094,11 @@ class WP_Widget_RSS extends WP_Widget {
                parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops );
        }
 
                parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops );
        }
 
-       public function widget($args, $instance) {
-
+       /**
+        * @param array $args
+        * @param array $instance
+        */
+       public function widget( $args, $instance ) {
                if ( isset($instance['error']) && $instance['error'] )
                        return;
 
                if ( isset($instance['error']) && $instance['error'] )
                        return;
 
@@ -983,15 +1150,23 @@ class WP_Widget_RSS extends WP_Widget {
                unset($rss);
        }
 
                unset($rss);
        }
 
-       public function update($new_instance, $old_instance) {
+       /**
+        * @param array $new_instance
+        * @param array $old_instance
+        * @return array
+        */
+       public function update( $new_instance, $old_instance ) {
                $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
                return wp_widget_rss_process( $new_instance, $testurl );
        }
 
                $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
                return wp_widget_rss_process( $new_instance, $testurl );
        }
 
-       public function form($instance) {
-
-               if ( empty($instance) )
+       /**
+        * @param array $instance
+        */
+       public function form( $instance ) {
+               if ( empty( $instance ) ) {
                        $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
                        $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
+               }
                $instance['number'] = $this->number;
 
                wp_widget_rss_form( $instance );
                $instance['number'] = $this->number;
 
                wp_widget_rss_form( $instance );
@@ -1225,6 +1400,10 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
                parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops);
        }
 
                parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops);
        }
 
+       /**
+        * @param array $args
+        * @param array $instance
+        */
        public function widget( $args, $instance ) {
                $current_taxonomy = $this->_get_current_taxonomy($instance);
                if ( !empty($instance['title']) ) {
        public function widget( $args, $instance ) {
                $current_taxonomy = $this->_get_current_taxonomy($instance);
                if ( !empty($instance['title']) ) {
@@ -1265,12 +1444,21 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
                echo $args['after_widget'];
        }
 
                echo $args['after_widget'];
        }
 
+       /**
+        * @param array $new_instance
+        * @param array $old_instance
+        * @return array
+        */
        public function update( $new_instance, $old_instance ) {
        public function update( $new_instance, $old_instance ) {
+               $instance = array();
                $instance['title'] = strip_tags(stripslashes($new_instance['title']));
                $instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
                return $instance;
        }
 
                $instance['title'] = strip_tags(stripslashes($new_instance['title']));
                $instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
                return $instance;
        }
 
+       /**
+        * @param array $instance
+        */
        public function form( $instance ) {
                $current_taxonomy = $this->_get_current_taxonomy($instance);
 ?>
        public function form( $instance ) {
                $current_taxonomy = $this->_get_current_taxonomy($instance);
 ?>
@@ -1288,6 +1476,10 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
        </select></p><?php
        }
 
        </select></p><?php
        }
 
+       /**
+        * @param array $instance
+        * @return string
+        */
        public function _get_current_taxonomy($instance) {
                if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )
                        return $instance['taxonomy'];
        public function _get_current_taxonomy($instance) {
                if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )
                        return $instance['taxonomy'];
@@ -1308,7 +1500,11 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
                parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops );
        }
 
                parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops );
        }
 
-       public function widget($args, $instance) {
+       /**
+        * @param array $args
+        * @param array $instance
+        */
+       public function widget( $args, $instance ) {
                // Get menu
                $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
 
                // Get menu
                $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
 
@@ -1323,11 +1519,35 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
                if ( !empty($instance['title']) )
                        echo $args['before_title'] . $instance['title'] . $args['after_title'];
 
                if ( !empty($instance['title']) )
                        echo $args['before_title'] . $instance['title'] . $args['after_title'];
 
-               wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu ) );
+               $nav_menu_args = array(
+                       'fallback_cb' => '',
+                       'menu'        => $nav_menu
+               );
+
+               /**
+                * Filter the arguments for the Custom Menu widget.
+                *
+                * @since 4.2.0
+                *
+                * @param array    $nav_menu_args {
+                *     An array of arguments passed to wp_nav_menu() to retrieve a custom menu.
+                *
+                *     @type callback|bool $fallback_cb Callback to fire if the menu doesn't exist. Default empty.
+                *     @type mixed         $menu        Menu ID, slug, or name.
+                * }
+                * @param stdClass $nav_menu      Nav menu object for the current menu.
+                * @param array    $args          Display arguments for the current widget.
+                */
+               wp_nav_menu( apply_filters( 'widget_nav_menu_args', $nav_menu_args, $nav_menu, $args ) );
 
                echo $args['after_widget'];
        }
 
 
                echo $args['after_widget'];
        }
 
+       /**
+        * @param array $new_instance
+        * @param array $old_instance
+        * @return array
+        */
        public function update( $new_instance, $old_instance ) {
                $instance = array();
                if ( ! empty( $new_instance['title'] ) ) {
        public function update( $new_instance, $old_instance ) {
                $instance = array();
                if ( ! empty( $new_instance['title'] ) ) {
@@ -1339,36 +1559,46 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
                return $instance;
        }
 
                return $instance;
        }
 
+       /**
+        * @param array $instance
+        */
        public function form( $instance ) {
                $title = isset( $instance['title'] ) ? $instance['title'] : '';
                $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
 
                // Get menus
        public function form( $instance ) {
                $title = isset( $instance['title'] ) ? $instance['title'] : '';
                $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
 
                // Get menus
-               $menus = wp_get_nav_menus( array( 'orderby' => 'name' ) );
+               $menus = wp_get_nav_menus();
 
                // If no menus exists, direct the user to go and create some.
 
                // If no menus exists, direct the user to go and create some.
-               if ( !$menus ) {
-                       echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
-                       return;
-               }
                ?>
                ?>
-               <p>
-                       <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
-                       <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" />
-               </p>
-               <p>
-                       <label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
-                       <select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
-                               <option value="0"><?php _e( '&mdash; Select &mdash;' ) ?></option>
-               <?php
-                       foreach ( $menus as $menu ) {
-                               echo '<option value="' . $menu->term_id . '"'
-                                       . selected( $nav_menu, $menu->term_id, false )
-                                       . '>'. esc_html( $menu->name ) . '</option>';
+               <p class="nav-menu-widget-no-menus-message" <?php if ( ! empty( $menus ) ) { echo ' style="display:none" '; } ?>>
+                       <?php
+                       if ( isset( $GLOBALS['wp_customize'] ) && $GLOBALS['wp_customize'] instanceof WP_Customize_Manager ) {
+                               // @todo When expanding a panel, the JS should be smart enough to collapse any existing panels and sections.
+                               $url = 'javascript: wp.customize.section.each(function( section ){ section.collapse(); }); wp.customize.panel( "nav_menus" ).focus();';
+                       } else {
+                               $url = admin_url( 'nav-menus.php' );
                        }
                        }
-               ?>
-                       </select>
+                       ?>
+                       <?php echo sprintf( __( 'No menus have been created yet. <a href="%s">Create some</a>.' ), esc_attr( $url ) ); ?>
                </p>
                </p>
+               <div class="nav-menu-widget-form-controls" <?php if ( empty( $menus ) ) { echo ' style="display:none" '; } ?>>
+                       <p>
+                               <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ) ?></label>
+                               <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $title ); ?>"/>
+                       </p>
+                       <p>
+                               <label for="<?php echo $this->get_field_id( 'nav_menu' ); ?>"><?php _e( 'Select Menu:' ); ?></label>
+                               <select id="<?php echo $this->get_field_id( 'nav_menu' ); ?>" name="<?php echo $this->get_field_name( 'nav_menu' ); ?>">
+                                       <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
+                                       <?php foreach ( $menus as $menu ) : ?>
+                                               <option value="<?php echo esc_attr( $menu->term_id ); ?>" <?php selected( $nav_menu, $menu->term_id ); ?>>
+                                                       <?php echo esc_html( $menu->name ); ?>
+                                               </option>
+                                       <?php endforeach; ?>
+                               </select>
+                       </p>
+               </div>
                <?php
        }
 }
                <?php
        }
 }
@@ -1419,5 +1649,3 @@ function wp_widgets_init() {
         */
        do_action( 'widgets_init' );
 }
         */
        do_action( 'widgets_init' );
 }
-
-add_action('init', 'wp_widgets_init', 1);