Ticket #21165: 21165.7.diff
File 21165.7.diff, 3.9 KB (added by , 8 years ago) |
---|
-
src/wp-includes/default-widgets.php
653 653 public function widget( $args, $instance ) { 654 654 static $first_dropdown = true; 655 655 656 $current_taxonomy = $this->_get_current_taxonomy( $instance ); 657 656 658 /** This filter is documented in wp-includes/default-widgets.php */ 657 659 $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base ); 658 660 … … 665 667 echo $args['before_title'] . $title . $args['after_title']; 666 668 } 667 669 670 $tax = get_taxonomy( $current_taxonomy ); 671 668 672 $cat_args = array( 669 673 'orderby' => 'name', 670 674 'show_count' => $c, 671 'hierarchical' => $h 675 'hierarchical' => $h, 676 'taxonomy' => $current_taxonomy 672 677 ); 673 678 674 679 if ( $d ) { … … 677 682 678 683 echo '<label class="screen-reader-text" for="' . esc_attr( $dropdown_id ) . '">' . $title . '</label>'; 679 684 680 $cat_args['show_option_none'] = __( 'Select Category' );685 $cat_args['show_option_none'] = $tax->labels->select_name; 681 686 $cat_args['id'] = $dropdown_id; 682 687 683 688 /** … … 740 745 $instance['count'] = !empty($new_instance['count']) ? 1 : 0; 741 746 $instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0; 742 747 $instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0; 748 $instance['taxonomy'] = stripslashes( $new_instance['taxonomy'] ); 743 749 744 750 return $instance; 745 751 } … … 754 760 $count = isset($instance['count']) ? (bool) $instance['count'] :false; 755 761 $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false; 756 762 $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false; 763 $current_taxonomy = $this->_get_current_taxonomy( $instance ); 757 764 ?> 758 765 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label> 759 766 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p> 760 767 768 <p> 769 <label for="<?php echo esc_attr( $this->get_field_id( 'taxonomy' ) ); ?>"><?php _e( 'Taxonomy:' ) ?></label> 770 <select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'taxonomy' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'taxonomy' ) ); ?>"> 771 <?php foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) : ?> 772 <?php 773 if ( ! $taxonomy->hierarchical || empty( $taxonomy->labels->name ) ) : 774 continue; 775 endif; 776 ?> 777 <option value="<?php echo esc_attr( $taxonomy->name ); ?>" <?php selected( $taxonomy->name, $current_taxonomy ) ?>><?php echo $taxonomy->labels->name; ?></option> 778 <?php endforeach; ?> 779 </select> 780 </p> 781 761 782 <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>"<?php checked( $dropdown ); ?> /> 762 783 <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Display as dropdown' ); ?></label><br /> 763 784 … … 766 787 767 788 <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> /> 768 789 <label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e( 'Show hierarchy' ); ?></label></p> 769 <?php790 <?php 770 791 } 771 792 793 /** 794 * Retrieves the taxonomy for the current widget instance. 795 * 796 * @since 4.4.0 797 * @access public 798 * 799 * @param array $instance Current settings. 800 * @return string Name of the current taxonomy if set, otherwise 'category'. 801 */ 802 public function _get_current_taxonomy( $instance ) { 803 if ( ! empty( $instance['taxonomy'] ) && taxonomy_exists( $instance['taxonomy'] ) ) { 804 return $instance['taxonomy']; 805 } 806 return 'category'; 807 } 808 772 809 } 773 810 774 811 /**