Ticket #21165: 21165.3.diff

File 21165.3.diff, 5.2 KB (added by fonglh, 11 months ago)

Changed default value of 'select_name' label from 'Select Taxonomy' to 'Select Category'

Line 
1Index: wp-includes/default-widgets.php
2===================================================================
3--- wp-includes/default-widgets.php     (revision 21220)
4+++ wp-includes/default-widgets.php     (working copy)
5@@ -440,13 +440,13 @@
6 class WP_Widget_Categories extends WP_Widget {
7 
8        function __construct() {
9-               $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories" ) );
10+               $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories or custom taxonomies" ) );
11                parent::__construct('categories', __('Categories'), $widget_ops);
12        }
13 
14        function widget( $args, $instance ) {
15                extract( $args );
16-
17+               $current_taxonomy = $this->_get_current_taxonomy( $instance );
18                $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base);
19                $c = ! empty( $instance['count'] ) ? '1' : '0';
20                $h = ! empty( $instance['hierarchical'] ) ? '1' : '0';
21@@ -456,10 +456,10 @@
22                if ( $title )
23                        echo $before_title . $title . $after_title;
24 
25-               $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
26+               $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h, 'taxonomy' => $current_taxonomy);
27 
28                if ( $d ) {
29-                       $cat_args['show_option_none'] = __('Select Category');
30+                       $cat_args['show_option_none'] = get_taxonomy( $current_taxonomy )->labels->select_name;
31                        wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $cat_args));
32 ?>
33 
34@@ -496,6 +496,7 @@
35                $instance['count'] = !empty($new_instance['count']) ? 1 : 0;
36                $instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
37                $instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
38+               $instance['taxonomy'] = stripslashes( $new_instance['taxonomy'] );
39 
40                return $instance;
41        }
42@@ -507,10 +508,22 @@
43                $count = isset($instance['count']) ? (bool) $instance['count'] :false;
44                $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
45                $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
46+               $current_taxonomy = $this->_get_current_taxonomy( $instance );
47 ?>
48                <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
49                <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>
50 
51+               <p><label for="<?php echo $this->get_field_id( 'taxonomy' ); ?>"><?php _e( 'Taxonomy:' ) ?></label>
52+               <select class="widefat" id="<?php echo $this->get_field_id( 'taxonomy' ); ?>" name="<?php echo $this->get_field_name( 'taxonomy' ); ?>">
53+               <?php foreach ( get_taxonomies() as $taxonomy ) :
54+                                       $tax = get_taxonomy( $taxonomy );
55+                                       if ( ! $tax->hierarchical || empty( $tax->labels->name ) )
56+                                               continue;
57+               ?>
58+               <option value="<?php echo esc_attr( $taxonomy ) ?>" <?php selected( $taxonomy, $current_taxonomy ) ?>><?php echo $tax->labels->name; ?></option>
59+       <?php endforeach; ?>
60+       </select></p>
61+
62                <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 ); ?> />
63                <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Display as dropdown' ); ?></label><br />
64 
65@@ -522,6 +535,14 @@
66 <?php
67        }
68 
69+       function _get_current_taxonomy($instance) {
70+               if ( ! empty( $instance['taxonomy'] ) && taxonomy_exists( $instance['taxonomy'] ) )
71+                       return $instance['taxonomy'];
72+
73+               return 'category';
74+       }
75+
76+
77 }
78 
79 /**
80Index: wp-includes/taxonomy.php
81===================================================================
82--- wp-includes/taxonomy.php    (revision 21220)
83+++ wp-includes/taxonomy.php    (working copy)
84@@ -43,6 +43,9 @@
85 
86        register_taxonomy( 'category', 'post', array(
87                'hierarchical' => true,
88+               'labels' => array(
89+                       'select_name' => __( 'Select Category' )
90+               ),
91                'query_var' => 'category_name',
92                'rewrite' => $rewrite['category'],
93                'public' => true,
94@@ -385,6 +388,7 @@
95  * Accepted keys of the label array in the taxonomy object:
96  * - name - general name for the taxonomy, usually plural. The same as and overridden by $tax->label. Default is Tags/Categories
97  * - singular_name - name for one object of this taxonomy. Default is Tag/Category
98+ * - select_name - prompt to select a taxonomy when using a dropdown list in the Categories widget. Default is 'Select Category'.
99  * - search_items - Default is Search Tags/Search Categories
100  * - popular_items - This string isn't used on hierarchical taxonomies. Default is Popular Tags
101  * - all_items - Default is All Tags/All Categories
102@@ -413,6 +417,7 @@
103        $nohier_vs_hier_defaults = array(
104                'name' => array( _x( 'Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ),
105                'singular_name' => array( _x( 'Tag', 'taxonomy singular name' ), _x( 'Category', 'taxonomy singular name' ) ),
106+               'select_name' => array( null, __( 'Select Category' ) ),
107                'search_items' => array( __( 'Search Tags' ), __( 'Search Categories' ) ),
108                'popular_items' => array( __( 'Popular Tags' ), null ),
109                'all_items' => array( __( 'All Tags' ), __( 'All Categories' ) ),