WordPress.org

Make WordPress Core

Ticket #21165: 21165.8.diff

File 21165.8.diff, 5.4 KB (added by kucrut, 4 years ago)

Refresh patch

  • src/wp-includes/taxonomy-functions.php

    diff --git src/wp-includes/taxonomy-functions.php src/wp-includes/taxonomy-functions.php
    index 280f440..6631bae 100644
    function register_taxonomy( $taxonomy, $object_type, $args = array() ) { 
    458458 *
    459459 * - name - general name for the taxonomy, usually plural. The same as and overridden by $tax->label. Default is Tags/Categories
    460460 * - singular_name - name for one object of this taxonomy. Default is Tag/Category
     461 * - select_name - prompt to select a taxonomy when using a dropdown list in the Categories widget. Default is 'Select Category'.
    461462 * - search_items - Default is Search Tags/Search Categories
    462463 * - popular_items - This string isn't used on hierarchical taxonomies. Default is Popular Tags
    463464 * - all_items - Default is All Tags/All Categories
    function get_taxonomy_labels( $tax ) { 
    496497        $nohier_vs_hier_defaults = array(
    497498                'name' => array( _x( 'Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ),
    498499                'singular_name' => array( _x( 'Tag', 'taxonomy singular name' ), _x( 'Category', 'taxonomy singular name' ) ),
     500                'select_name' => array( null, __( 'Select Category' ) ),
    499501                'search_items' => array( __( 'Search Tags' ), __( 'Search Categories' ) ),
    500502                'popular_items' => array( __( 'Popular Tags' ), null ),
    501503                'all_items' => array( __( 'All Tags' ), __( 'All Categories' ) ),
  • src/wp-includes/widgets/class-wp-widget-categories.php

    diff --git src/wp-includes/widgets/class-wp-widget-categories.php src/wp-includes/widgets/class-wp-widget-categories.php
    index 313041a..dabfc0e 100644
    class WP_Widget_Categories extends WP_Widget { 
    2222        public function widget( $args, $instance ) {
    2323                static $first_dropdown = true;
    2424
     25                $current_taxonomy = $this->_get_current_taxonomy( $instance );
     26
    2527                /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
    2628                $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base );
    2729
    class WP_Widget_Categories extends WP_Widget { 
    3436                        echo $args['before_title'] . $title . $args['after_title'];
    3537                }
    3638
     39                $tax = get_taxonomy( $current_taxonomy );
     40
    3741                $cat_args = array(
    3842                        'orderby'      => 'name',
    3943                        'show_count'   => $c,
    40                         'hierarchical' => $h
     44                        'hierarchical' => $h,
     45                        'taxonomy'     => $current_taxonomy,
    4146                );
    4247
    4348                if ( $d ) {
    class WP_Widget_Categories extends WP_Widget { 
    4651
    4752                        echo '<label class="screen-reader-text" for="' . esc_attr( $dropdown_id ) . '">' . $title . '</label>';
    4853
    49                         $cat_args['show_option_none'] = __( 'Select Category' );
     54                        $cat_args['show_option_none'] = $tax->labels->select_name;
    5055                        $cat_args['id'] = $dropdown_id;
    5156
    5257                        /**
    class WP_Widget_Categories extends WP_Widget { 
    109114                $instance['count'] = !empty($new_instance['count']) ? 1 : 0;
    110115                $instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
    111116                $instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
     117                $instance['taxonomy'] = stripslashes( $new_instance['taxonomy'] );
    112118
    113119                return $instance;
    114120        }
    class WP_Widget_Categories extends WP_Widget { 
    123129                $count = isset($instance['count']) ? (bool) $instance['count'] :false;
    124130                $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
    125131                $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
     132                $current_taxonomy = $this->_get_current_taxonomy( $instance );
    126133?>
    127134                <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
    128135                <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>
    129136
     137                <p>
     138                        <label for="<?php echo esc_attr( $this->get_field_id( 'taxonomy' ) ); ?>"><?php _e( 'Taxonomy:' ) ?></label>
     139                        <select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'taxonomy' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'taxonomy' ) ); ?>">
     140                        <?php foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) : ?>
     141                                <?php
     142                                if ( ! $taxonomy->hierarchical || empty( $taxonomy->labels->name ) ) :
     143                                        continue;
     144                                endif;
     145                                ?>
     146                                <option value="<?php echo esc_attr( $taxonomy->name ); ?>" <?php selected( $taxonomy->name, $current_taxonomy ) ?>><?php echo esc_html( $taxonomy->labels->name ); ?></option>
     147                        <?php endforeach; ?>
     148                        </select>
     149                </p>
     150
    130151                <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 ); ?> />
    131152                <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Display as dropdown' ); ?></label><br />
    132153
    class WP_Widget_Categories extends WP_Widget { 
    138159<?php
    139160        }
    140161
     162        /**
     163         * Retrieves the taxonomy for the current widget instance.
     164         *
     165         * @since 4.4.0
     166         * @access public
     167         *
     168         * @param array $instance Current settings.
     169         * @return string Name of the current taxonomy if set, otherwise 'category'.
     170         */
     171        public function _get_current_taxonomy( $instance ) {
     172                if ( ! empty( $instance['taxonomy'] ) && taxonomy_exists( $instance['taxonomy'] ) ) {
     173                        return $instance['taxonomy'];
     174                }
     175                return 'category';
     176        }
    141177}