Ticket #11838: 11838.diff

File 11838.diff, 14.0 KB (added by dd32, 3 years ago)
Line 
1Index: wp-admin/categories.php
2===================================================================
3--- wp-admin/categories.php     (revision 12659)
4+++ wp-admin/categories.php     (working copy)
5@@ -11,8 +11,26 @@
6 
7 $title = __('Categories');
8 
9-wp_reset_vars( array('action') );
10+wp_reset_vars( array('action', 'taxonomy', 'post_type') );
11 
12+if ( empty($taxonomy) )
13+       $taxonomy = 'category';
14+
15+if ( !is_taxonomy($taxonomy) )
16+       wp_die(__('Invalid taxonomy'));
17+
18+if ( empty($post_type) || !in_array( $post_type, get_post_types( array('_show' => true) ) ) )
19+       $post_type = 'post';
20+
21+if ( 'post' != $post_type ) {
22+       $parent_file = "edit.php?post_type=$post_type";
23+       $submenu_file = "categories.php?taxonomy=$taxonomy&post_type=$post_type";
24+} else {
25+       $parent_file = 'edit.php';
26+       $submenu_file = "categories.php?taxonomy=$taxonomy";   
27+}
28+
29+
30 if ( isset( $_GET['action'] ) && isset($_GET['delete']) && ( 'delete' == $_GET['action'] || 'delete' == $_GET['action2'] ) )
31        $action = 'bulk-delete';
32 
33@@ -135,7 +153,7 @@
34 <div class="wrap nosubsub">
35 <?php screen_icon(); ?>
36 <h2><?php echo esc_html( $title );
37-if ( isset($_GET['s']) && $_GET['s'] )
38+if ( !empty($_GET['s']) )
39        printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_GET['s']) ) ); ?>
40 </h2>
41 
42@@ -146,6 +164,8 @@
43 endif; ?>
44 
45 <form class="search-form topmargin" action="" method="get">
46+<input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
47+<input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
48 <p class="search-box">
49        <label class="screen-reader-text" for="category-search-input"><?php _e('Search Categories'); ?>:</label>
50        <input type="text" id="category-search-input" name="s" value="<?php _admin_search_query(); ?>" />
51@@ -159,6 +179,8 @@
52 <div id="col-right">
53 <div class="col-wrap">
54 <form id="posts-filter" action="" method="get">
55+<input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
56+<input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
57 <div class="tablenav">
58 
59 <?php
60@@ -172,9 +194,9 @@
61 $cats_per_page = apply_filters( 'edit_categories_per_page', $cats_per_page );
62 
63 if ( !empty($_GET['s']) )
64-       $num_cats = count(get_categories(array('hide_empty' => 0, 'search' => $_GET['s'])));
65+       $num_cats = count(get_categories(array('taxonomy' => $taxonomy, 'hide_empty' => 0, 'search' => $_GET['s'])));
66 else
67-       $num_cats = wp_count_terms('category');
68+       $num_cats = wp_count_terms($taxonomy);
69 
70 $page_links = paginate_links( array(
71        'base' => add_query_arg( 'pagenum', '%#%' ),
72@@ -218,7 +240,7 @@
73 
74        <tbody id="the-list" class="list:cat">
75 <?php
76-cat_rows(0, 0, 0, $pagenum, $cats_per_page);
77+cat_rows(0, 0, 0, $pagenum, $cats_per_page, $taxonomy);
78 ?>
79        </tbody>
80 </table>
81@@ -244,8 +266,12 @@
82 </form>
83 
84 <div class="form-wrap">
85-<p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete the posts in that category. Instead, posts that were only assigned to the deleted category are set to the category <strong>%s</strong>.'), apply_filters('the_category', get_cat_name(get_option('default_category')))) ?></p>
86+<?php if ( get_option('default_' . $taxonomy) ) : ?>
87+<p><?php printf(__('<strong>Note:</strong><br />Deleting a %1$s does not delete the objects in that %1$s. Instead, objects that were only assigned to the deleted %1$s are set to the %1$s <strong>%2$s</strong>.'), $tax->label, apply_filters('the_category', get_cat_name(get_option('default_' . $taxonomy)))) ?></p>
88+<?php endif; ?>
89+<?php if ( 'category' == $taxonomy ) : ?>
90 <p><?php printf(__('Categories can be selectively converted to tags using the <a href="%s">category to tag converter</a>.'), 'admin.php?import=wp-cat2tag') ?></p>
91+<?php endif; ?>
92 </div>
93 
94 </div>
95@@ -261,6 +287,8 @@
96 <h3><?php _e('Add Category'); ?></h3>
97 <div id="ajax-response"></div>
98 <form name="addcat" id="addcat" method="post" action="categories.php" class="add:the-list: validate">
99+<input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
100+<input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
101 <input type="hidden" name="action" value="addcat" />
102 <?php wp_original_referer_field(true, 'previous'); wp_nonce_field('add-category'); ?>
103 
104@@ -278,7 +306,7 @@
105 
106 <div class="form-field">
107        <label for="category_parent"><?php _e('Category Parent') ?></label>
108-       <?php wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'category_parent', 'orderby' => 'name', 'selected' => $category->parent, 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
109+       <?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'category_parent', 'orderby' => 'name', 'selected' => $category->parent, 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
110     <p><?php _e('Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.'); ?></p>
111 </div>
112 
113Index: wp-admin/includes/taxonomy.php
114===================================================================
115--- wp-admin/includes/taxonomy.php      (revision 12659)
116+++ wp-admin/includes/taxonomy.php      (working copy)
117@@ -108,7 +108,7 @@
118  * @return unknown
119  */
120 function wp_insert_category($catarr, $wp_error = false) {
121-       $cat_defaults = array('cat_ID' => 0, 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => '');
122+       $cat_defaults = array('cat_ID' => 0, 'taxonomy' => 'category', 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => '');
123        $catarr = wp_parse_args($catarr, $cat_defaults);
124        extract($catarr, EXTR_SKIP);
125 
126@@ -142,9 +142,9 @@
127        $args = compact('name', 'slug', 'parent', 'description');
128 
129        if ( $update )
130-               $cat_ID = wp_update_term($cat_ID, 'category', $args);
131+               $cat_ID = wp_update_term($cat_ID, $taxonomy, $args);
132        else
133-               $cat_ID = wp_insert_term($cat_name, 'category', $args);
134+               $cat_ID = wp_insert_term($cat_name, $taxonomy, $args);
135 
136        if ( is_wp_error($cat_ID) ) {
137                if ( $wp_error )
138Index: wp-admin/includes/template.php
139===================================================================
140--- wp-admin/includes/template.php      (revision 12659)
141+++ wp-admin/includes/template.php      (working copy)
142@@ -20,13 +20,13 @@
143  * @param unknown_type $page
144  * @param unknown_type $per_page
145  */
146-function cat_rows( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_page = 20 ) {
147+function cat_rows( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_page = 20, $taxonomy = 'category' ) {
148 
149        $count = 0;
150 
151        if ( empty($categories) ) {
152 
153-               $args = array('hide_empty' => 0);
154+               $args = array('hide_empty' => 0, 'taxonomy' => $taxonomy);
155                if ( !empty($_GET['s']) )
156                        $args['search'] = $_GET['s'];
157 
158@@ -36,7 +36,7 @@
159                        return false;
160        }
161 
162-       $children = _get_term_hierarchy('category');
163+       $children = _get_term_hierarchy($taxonomy);
164 
165        _cat_rows( $parent, $level, $categories, $children, $page, $per_page, $count );
166 
167@@ -59,8 +59,8 @@
168 
169        $start = ($page - 1) * $per_page;
170        $end = $start + $per_page;
171-       ob_start();
172 
173+       $output = '';
174        foreach ( $categories as $key => $category ) {
175                if ( $count >= $end )
176                        break;
177@@ -83,25 +83,22 @@
178 
179                        $num_parents = count($my_parents);
180                        while( $my_parent = array_pop($my_parents) ) {
181-                               echo "\t" . _cat_row( $my_parent, $level - $num_parents );
182+                               $output .=  "\t" . _cat_row( $my_parent, $level - $num_parents );
183                                $num_parents--;
184                        }
185                }
186 
187                if ( $count >= $start )
188-                       echo "\t" . _cat_row( $category, $level );
189+                       $output .= "\t" . _cat_row( $category, $level );
190 
191                unset( $categories[ $key ] );
192 
193                $count++;
194 
195                if ( isset($children[$category->term_id]) )
196-                       _cat_rows( $category->term_id, $level + 1, $categories, $children, $page, $per_page, $count );
197+                       $output .= _cat_rows( $category->term_id, $level + 1, $categories, $children, $page, $per_page, $count );
198        }
199 
200-       $output = ob_get_contents();
201-       ob_end_clean();
202-
203        echo $output;
204 }
205 
206@@ -2568,7 +2565,7 @@
207 ?>
208 </select>
209 <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" />
210-<a href="#postcustomstuff" class="hide-if-no-js" onClick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
211+<a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
212 <span id="enternew"><?php _e('Enter new'); ?></span>
213 <span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a>
214 <?php } else { ?>
215@@ -3239,7 +3236,7 @@
216                                <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
217                                <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
218                                <input type="text" id="find-posts-input" name="ps" value="" />
219-                               <input type="button" onClick="findPosts.send();" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br />
220+                               <input type="button" onclick="findPosts.send();" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br />
221 
222                                <input type="radio" name="find-posts-what" id="find-posts-posts" checked="checked" value="posts" />
223                                <label for="find-posts-posts"><?php _e( 'Posts' ); ?></label>
224@@ -3249,7 +3246,7 @@
225                        <div id="find-posts-response"></div>
226                </div>
227                <div class="find-box-buttons">
228-                       <input type="button" class="button alignleft" onClick="findPosts.close();" value="<?php esc_attr_e('Close'); ?>" />
229+                       <input type="button" class="button alignleft" onclick="findPosts.close();" value="<?php esc_attr_e('Close'); ?>" />
230                        <input id="find-posts-submit" type="submit" class="button-primary alignright" value="<?php esc_attr_e('Select'); ?>" />
231                </div>
232        </div>
233Index: wp-admin/menu.php
234===================================================================
235--- wp-admin/menu.php   (revision 12659)
236+++ wp-admin/menu.php   (working copy)
237@@ -47,15 +47,16 @@
238 
239        $i = 15;
240        foreach ( $wp_taxonomies as $tax ) {
241-               if ( $tax->hierarchical || ! in_array('post', (array) $tax->object_type, true) )
242+               if ( ! in_array('post', (array) $tax->object_type, true) )
243                        continue;
244 
245-               $submenu['edit.php'][$i] = array( esc_attr($tax->label), 'manage_categories', 'edit-tags.php?taxonomy=' . $tax->name );
246+               if ( $tax->hierarchical )
247+                       $submenu['edit.php'][$i] = array( esc_attr($tax->label), 'manage_categories', 'categories.php?taxonomy=' . $tax->name );
248+               else
249+                       $submenu['edit.php'][$i] = array( esc_attr($tax->label), 'manage_categories', 'edit-tags.php?taxonomy=' . $tax->name );
250                ++$i;
251        }
252 
253-       $submenu['edit.php'][50] = array( __('Categories'), 'manage_categories', 'categories.php' );
254-
255 $menu[10] = array( __('Media'), 'upload_files', 'upload.php', '', 'menu-top', 'menu-media', 'div' );
256        $submenu['upload.php'][5] = array( __('Library'), 'upload_files', 'upload.php');
257        /* translators: add new file */
258@@ -86,10 +87,13 @@
259 
260        $i = 15;
261        foreach ( $wp_taxonomies as $tax ) {
262-               if ( $tax->hierarchical || ! in_array($ptype, (array) $tax->object_type, true) )
263+               if ( ! in_array($ptype, (array) $tax->object_type, true) )
264                        continue;
265 
266-               $submenu["edit.php?post_type=$ptype"][$i] = array( esc_attr($tax->label), 'manage_categories', "edit-tags.php?taxonomy=$tax->name&amp;post_type=$ptype" );
267+               if ( $tax->hierarchical )
268+                       $submenu["edit.php?post_type=$ptype"][$i] = array( esc_attr($tax->label), 'manage_categories', "categories.php?taxonomy=$tax->name&amp;post_type=$ptype" );
269+               else
270+                       $submenu["edit.php?post_type=$ptype"][$i] = array( esc_attr($tax->label), 'manage_categories', "edit-tags.php?taxonomy=$tax->name&amp;post_type=$ptype" );
271                ++$i;
272        }
273 }
274Index: wp-includes/category-template.php
275===================================================================
276--- wp-includes/category-template.php   (revision 12659)
277+++ wp-includes/category-template.php   (working copy)
278@@ -337,7 +337,8 @@
279                'exclude' => '', 'echo' => 1,
280                'selected' => 0, 'hierarchical' => 0,
281                'name' => 'cat', 'class' => 'postform',
282-               'depth' => 0, 'tab_index' => 0
283+               'depth' => 0, 'tab_index' => 0,
284+               'taxonomy' => 'category', 'hide_if_empty' => false
285        );
286 
287        $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
288@@ -359,9 +360,11 @@
289        $name = esc_attr($name);
290        $class = esc_attr($class);
291 
292-       $output = '';
293+       if ( ! $r['hide_if_empty'] || ! empty($categories) )
294+               $output = "<select name='$name' id='$name' class='$class' $tab_index_attribute>\n";
295+       else
296+               $output = '';
297        if ( ! empty( $categories ) ) {
298-               $output = "<select name='$name' id='$name' class='$class' $tab_index_attribute>\n";
299 
300                if ( $show_option_all ) {
301                        $show_option_all = apply_filters( 'list_cats', $show_option_all );
302@@ -381,9 +384,11 @@
303                        $depth = -1; // Flat.
304 
305                $output .= walk_category_dropdown_tree( $categories, $depth, $r );
306+       }
307+       if ( ! $r['hide_if_empty'] || ! empty($categories) )
308                $output .= "</select>\n";
309-       }
310 
311+
312        $output = apply_filters( 'wp_dropdown_cats', $output );
313 
314        if ( $echo )
315Index: wp-includes/category.php
316===================================================================
317--- wp-includes/category.php    (revision 12659)
318+++ wp-includes/category.php    (working copy)
319@@ -37,12 +37,13 @@
320  * @return array List of categories.
321  */
322 function &get_categories( $args = '' ) {
323-       $defaults = array( 'type' => 'category' );
324+       $defaults = array( 'taxonomy' => 'category' );
325        $args = wp_parse_args( $args, $defaults );
326 
327-       $taxonomy = apply_filters( 'get_categories_taxonomy', 'category', $args );
328-       if ( 'link' == $args['type'] )
329-               $taxonomy = 'link_category';
330+       if ( isset($args['type']) && 'link' == $args['type'] ) //Back compat
331+               $args['taxonomy'] = 'link_category';
332+
333+       $taxonomy = apply_filters( 'get_categories_taxonomy', $args['taxonomy'], $args );
334        $categories = (array) get_terms( $taxonomy, $args );
335 
336        foreach ( array_keys( $categories ) as $k )