Make WordPress Core

Ticket #18650: 18650.7.patch

File 18650.7.patch, 3.0 KB (added by SergeyBiryukov, 10 years ago)
  • src/wp-includes/default-widgets.php

     
    276276                $c = ! empty( $instance['count'] ) ? '1' : '0';
    277277                $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
    278278
     279                $dropdown_id = "{$this->id_base}-dropdown-{$this->number}";
     280
    279281                /** This filter is documented in wp-includes/default-widgets.php */
    280282                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Archives' ) : $instance['title'], $instance, $this->id_base );
    281283
    282284                echo $args['before_widget'];
    283285                if ( $title ) {
     286                        if ( $d ) {
     287                                $title = sprintf( '<label for="%s">%s</label>', esc_attr( $dropdown_id ), $title );
     288                        }
    284289                        echo $args['before_title'] . $title . $args['after_title'];
    285290                }
    286291
    287292                if ( $d ) {
    288293?>
    289                 <select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
     294                <select id="<?php echo esc_attr( $dropdown_id ); ?>" name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
    290295                        <?php
    291296                        /**
    292297                         * Filter the arguments for the Archives widget drop-down.
     
    563568        }
    564569
    565570        public function widget( $args, $instance ) {
     571                static $first_dropdown = true;
    566572
    567573                /** This filter is documented in wp-includes/default-widgets.php */
    568574                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base );
     
    571577                $h = ! empty( $instance['hierarchical'] ) ? '1' : '0';
    572578                $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
    573579
     580                if ( $d ) {
     581                        $dropdown_id = ( $first_dropdown ) ? 'cat' : "{$this->id_base}-dropdown-{$this->number}";
     582                        $first_dropdown = false;
     583                }
     584
    574585                echo $args['before_widget'];
    575586                if ( $title ) {
     587                        if ( $d ) {
     588                                $title = sprintf( '<label for="%s">%s</label>', esc_attr( $dropdown_id ), $title );
     589                        }
    576590                        echo $args['before_title'] . $title . $args['after_title'];
    577591                }
    578592
    579                 $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
     593                $cat_args = array(
     594                        'orderby'      => 'name',
     595                        'show_count'   => $c,
     596                        'hierarchical' => $h
     597                );
    580598
    581599                if ( $d ) {
    582                         $cat_args['show_option_none'] = __('Select Category');
     600                        $cat_args['show_option_none'] = __( 'Select Category' );
     601                        $cat_args['id'] = $dropdown_id;
    583602
    584603                        /**
    585604                         * Filter the arguments for the Categories widget drop-down.
     
    595614
    596615<script type='text/javascript'>
    597616/* <![CDATA[ */
    598         var dropdown = document.getElementById("cat");
     617(function() {
     618        var dropdown = document.getElementById("<?php echo esc_js( $dropdown_id ); ?>");
    599619        function onCatChange() {
    600620                if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
    601621                        location.href = "<?php echo home_url(); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
     
    602622                }
    603623        }
    604624        dropdown.onchange = onCatChange;
     625})();
    605626/* ]]> */
    606627</script>
    607628