Make WordPress Core

Changeset 12694


Ignore:
Timestamp:
01/11/2010 07:27:44 PM (12 years ago)
Author:
ryan
Message:

Show custom hierarchical taxonomies in the menus. Props dd32. see #11838

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/categories.php

    r12616 r12694  
    1212$title = __('Categories');
    1313
    14 wp_reset_vars( array('action') );
     14wp_reset_vars( array('action', 'taxonomy', 'post_type') );
     15
     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
    1533
    1634if ( isset( $_GET['action'] ) && isset($_GET['delete']) && ( 'delete' == $_GET['action'] || 'delete' == $_GET['action2'] ) )
     
    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>
     
    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>
     
    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
     
    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(
     
    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>
     
    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
     
    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'); ?>
     
    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>
  • trunk/wp-admin/includes/taxonomy.php

    r12662 r12694  
    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);
     
    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) ) {
  • trunk/wp-admin/includes/template.php

    r12652 r12694  
    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;
     
    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'];
     
    3737    }
    3838
    39     $children = _get_term_hierarchy('category');
    40 
    41     _cat_rows( $parent, $level, $categories, $children, $page, $per_page, $count );
     39    $children = _get_term_hierarchy($taxonomy);
     40
     41    echo _cat_rows( $parent, $level, $categories, $children, $page, $per_page, $count );
    4242
    4343}
     
    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 ) {
     
    6060    $start = ($page - 1) * $per_page;
    6161    $end = $start + $per_page;
    62     ob_start();
    63 
     62
     63    $output = '';
    6464    foreach ( $categories as $key => $category ) {
    6565        if ( $count >= $end )
     
    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            }
     
    9090
    9191        if ( $count >= $start )
    92             echo "\t" . _cat_row( $category, $level );
     92            $output .= "\t" . _cat_row( $category, $level );
    9393
    9494        unset( $categories[ $key ] );
     
    9797
    9898        if ( isset($children[$category->term_id]) )
    99             _cat_rows( $category->term_id, $level + 1, $categories, $children, $page, $per_page, $count );
    100     }
    101 
    102     $output = ob_get_contents();
    103     ob_end_clean();
    104 
    105     echo $output;
     99            $output .= _cat_rows( $category->term_id, $level + 1, $categories, $children, $page, $per_page, $count );
     100    }
     101
     102    return $output;
    106103}
    107104
     
    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>
     
    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" />
     
    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>
  • trunk/wp-admin/menu.php

    r12673 r12694  
    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    }
    56 
    57     $submenu['edit.php'][50] = array( __('Categories'), 'manage_categories', 'categories.php' );
    5859
    5960$menu[10] = array( __('Media'), 'upload_files', 'upload.php', '', 'menu-top', 'menu-media', 'div' );
     
    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    }
  • trunk/wp-includes/category-template.php

    r12598 r12694  
    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
     
    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 ) {
     
    382385
    383386        $output .= walk_category_dropdown_tree( $categories, $depth, $r );
     387    }
     388    if ( ! $r['hide_if_empty'] || ! empty($categories) )
    384389        $output .= "</select>\n";
    385     }
     390
    386391
    387392    $output = apply_filters( 'wp_dropdown_cats', $output );
  • trunk/wp-includes/category.php

    r12515 r12694  
    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
Note: See TracChangeset for help on using the changeset viewer.