WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/22/2010 07:30:05 PM (12 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/meta-boxes.php

    r12789 r12798  
    269269 * @param object $post
    270270 */
    271 function post_categories_meta_box($post) {
    272 ?>
    273 <ul id="category-tabs">
    274     <li class="tabs"><a href="#categories-all" tabindex="3"><?php _e( 'All Categories' ); ?></a></li>
    275     <li class="hide-if-no-js"><a href="#categories-pop" tabindex="3"><?php _e( 'Most Used' ); ?></a></li>
    276 </ul>
    277 
    278 <div id="categories-pop" class="tabs-panel" style="display: none;">
    279     <ul id="categorychecklist-pop" class="categorychecklist form-no-clear" >
    280 <?php $popular_ids = wp_popular_terms_checklist('category'); ?>
    281     </ul>
    282 </div>
    283 
    284 <div id="categories-all" class="tabs-panel">
    285     <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
    286 <?php wp_category_checklist($post->ID, false, false, $popular_ids) ?>
    287     </ul>
    288 </div>
    289 
    290 <?php if ( current_user_can('manage_categories') ) : ?>
    291 <div id="category-adder" class="wp-hidden-children">
    292     <h4><a id="category-add-toggle" href="#category-add" class="hide-if-no-js" tabindex="3"><?php _e( '+ Add New Category' ); ?></a></h4>
    293     <p id="category-add" class="wp-hidden-child">
    294     <label class="screen-reader-text" for="newcat"><?php _e( 'Add New Category' ); ?></label><input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php esc_attr_e( 'New category name' ); ?>" tabindex="3" aria-required="true"/>
    295     <label class="screen-reader-text" for="newcat_parent"><?php _e('Parent category'); ?>:</label><?php wp_dropdown_categories( array( 'hide_empty' => 0, 'name' => 'newcat_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category') ) ); ?>
    296     <input type="button" id="category-add-sumbit" class="add:categorychecklist:category-add button" value="<?php esc_attr_e( 'Add' ); ?>" tabindex="3" />
    297 <?php   wp_nonce_field( 'add-category', '_ajax_nonce', false ); ?>
    298     <span id="category-ajax-response"></span></p>
    299 </div>
    300 <?php
    301 endif;
    302 
     271function post_categories_meta_box( $post, $box ) {
     272    $defaults = array('taxonomy' => 'category');
     273    if ( !isset($box['args']) || !is_array($box['args']) )
     274        $args = array();
     275    else
     276        $args = $box['args'];
     277    extract( wp_parse_args($args, $defaults), EXTR_SKIP );
     278    ?>
     279    <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv">
     280        <ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs">
     281            <li class="tabs"><a href="#<?php echo $taxonomy; ?>-all" tabindex="3"><?php _e( 'All Categories' ); ?></a></li>
     282            <li class="hide-if-no-js"><a href="#<?php echo $taxonomy; ?>-pop" tabindex="3"><?php _e( 'Most Used' ); ?></a></li>
     283        </ul>
     284
     285        <div id="<?php echo $taxonomy; ?>-pop" class="tabs-panel" style="display: none;">
     286            <ul id="<?php echo $taxonomy; ?>checklist-pop" class="categorychecklist form-no-clear" >
     287                <?php $popular_ids = wp_popular_terms_checklist($taxonomy); ?>
     288            </ul>
     289        </div>
     290
     291        <div id="<?php echo $taxonomy; ?>-all" class="tabs-panel">
     292            <ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy?> categorychecklist form-no-clear">
     293                <?php wp_terms_checklist($post->ID, array('taxonomy'=>$taxonomy, 'popular_cats'=> $popular_ids)) ?>
     294            </ul>
     295        </div>
     296
     297    <?php if ( current_user_can('manage_categories') ) : ?>
     298            <div id="<?php echo $taxonomy; ?>-adder" class="wp-hidden-children">
     299                <h4><a id="<?php echo $taxonomy; ?>-add-toggle" href="#<?php echo $taxonomy; ?>-add" class="hide-if-no-js" tabindex="3"><?php _e( '+ Add New Category' ); ?></a></h4>
     300                <p id="<?php echo $taxonomy; ?>-add" class="category-add wp-hidden-child">
     301                    <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>"><?php _e( 'Add New Category' ); ?></label><input type="text" name="new<?php echo $taxonomy; ?>" id="new<?php echo $taxonomy; ?>" class="form-required form-input-tip" value="<?php esc_attr_e( 'New category name' ); ?>" tabindex="3" aria-required="true"/>
     302                    <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>_parent"><?php _e('Parent category'); ?>:</label><?php wp_dropdown_categories( array( 'taxonomy' => $taxonomy, 'hide_empty' => 0, 'name' => 'new'.$taxonomy.'_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('Parent category'), 'tab_index' => 3 ) ); ?>
     303                    <input type="button" id="<?php echo $taxonomy; ?>-add-submit" class="add:<?php echo $taxonomy ?>checklist:<?php echo $taxonomy ?>-add button category-add-sumbit" value="<?php esc_attr_e( 'Add' ); ?>" tabindex="3" />
     304                    <?php wp_nonce_field( 'add-'.$taxonomy, '_ajax_nonce', false ); ?>
     305                    <span id="<?php echo $taxonomy; ?>-ajax-response"></span>
     306                </p>
     307            </div>
     308        <?php endif; ?>
     309    </div>
     310    <?php
    303311}
    304312
Note: See TracChangeset for help on using the changeset viewer.