WordPress.org

Make WordPress Core

Ticket #11838: 11838.2.patch

File 11838.2.patch, 14.1 KB (added by dd32, 8 years ago)
  • wp-admin/categories.php

     
    1111
    1212$title = __('Categories');
    1313
    14 wp_reset_vars( array('action') );
     14wp_reset_vars( array('action', 'taxonomy', 'post_type') );
    1515
     16if ( empty($taxonomy) )
     17        $taxonomy = 'category';
     18
     19if ( !is_taxonomy($taxonomy) )
     20        wp_die(__('Invalid taxonomy'));
     21
     22if ( empty($post_type) || !in_array( $post_type, get_post_types( array('_show' => true) ) ) )
     23        $post_type = 'post';
     24
     25if ( 'post' != $post_type ) {
     26        $parent_file = "edit.php?post_type=$post_type";
     27        $submenu_file = "categories.php?taxonomy=$taxonomy&post_type=$post_type";
     28} else {
     29        $parent_file = 'edit.php';
     30        $submenu_file = "categories.php?taxonomy=$taxonomy";   
     31}
     32
     33
    1634if ( isset( $_GET['action'] ) && isset($_GET['delete']) && ( 'delete' == $_GET['action'] || 'delete' == $_GET['action2'] ) )
    1735        $action = 'bulk-delete';
    1836
     
    135153<div class="wrap nosubsub">
    136154<?php screen_icon(); ?>
    137155<h2><?php echo esc_html( $title );
    138 if ( isset($_GET['s']) && $_GET['s'] )
     156if ( !empty($_GET['s']) )
    139157        printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( stripslashes($_GET['s']) ) ); ?>
    140158</h2>
    141159
     
    146164endif; ?>
    147165
    148166<form class="search-form topmargin" action="" method="get">
     167<input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
     168<input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
    149169<p class="search-box">
    150170        <label class="screen-reader-text" for="category-search-input"><?php _e('Search Categories'); ?>:</label>
    151171        <input type="text" id="category-search-input" name="s" value="<?php _admin_search_query(); ?>" />
     
    159179<div id="col-right">
    160180<div class="col-wrap">
    161181<form id="posts-filter" action="" method="get">
     182<input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
     183<input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
    162184<div class="tablenav">
    163185
    164186<?php
     
    172194$cats_per_page = apply_filters( 'edit_categories_per_page', $cats_per_page );
    173195
    174196if ( !empty($_GET['s']) )
    175         $num_cats = count(get_categories(array('hide_empty' => 0, 'search' => $_GET['s'])));
     197        $num_cats = count(get_categories(array('taxonomy' => $taxonomy, 'hide_empty' => 0, 'search' => $_GET['s'])));
    176198else
    177         $num_cats = wp_count_terms('category');
     199        $num_cats = wp_count_terms($taxonomy);
    178200
    179201$page_links = paginate_links( array(
    180202        'base' => add_query_arg( 'pagenum', '%#%' ),
     
    218240
    219241        <tbody id="the-list" class="list:cat">
    220242<?php
    221 cat_rows(0, 0, 0, $pagenum, $cats_per_page);
     243cat_rows(0, 0, 0, $pagenum, $cats_per_page, $taxonomy);
    222244?>
    223245        </tbody>
    224246</table>
     
    244266</form>
    245267
    246268<div class="form-wrap">
    247 <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>
     269<?php if ( get_option('default_' . $taxonomy) ) : ?>
     270<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>
     271<?php endif; ?>
     272<?php if ( 'category' == $taxonomy ) : ?>
    248273<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>
     274<?php endif; ?>
    249275</div>
    250276
    251277</div>
     
    261287<h3><?php _e('Add Category'); ?></h3>
    262288<div id="ajax-response"></div>
    263289<form name="addcat" id="addcat" method="post" action="categories.php" class="add:the-list: validate">
     290<input type="hidden" name="taxonomy" value="<?php echo esc_attr($taxonomy); ?>" />
     291<input type="hidden" name="post_type" value="<?php echo esc_attr($post_type); ?>" />
    264292<input type="hidden" name="action" value="addcat" />
    265293<?php wp_original_referer_field(true, 'previous'); wp_nonce_field('add-category'); ?>
    266294
     
    278306
    279307<div class="form-field">
    280308        <label for="category_parent"><?php _e('Category Parent') ?></label>
    281         <?php wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'category_parent', 'orderby' => 'name', 'selected' => $category->parent, 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
     309        <?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'))); ?>
    282310    <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>
    283311</div>
    284312
  • wp-admin/includes/taxonomy.php

     
    108108 * @return unknown
    109109 */
    110110function wp_insert_category($catarr, $wp_error = false) {
    111         $cat_defaults = array('cat_ID' => 0, 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => '');
     111        $cat_defaults = array('cat_ID' => 0, 'taxonomy' => 'category', 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => '');
    112112        $catarr = wp_parse_args($catarr, $cat_defaults);
    113113        extract($catarr, EXTR_SKIP);
    114114
     
    142142        $args = compact('name', 'slug', 'parent', 'description');
    143143
    144144        if ( $update )
    145                 $cat_ID = wp_update_term($cat_ID, 'category', $args);
     145                $cat_ID = wp_update_term($cat_ID, $taxonomy, $args);
    146146        else
    147                 $cat_ID = wp_insert_term($cat_name, 'category', $args);
     147                $cat_ID = wp_insert_term($cat_name, $taxonomy, $args);
    148148
    149149        if ( is_wp_error($cat_ID) ) {
    150150                if ( $wp_error )
  • wp-admin/includes/template.php

     
    2020 * @param unknown_type $page
    2121 * @param unknown_type $per_page
    2222 */
    23 function cat_rows( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_page = 20 ) {
     23function cat_rows( $parent = 0, $level = 0, $categories = 0, $page = 1, $per_page = 20, $taxonomy = 'category' ) {
    2424
    2525        $count = 0;
    2626
    2727        if ( empty($categories) ) {
    2828
    29                 $args = array('hide_empty' => 0);
     29                $args = array('hide_empty' => 0, 'taxonomy' => $taxonomy);
    3030                if ( !empty($_GET['s']) )
    3131                        $args['search'] = $_GET['s'];
    3232
     
    3636                        return false;
    3737        }
    3838
    39         $children = _get_term_hierarchy('category');
     39        $children = _get_term_hierarchy($taxonomy);
    4040
    41         _cat_rows( $parent, $level, $categories, $children, $page, $per_page, $count );
     41        echo _cat_rows( $parent, $level, $categories, $children, $page, $per_page, $count );
    4242
    4343}
    4444
     
    5353 * @param unknown_type $level
    5454 * @param unknown_type $page
    5555 * @param unknown_type $per_page
    56  * @return unknown
     56 * @return string the output of the table.
    5757 */
    5858function _cat_rows( $parent = 0, $level = 0, $categories, &$children, $page = 1, $per_page = 20, &$count ) {
    5959
    6060        $start = ($page - 1) * $per_page;
    6161        $end = $start + $per_page;
    62         ob_start();
    6362
     63        $output = '';
    6464        foreach ( $categories as $key => $category ) {
    6565                if ( $count >= $end )
    6666                        break;
     
    8383
    8484                        $num_parents = count($my_parents);
    8585                        while( $my_parent = array_pop($my_parents) ) {
    86                                 echo "\t" . _cat_row( $my_parent, $level - $num_parents );
     86                                $output = "\t" . _cat_row( $my_parent, $level - $num_parents );
    8787                                $num_parents--;
    8888                        }
    8989                }
    9090
    9191                if ( $count >= $start )
    92                         echo "\t" . _cat_row( $category, $level );
     92                        $output .= "\t" . _cat_row( $category, $level );
    9393
    9494                unset( $categories[ $key ] );
    9595
    9696                $count++;
    9797
    9898                if ( isset($children[$category->term_id]) )
    99                         _cat_rows( $category->term_id, $level + 1, $categories, $children, $page, $per_page, $count );
     99                        $output .= _cat_rows( $category->term_id, $level + 1, $categories, $children, $page, $per_page, $count );
    100100        }
    101101
    102         $output = ob_get_contents();
    103         ob_end_clean();
    104 
    105         echo $output;
     102        return $output;
    106103}
    107104
    108105/**
     
    25682565?>
    25692566</select>
    25702567<input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" tabindex="7" value="" />
    2571 <a href="#postcustomstuff" class="hide-if-no-js" onClick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
     2568<a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
    25722569<span id="enternew"><?php _e('Enter new'); ?></span>
    25732570<span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a>
    25742571<?php } else { ?>
     
    32393236                                <?php wp_nonce_field( 'find-posts', '_ajax_nonce', false ); ?>
    32403237                                <label class="screen-reader-text" for="find-posts-input"><?php _e( 'Search' ); ?></label>
    32413238                                <input type="text" id="find-posts-input" name="ps" value="" />
    3242                                 <input type="button" onClick="findPosts.send();" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br />
     3239                                <input type="button" onclick="findPosts.send();" value="<?php esc_attr_e( 'Search' ); ?>" class="button" /><br />
    32433240
    32443241                                <input type="radio" name="find-posts-what" id="find-posts-posts" checked="checked" value="posts" />
    32453242                                <label for="find-posts-posts"><?php _e( 'Posts' ); ?></label>
     
    32493246                        <div id="find-posts-response"></div>
    32503247                </div>
    32513248                <div class="find-box-buttons">
    3252                         <input type="button" class="button alignleft" onClick="findPosts.close();" value="<?php esc_attr_e('Close'); ?>" />
     3249                        <input type="button" class="button alignleft" onclick="findPosts.close();" value="<?php esc_attr_e('Close'); ?>" />
    32533250                        <input id="find-posts-submit" type="submit" class="button-primary alignright" value="<?php esc_attr_e('Select'); ?>" />
    32543251                </div>
    32553252        </div>
  • wp-admin/menu.php

     
    4747
    4848        $i = 15;
    4949        foreach ( $wp_taxonomies as $tax ) {
    50                 if ( $tax->hierarchical || ! in_array('post', (array) $tax->object_type, true) )
     50                if ( ! in_array('post', (array) $tax->object_type, true) )
    5151                        continue;
    5252
    53                 $submenu['edit.php'][$i] = array( esc_attr($tax->label), 'manage_categories', 'edit-tags.php?taxonomy=' . $tax->name );
     53                if ( $tax->hierarchical )
     54                        $submenu['edit.php'][$i] = array( esc_attr($tax->label), 'manage_categories', 'categories.php?taxonomy=' . $tax->name );
     55                else
     56                        $submenu['edit.php'][$i] = array( esc_attr($tax->label), 'manage_categories', 'edit-tags.php?taxonomy=' . $tax->name );
    5457                ++$i;
    5558        }
    5659
    57         $submenu['edit.php'][50] = array( __('Categories'), 'manage_categories', 'categories.php' );
    58 
    5960$menu[10] = array( __('Media'), 'upload_files', 'upload.php', '', 'menu-top', 'menu-media', 'div' );
    6061        $submenu['upload.php'][5] = array( __('Library'), 'upload_files', 'upload.php');
    6162        /* translators: add new file */
     
    8687
    8788        $i = 15;
    8889        foreach ( $wp_taxonomies as $tax ) {
    89                 if ( $tax->hierarchical || ! in_array($ptype, (array) $tax->object_type, true) )
     90                if ( ! in_array($ptype, (array) $tax->object_type, true) )
    9091                        continue;
    9192
    92                 $submenu["edit.php?post_type=$ptype"][$i] = array( esc_attr($tax->label), 'manage_categories', "edit-tags.php?taxonomy=$tax->name&amp;post_type=$ptype" );
     93                if ( $tax->hierarchical )
     94                        $submenu["edit.php?post_type=$ptype"][$i] = array( esc_attr($tax->label), 'manage_categories', "categories.php?taxonomy=$tax->name&amp;post_type=$ptype" );
     95                else
     96                        $submenu["edit.php?post_type=$ptype"][$i] = array( esc_attr($tax->label), 'manage_categories', "edit-tags.php?taxonomy=$tax->name&amp;post_type=$ptype" );
    9397                ++$i;
    9498        }
    9599}
  • wp-includes/category-template.php

     
    337337                'exclude' => '', 'echo' => 1,
    338338                'selected' => 0, 'hierarchical' => 0,
    339339                'name' => 'cat', 'class' => 'postform',
    340                 'depth' => 0, 'tab_index' => 0
     340                'depth' => 0, 'tab_index' => 0,
     341                'taxonomy' => 'category', 'hide_if_empty' => false
    341342        );
    342343
    343344        $defaults['selected'] = ( is_category() ) ? get_query_var( 'cat' ) : 0;
     
    359360        $name = esc_attr($name);
    360361        $class = esc_attr($class);
    361362
    362         $output = '';
     363        if ( ! $r['hide_if_empty'] || ! empty($categories) )
     364                $output = "<select name='$name' id='$name' class='$class' $tab_index_attribute>\n";
     365        else
     366                $output = '';
    363367        if ( ! empty( $categories ) ) {
    364                 $output = "<select name='$name' id='$name' class='$class' $tab_index_attribute>\n";
    365368
    366369                if ( $show_option_all ) {
    367370                        $show_option_all = apply_filters( 'list_cats', $show_option_all );
     
    381384                        $depth = -1; // Flat.
    382385
    383386                $output .= walk_category_dropdown_tree( $categories, $depth, $r );
     387        }
     388        if ( ! $r['hide_if_empty'] || ! empty($categories) )
    384389                $output .= "</select>\n";
    385         }
    386390
     391
    387392        $output = apply_filters( 'wp_dropdown_cats', $output );
    388393
    389394        if ( $echo )
  • wp-includes/category.php

     
    3737 * @return array List of categories.
    3838 */
    3939function &get_categories( $args = '' ) {
    40         $defaults = array( 'type' => 'category' );
     40        $defaults = array( 'taxonomy' => 'category' );
    4141        $args = wp_parse_args( $args, $defaults );
    4242
    43         $taxonomy = apply_filters( 'get_categories_taxonomy', 'category', $args );
    44         if ( 'link' == $args['type'] )
    45                 $taxonomy = 'link_category';
     43        $taxonomy = apply_filters( 'get_categories_taxonomy', $args['taxonomy'], $args );
     44
     45        if ( isset($args['type']) && 'link' == $args['type'] ) //Back compat
     46                $taxonomy = $args['taxonomy'] = 'link_category';
     47
    4648        $categories = (array) get_terms( $taxonomy, $args );
    4749
    4850        foreach ( array_keys( $categories ) as $k )