Make WordPress Core


Ignore:
Timestamp:
01/22/2010 07:30:05 PM (17 years ago)
Author:
ryan
Message:

Create metaboxes for hierarchical taxonomies. Props prettyboymp. fixes #10122

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/template.php

    r12797 r12798  
    466466        function start_el(&$output, $category, $depth, $args) {
    467467                extract($args);
     468                if ( empty($taxonomy) )
     469                        $taxonomy = 'category';
     470
     471                if ( $taxonomy == 'category' )
     472                        $name = 'post_category';
     473                else
     474                        $name = 'tax_input['.$taxonomy.']';
    468475
    469476                $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
    470                 $output .= "\n<li id='category-$category->term_id'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="post_category[]" id="in-category-' . $category->term_id . '"' . (in_array( $category->term_id, $selected_cats ) ? ' checked="checked"' : "" ) . '/> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>';
     477                $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' . (in_array( $category->term_id, $selected_cats ) ? ' checked="checked"' : "" ) . '/> ' . esc_html( apply_filters('the_category', $category->name )) . '</label>';
    471478        }
    472479
    … …  
    487494 */
    488495function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null, $checked_ontop = true ) {
     496        wp_terms_checklist($post_id,
     497                array(
     498                        'taxonomy' => 'category',
     499                        'descendants_and_self' => $descendants_and_self,
     500                        'selected_cats' => $selected_cats,
     501                        'popular_cats' => $popular_cats,
     502                        'walker' => $walker,
     503                        'checked_ontop' => $checked_ontop
     504  ));
     505}
     506
     507/**
     508 * Taxonomy independent version of wp_category_checklist
     509 *
     510 * @param int $post_id
     511 * @param array $args
     512 */
     513function wp_terms_checklist($post_id = 0, $args = array()) {
     514        $defaults = array(
     515                'descendants_and_self' => 0,
     516                'selected_cats' => false,
     517                'popular_cats' => false,
     518                'walker' => null,
     519                'taxonomy' => 'category',
     520                'checked_ontop' => true
     521        );
     522        extract( wp_parse_args($args, $defaults), EXTR_SKIP );
     523
    489524        if ( empty($walker) || !is_a($walker, 'Walker') )
    490525                $walker = new Walker_Category_Checklist;
    … …  
    492527        $descendants_and_self = (int) $descendants_and_self;
    493528
    494         $args = array();
     529        $args = array('taxonomy' => $taxonomy);
    495530
    496531        if ( is_array( $selected_cats ) )
    497532                $args['selected_cats'] = $selected_cats;
    498533        elseif ( $post_id )
    499                 $args['selected_cats'] = wp_get_post_categories($post_id);
     534                $args['selected_cats'] = wp_get_object_terms($post_id, $taxonomy, array_merge($args, array('fields' => 'ids')));
    500535        else
    501536                $args['selected_cats'] = array();
    … …  
    504539                $args['popular_cats'] = $popular_cats;
    505540        else
    506                 $args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
     541                $args['popular_cats'] = get_terms( $taxonomy, array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
    507542
    508543        if ( $descendants_and_self ) {
    509                 $categories = get_categories(array('child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0));
    510                 $self = get_category( $descendants_and_self );
     544                $categories = (array) get_terms($taxonomy, array( 'child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0 ) );
     545                $self = get_term( $descendants_and_self, $taxonomy );
    511546                array_unshift( $categories, $self );
    512547        } else {
    513                 $categories = get_categories(array('get' => 'all'));
     548                $categories = (array) get_terms($taxonomy, array('get' => 'all'));
    514549        }
    515550
    … …  
    548583
    549584        if ( $post_ID )
    550                 $checked_categories = wp_get_post_categories($post_ID);
     585                $checked_categories = wp_get_object_terms($post_ID, 'category', array('fields'=>'ids'));
    551586        else
    552587                $checked_categories = array();
    … …  
    559594                if ( !$echo ) // hack for AJAX use
    560595                        continue;
    561                 $id = "popular-category-$category->term_id";
     596                $id = "popular-$taxonomy-$category->term_id";
    562597                $checked = in_array( $category->term_id, $checked_categories ) ? 'checked="checked"' : '';
    563598                ?>
    … …  
    38353870 *
    38363871 * @uses $current_screen
    3837  * 
     3872 *
    38383873 * @param string $id Screen id, optional.
    38393874 */
    … …  
    38523887                $current_screen = array('id' => $id, 'base' => $id);
    38533888        }
    3854        
     3889
    38553890        $current_screen = (object) $current_screen;
    3856        
     3891
    38573892        if ( 'edit' == $current_screen->id ) {
    38583893                if ( empty($typenow) )
    … …  
    38683903                $typenow = '';
    38693904        }
    3870        
     3905
    38713906        $current_screen = apply_filters('current_screen', $current_screen);
    38723907}
Note: See TracChangeset for help on using the changeset viewer.