Make WordPress Core

Ticket #10122: hierarchical_metaboxes.patch

File hierarchical_metaboxes.patch, 28.1 KB (added by prettyboymp, 15 years ago)

removed alert left from debugging

  • wp-admin/admin-ajax.php

     
    191191        $x->send();
    192192}
    193193
     194/**
     195 * Handles heirarichal taxonomy meta_box add functions.  Called via admin_ajax
     196 * posts with action: add-{taxonomy name}
     197 *
     198 * @since 2.9
     199 *
     200 */
     201function _wp_ajax_add_heirarichal_term()
     202{
     203        $action = $_POST['action'];
     204        $taxonomy = get_taxonomy(substr($action, 4));
     205        if(!$taxonomy)
     206                die('-1');
     207        check_ajax_referer( $action );
     208        if ( !current_user_can( 'manage_categories' ) )
     209                die('-1');
     210        $names = explode(',', $_POST['new'.$taxonomy->name]);
     211        if ( 0 > $parent = (int) $_POST['new'.$taxonomy->name.'_parent'] )
     212                $parent = 0;
     213        $post_category = isset($_POST['post_category'])? (array) $_POST['post_category'] : array();
     214        $checked_categories = array_map( 'absint', (array) $post_category );
     215        $popular_ids = isset( $_POST['popular_ids'] ) ?
     216                        array_map( 'absint', explode( ',', $_POST['popular_ids'] ) ) :
     217                        false;
     218
     219        $x = new WP_Ajax_Response();
     220        foreach ( $names as $cat_name ) {
     221                $cat_name = trim($cat_name);
     222                $category_nicename = sanitize_title($cat_name);
     223                if ( '' === $category_nicename )
     224                        continue;
     225
     226                if(!($cat_id = is_term($cat_name, $taxonomy->name, $parent))) {
     227                        $cat_id = wp_insert_term($cat_name, $taxonomy->name, array('parent'=>$parent));
     228                }
     229                if ( is_array($cat_id) )
     230                                $cat_id = $cat_id['term_id'];
     231                $checked_categories[] = $cat_id;
     232                if ( $parent ) // Do these all at once in a second
     233                        continue;
     234                $category = get_term( $cat_id, $taxonomy->name);
     235                ob_start();
     236                        wp_terms_checklist( 0, array('taxonomy'=>$taxonomy->name, 'descendants_and_self'=>$cat_id, 'selected_cats'=>$checked_categories, 'popular_cats'=>$popular_ids));
     237                $data = ob_get_contents();
     238                ob_end_clean();
     239                $x->add( array(
     240                        'what' =>       $taxonomy->name,
     241                        'id' => $cat_id,
     242                        'data' => $data,
     243                        'position' => -1
     244                ) );
     245        }
     246        if ( $parent ) { // Foncy - replace the parent and all its children
     247                $parent = get_term($parent, $taxonomy->name);
     248                ob_start();
     249                        global $post_ID;
     250                        wp_terms_checklist($post_ID, array('taxonomy' => $taxonomy->name));
     251                $data = ob_get_contents();
     252                ob_end_clean();
     253                $x->add( array(
     254                        'what' => $taxonomy->name,
     255                        'id' => $parent->term_id,
     256                        'old_id' => $parent->term_id,
     257                        'data' => $data,
     258                        'position' => -1
     259                ) );
     260
     261        }
     262        $x->send();
     263        die();
     264}
     265
    194266$id = isset($_POST['id'])? (int) $_POST['id'] : 0;
    195267switch ( $action = $_POST['action'] ) :
    196268case 'delete-comment' : // On success, die with time() instead of 1
     
    388460        _wp_ajax_delete_comment_response( $comment->comment_ID );
    389461        die( '0' );
    390462        break;
    391 case 'add-category' : // On the Fly
    392         check_ajax_referer( $action );
    393         if ( !current_user_can( 'manage_categories' ) )
    394                 die('-1');
    395         $names = explode(',', $_POST['newcat']);
    396         if ( 0 > $parent = (int) $_POST['newcat_parent'] )
    397                 $parent = 0;
    398         $post_category = isset($_POST['post_category'])? (array) $_POST['post_category'] : array();
    399         $checked_categories = array_map( 'absint', (array) $post_category );
    400         $popular_ids = isset( $_POST['popular_ids'] ) ?
    401                         array_map( 'absint', explode( ',', $_POST['popular_ids'] ) ) :
    402                         false;
    403 
    404         $x = new WP_Ajax_Response();
    405         foreach ( $names as $cat_name ) {
    406                 $cat_name = trim($cat_name);
    407                 $category_nicename = sanitize_title($cat_name);
    408                 if ( '' === $category_nicename )
    409                         continue;
    410                 $cat_id = wp_create_category( $cat_name, $parent );
    411                 $checked_categories[] = $cat_id;
    412                 if ( $parent ) // Do these all at once in a second
    413                         continue;
    414                 $category = get_category( $cat_id );
    415                 ob_start();
    416                         wp_category_checklist( 0, $cat_id, $checked_categories, $popular_ids );
    417                 $data = ob_get_contents();
    418                 ob_end_clean();
    419                 $x->add( array(
    420                         'what' => 'category',
    421                         'id' => $cat_id,
    422                         'data' => $data,
    423                         'position' => -1
    424                 ) );
    425         }
    426         if ( $parent ) { // Foncy - replace the parent and all its children
    427                 $parent = get_category( $parent );
    428                 ob_start();
    429                         dropdown_categories( 0, $parent );
    430                 $data = ob_get_contents();
    431                 ob_end_clean();
    432                 $x->add( array(
    433                         'what' => 'category',
    434                         'id' => $parent->term_id,
    435                         'old_id' => $parent->term_id,
    436                         'data' => $data,
    437                         'position' => -1
    438                 ) );
    439 
    440         }
    441         $x->send();
    442         break;
    443463case 'add-link-category' : // On the Fly
    444464        check_ajax_referer( $action );
    445465        if ( !current_user_can( 'manage_categories' ) )
  • wp-admin/css/colors-classic.dev.css

     
    104104}
    105105
    106106div.tabs-panel,
    107 ul#category-tabs li.tabs {
     107ul.category-tabs li.tabs {
    108108        border-color: #dfdfdf;
    109109}
    110110
    111 ul#category-tabs li.tabs {
     111ul.category-tabs li.tabs {
    112112        background-color: #f1f1f1;
    113113}
    114114
     
    381381        background:#faf9f7 !important;
    382382}
    383383
    384 #side-sortables #category-tabs .tabs a {
     384#side-sortables .category-tabs .tabs a {
    385385        color: #333;
    386386}
    387387
     
    14471447        background-color: #f5f5f5;
    14481448}
    14491449
    1450 #post-body ul#category-tabs li.tabs a {
     1450#post-body ul.category-tabs li.tabs a {
    14511451        color: #333;
    14521452}
    14531453
  • wp-admin/css/colors-fresh.dev.css

     
    104104}
    105105
    106106div.tabs-panel,
    107 ul#category-tabs li.tabs {
     107ul.category-tabs li.tabs {
    108108        border-color: #dfdfdf;
    109109}
    110110
    111 ul#category-tabs li.tabs {
     111ul.category-tabs li.tabs {
    112112        background-color: #f1f1f1;
    113113}
    114114
     
    377377        border-color: #dfdfdf;
    378378}
    379379
    380 #side-sortables #category-tabs .tabs a {
     380#side-sortables .category-tabs .tabs a {
    381381        color: #333;
    382382}
    383383
     
    14421442        background-color: #f5f5f5;
    14431443}
    14441444
    1445 #post-body ul#category-tabs li.tabs a {
     1445#post-body ul.category-tabs li.tabs a {
    14461446        color: #333;
    14471447}
    14481448
  • wp-admin/css/press-this.dev.css

     
    304304        display: none;
    305305}
    306306
    307 #category-adder {
     307.category-adder {
    308308        padding: 4px 0;
    309309}
    310310
    311 #category-adder h4 {
     311.category-adder h4 {
    312312        margin: 0 0 8px;
    313313}
    314314
     
    335335}
    336336
    337337#category-add input,
    338 #category-add-sumbit {
     338.category-add-sumbit {
    339339        width: auto;
    340340}
    341341
    342342/* Categories */
    343 #categorydiv ul,
     343.categorydiv ul,
    344344#linkcategorydiv ul {
    345345        list-style: none;
    346346        padding: 0;
    347347        margin: 0;
    348348}
    349349
    350 #categorydiv ul.categorychecklist ul {
     350.categorydiv ul.categorychecklist ul {
    351351        margin-left: 18px;
    352352}
    353353
    354 #categorydiv div.tabs-panel {
     354.categorydiv div.tabs-panel {
    355355        height: 140px;
    356356        overflow: auto;
    357357}
  • wp-admin/edit-form-advanced.php

     
    6565
    6666// all tag-style post taxonomies
    6767foreach ( get_object_taxonomies('post') as $tax_name ) {
     68        $taxonomy = get_taxonomy($tax_name);
     69        $label = isset($taxonomy->label) ? esc_attr($taxonomy->label) : $tax_name;
    6870        if ( !is_taxonomy_hierarchical($tax_name) ) {
    69                 $taxonomy = get_taxonomy($tax_name);
    70                 $label = isset($taxonomy->label) ? esc_attr($taxonomy->label) : $tax_name;
    71 
    7271                add_meta_box('tagsdiv-' . $tax_name, $label, 'post_tags_meta_box', 'post', 'side', 'core');
     72        }       else {
     73                add_meta_box($tax_name.'div', $label, 'post_categories_meta_box', 'post', 'side', 'core', array('taxonomy'=>$tax_name));
    7374        }
    7475}
    7576
    76 add_meta_box('categorydiv', __('Categories'), 'post_categories_meta_box', 'post', 'side', 'core');
    7777// add_meta_box('passworddiv', __('Privacy Options'), 'post_password_meta_box', 'post', 'side', 'core');
    7878add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', 'post', 'normal', 'core');
    7979add_meta_box('trackbacksdiv', __('Send Trackbacks'), 'post_trackback_meta_box', 'post', 'normal', 'core');
  • wp-admin/includes/meta-boxes.php

     
    258258 *
    259259 * @param object $post
    260260 */
    261 function post_categories_meta_box($post) {
    262 ?>
    263 <ul id="category-tabs">
    264         <li class="tabs"><a href="#categories-all" tabindex="3"><?php _e( 'All Categories' ); ?></a></li>
    265         <li class="hide-if-no-js"><a href="#categories-pop" tabindex="3"><?php _e( 'Most Used' ); ?></a></li>
    266 </ul>
     261function post_categories_meta_box($post, $box) {
     262        $defaults = array(
     263                'taxonomy' => 'category'
     264        );
     265        if(!isset($box['args']) || !is_array($args = $box['args']))
     266        {
     267                $args = array();
     268        }
     269        extract(array_merge($defaults, $args));
     270        ?>
     271        <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv">
     272                <ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs">
     273                        <li class="tabs"><a href="#<?php echo $taxonomy; ?>-all" tabindex="3"><?php _e( 'All Categories' ); ?></a></li>
     274                        <li class="hide-if-no-js"><a href="#<?php echo $taxonomy; ?>-pop" tabindex="3"><?php _e( 'Most Used' ); ?></a></li>
     275                </ul>
    267276
    268 <div id="categories-pop" class="tabs-panel" style="display: none;">
    269         <ul id="categorychecklist-pop" class="categorychecklist form-no-clear" >
    270 <?php $popular_ids = wp_popular_terms_checklist('category'); ?>
    271         </ul>
    272 </div>
     277                <div id="<?php echo $taxonomy; ?>-pop" class="tabs-panel" style="display: none;">
     278                        <ul id="<?php echo $taxonomy; ?>checklist-pop" class="categorychecklist form-no-clear" >
     279                                <?php $popular_ids = wp_popular_terms_checklist($taxonomy); ?>
     280                        </ul>
     281                </div>
    273282
    274 <div id="categories-all" class="tabs-panel">
    275         <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
    276 <?php wp_category_checklist($post->ID, false, false, $popular_ids) ?>
    277         </ul>
    278 </div>
     283                <div id="<?php echo $taxonomy; ?>-all" class="tabs-panel">
     284                        <ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy?> categorychecklist form-no-clear">
     285                                <?php wp_terms_checklist($post->ID, array('taxonomy'=>$taxonomy, 'popular_cats'=> $popular_ids)) ?>
     286                        </ul>
     287                </div>
    279288
    280 <?php if ( current_user_can('manage_categories') ) : ?>
    281 <div id="category-adder" class="wp-hidden-children">
    282         <h4><a id="category-add-toggle" href="#category-add" class="hide-if-no-js" tabindex="3"><?php _e( '+ Add New Category' ); ?></a></h4>
    283         <p id="category-add" class="wp-hidden-child">
    284         <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"/>
    285         <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'), 'tab_index' => 3 ) ); ?>
    286         <input type="button" id="category-add-sumbit" class="add:categorychecklist:category-add button" value="<?php esc_attr_e( 'Add' ); ?>" tabindex="3" />
    287 <?php   wp_nonce_field( 'add-category', '_ajax_nonce', false ); ?>
    288         <span id="category-ajax-response"></span></p>
    289 </div>
    290 <?php
    291 endif;
    292 
     289                <?php if ( current_user_can('manage_categories') ) : ?>
     290                        <div id="<?php echo $taxonomy; ?>-adder" class="wp-hidden-children">
     291                                <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>
     292                                <p id="<?php echo $taxonomy; ?>-add" class="category-add wp-hidden-child">
     293                                        <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"/>
     294                                        <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 ) ); ?>
     295                                        <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" />
     296                                        <?php   wp_nonce_field( 'add-'.$taxonomy, '_ajax_nonce', false ); ?>
     297                                        <span id="<?php echo $taxonomy; ?>-ajax-response"></span>
     298                                </p>
     299                        </div>
     300                <?php   endif; ?>
     301        </div>
     302        <?php
    293303}
    294304
    295305
  • wp-admin/includes/template.php

     
    467467
    468468        function start_el(&$output, $category, $depth, $args) {
    469469                extract($args);
     470                if(empty($taxonomy))
     471                        $taxonomy = 'category';
    470472
     473                if($taxonomy == 'category')
     474                        $name = 'post_category';
     475                else
     476                        $name = 'tax_input['.$taxonomy.']';
    471477                $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : '';
    472                 $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>';
     478                $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>';
    473479        }
    474480
    475481        function end_el(&$output, $category, $depth, $args) {
     
    488494 * @param unknown_type $popular_cats
    489495 */
    490496function wp_category_checklist( $post_id = 0, $descendants_and_self = 0, $selected_cats = false, $popular_cats = false, $walker = null ) {
     497        wp_terms_checklist($post_id,
     498                array(
     499                        'taxonomy' => 'category',
     500                        'descendants_and_self' => $descendants_and_self,
     501                        'selected_cats' => $selected_cats,
     502                        'popular_cats' => $popular_cats,
     503                        'walker' => $walker
     504                )
     505        );
     506}
     507
     508/**
     509 * Taxonomy independent version of wp_category_checklist
     510 *
     511 * @param int $post_id
     512 * @param array $args
     513 */
     514function wp_terms_checklist($post_id = 0, $args = array())
     515{
     516        $defaults = array(
     517                'descendants_and_self' => 0,
     518                'selected_cats' => false,
     519                'popular_cats' => false,
     520                'walker' => null,
     521                'taxonomy' => 'category'
     522        );
     523        extract(array_merge($defaults, $args));
     524
    491525        if ( empty($walker) || !is_a($walker, 'Walker') )
    492526                $walker = new Walker_Category_Checklist;
    493527
    494528        $descendants_and_self = (int) $descendants_and_self;
    495529
    496         $args = array();
     530        $args = array('taxonomy'=>$taxonomy);
    497531
    498532        if ( is_array( $selected_cats ) )
    499533                $args['selected_cats'] = $selected_cats;
    500534        elseif ( $post_id )
    501                 $args['selected_cats'] = wp_get_post_categories($post_id);
     535                $args['selected_cats'] =  wp_get_object_terms($post_id, $taxonomy, array_merge($args, array('fields' => 'ids')));
    502536        else
    503537                $args['selected_cats'] = array();
    504538
    505539        if ( is_array( $popular_cats ) )
    506540                $args['popular_cats'] = $popular_cats;
    507541        else
    508                 $args['popular_cats'] = get_terms( 'category', array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
    509 
     542                $args['popular_cats'] = get_terms( $taxonomy, array( 'fields' => 'ids', 'orderby' => 'count', 'order' => 'DESC', 'number' => 10, 'hierarchical' => false ) );
    510543        if ( $descendants_and_self ) {
    511                 $categories = get_categories( "child_of=$descendants_and_self&hierarchical=0&hide_empty=0" );
    512                 $self = get_category( $descendants_and_self );
     544                $categories = (array) get_terms($taxonomy, "child_of=$descendants_and_self&hierarchical=0&hide_empty=0" );
     545                $self = get_term( $descendants_and_self, $taxonomy );
    513546                array_unshift( $categories, $self );
    514547        } else {
    515                 $categories = get_categories('get=all');
     548                $categories = (array) get_terms($taxonomy, 'get=all');
    516549        }
    517 
    518550        // Post process $categories rather than adding an exclude to the get_terms() query to keep the query the same across all posts (for any query cache)
    519551        $checked_categories = array();
    520552        $keys = array_keys( $categories );
  • wp-admin/js/post.dev.js

     
    210210})(jQuery);
    211211
    212212jQuery(document).ready( function($) {
    213         var noSyncChecks = false, syncChecks, catAddAfter, stamp = $('#timestamp').html(), visibility = $('#post-visibility-display').html(), sticky = '';
     213        var stamp = $('#timestamp').html(), visibility = $('#post-visibility-display').html(), sticky = '';
    214214
    215215        // postboxes
    216216        postboxes.add_postbox_toggles('post');
     
    227227                $(this).suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+tax, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
    228228        });
    229229
    230         // category tabs
    231         $('#category-tabs a').click(function(){
    232                 var t = $(this).attr('href');
    233                 $(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
    234                 $('.tabs-panel').hide();
    235                 $(t).show();
    236                 if ( '#categories-all' == t )
    237                         deleteUserSetting('cats');
    238                 else
    239                         setUserSetting('cats','pop');
    240                 return false;
    241         });
    242         if ( getUserSetting('cats') )
    243                 $('#category-tabs a[href="#categories-pop"]').click();
     230        $('.categorydiv').each(function(){
     231                var this_id = $(this).attr('id'), noSyncChecks = false, syncChecks, catAddAfter, popularCats;
     232                var taxonomy = this_id.split('-').pop();
     233                var settingName = taxonomy+'_tab';
     234                if(taxonomy == 'category')
     235                        settingName = 'cats';
    244236
    245         // Ajax Cat
    246         $('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ) } );
    247         $('#category-add-sumbit').click(function(){$('#newcat').focus();});
     237                // category tabs
     238                $('#'+taxonomy+'-tabs a').click(function(){
     239                        var t = $(this).attr('href');
     240                        $(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
     241                        $('#taxonomy-'+taxonomy+' .tabs-panel').hide();
     242                        $(t).show();
     243                        if ( '#'+taxonomy+'-all' == t )
     244                                deleteUserSetting(settingName);
     245                        else
     246                                setUserSetting(settingName,'pop');
     247                        return false;
     248                });
     249                if ( getUserSetting(settingName) )
     250                        $('#'+this_id+' a[href="#'+taxonomy+'-pop"]').click();
    248251
    249         syncChecks = function() {
    250                 if ( noSyncChecks )
    251                         return;
    252                 noSyncChecks = true;
    253                 var th = jQuery(this), c = th.is(':checked'), id = th.val().toString();
    254                 $('#in-category-' + id + ', #in-popular-category-' + id).attr( 'checked', c );
    255                 noSyncChecks = false;
    256         };
     252                // Ajax Cat
     253                $('#new'+taxonomy).one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ) } );
     254                $('#'+taxonomy+'-add-submit').click(function(){$('#new'+taxonomy).focus();});
    257255
    258         popularCats = $('#categorychecklist-pop :checkbox').map( function() { return parseInt(jQuery(this).val(), 10); } ).get().join(',');
    259         catAddBefore = function( s ) {
    260                 if ( !$('#newcat').val() )
    261                         return false;
    262                 s.data += '&popular_ids=' + popularCats + '&' + jQuery( '#categorychecklist :checked' ).serialize();
    263                 return s;
    264         };
     256                syncChecks = function() {
     257                        if ( noSyncChecks )
     258                                return;
     259                        noSyncChecks = true;
     260                        var th = jQuery(this), c = th.is(':checked'), id = th.val().toString();
     261                        $('#in-'+taxonomy+'-' + id + ', #in-'+taxonomy+'-category-' + id).attr( 'checked', c );
     262                        noSyncChecks = false;
     263                };
    265264
    266         catAddAfter = function( r, s ) {
    267                 var newCatParent = jQuery('#newcat_parent'), newCatParentOption = newCatParent.find( 'option[value="-1"]' );
    268                 $(s.what + ' response_data', r).each( function() {
    269                         var t = $($(this).text());
    270                         t.find( 'label' ).each( function() {
    271                                 var th = $(this), val = th.find('input').val(), id = th.find('input')[0].id, name, o;
    272                                 $('#' + id).change( syncChecks ).change();
    273                                 if ( newCatParent.find( 'option[value="' + val + '"]' ).size() )
    274                                         return;
    275                                 name = $.trim( th.text() );
    276                                 o = $( '<option value="' +  parseInt( val, 10 ) + '"></option>' ).text( name );
    277                                 newCatParent.prepend( o );
     265                popularCats = $('#'+taxonomy+'checklist-pop :checkbox').map( function() { return parseInt(jQuery(this).val(), 10); } ).get().join(',');
     266                catAddBefore = function( s ) {
     267                        if ( !$('#new'+taxonomy).val() )
     268                                return false;
     269                        s.data += '&popular_ids=' + popularCats + '&' + jQuery( '#'+taxonomy+'checklist :checked' ).serialize();
     270                        return s;
     271                };
     272
     273                catAddAfter = function( r, s ) {
     274                        var newCatParent = jQuery('#new'+taxonomy+'_parent'), newCatParentOption = newCatParent.find( 'option[value="-1"]' );
     275                        $(s.what + ' response_data', r).each( function() {
     276                                var t = $($(this).text());
     277                                t.find( 'label' ).each( function() {
     278                                        var th = $(this), val = th.find('input').val(), id = th.find('input')[0].id, name, o;
     279                                        $('#' + id).change( syncChecks ).change();
     280                                        if ( newCatParent.find( 'option[value="' + val + '"]' ).size() )
     281                                                return;
     282                                        name = $.trim( th.text() );
     283                                        o = $( '<option value="' +  parseInt( val, 10 ) + '"></option>' ).text( name );
     284                                        newCatParent.prepend( o );
     285                                } );
     286                                newCatParentOption.attr( 'selected', 'selected' );
    278287                        } );
    279                         newCatParentOption.attr( 'selected', 'selected' );
     288                };
     289
     290                $('#'+taxonomy+'checklist').wpList( {
     291                        alt: '',
     292                        response: taxonomy+'-ajax-response',
     293                        addBefore: catAddBefore,
     294                        addAfter: catAddAfter
    280295                } );
    281         };
    282296
    283         $('#categorychecklist').wpList( {
    284                 alt: '',
    285                 response: 'category-ajax-response',
    286                 addBefore: catAddBefore,
    287                 addAfter: catAddAfter
    288         } );
     297                $('#'+taxonomy+'-add-toggle').click( function() {
     298                        $('#'+taxonomy+'-adder').toggleClass( 'wp-hidden-children' );
     299                        $('#'+taxonomy+'-tabs a[href="#'+taxonomy+'-all"]').click();
     300                        return false;
     301                } );
    289302
    290         $('#category-add-toggle').click( function() {
    291                 $('#category-adder').toggleClass( 'wp-hidden-children' );
    292                 $('#category-tabs a[href="#categories-all"]').click();
    293                 return false;
    294         } );
     303                $('#'+taxonomy+'checklist .popular-category :checkbox').change( syncChecks ).filter( ':checked' ).change(), sticky = '';
    295304
    296         $('.categorychecklist .popular-category :checkbox').change( syncChecks ).filter( ':checked' ).change(), sticky = '';
     305        });
    297306
    298307        function updateVisibility() {
    299308                if ( $('#post-visibility-select input:radio:checked').val() != 'public' ) {
  • wp-admin/rtl.dev.css

     
    298298        margin-left: 0;
    299299        margin-right: 120px;
    300300}
    301 #post-body ul#category-tabs li.tabs {
     301#post-body ul.category-tabs li.tabs {
    302302        -moz-border-radius: 0 3px 3px 0;
    303303        -webkit-border-top-left-radius: 0;
    304304        -webkit-border-top-right-radius: 3px;
     
    309309        border-bottom-left-radius: 0;
    310310        border-bottom-right-radius: 3px;
    311311}
    312 #post-body ul#category-tabs {
     312#post-body ul.category-tabs {
    313313        float: right;
    314314        text-align: left;
    315315        margin: 0 0 0 -120px;
     
    320320}
    321321/* 1800 - 2000
    322322=================================== */
    323 #side-sortables #category-tabs li {
     323#side-sortables .category-tabs li {
    324324        padding-right: 0;
    325325        padding-left: 8px;
    326326}
  • wp-admin/wp-admin.dev.css

     
    19381938
    19391939/* Categories */
    19401940
    1941 #category-adder {
     1941.category-adder {
    19421942        margin-left: 120px;
    19431943        padding: 4px 0;
    19441944}
    19451945
    1946 #category-adder h4 {
     1946.category-adder h4 {
    19471947        margin: 0 0 8px;
    19481948}
    19491949
    1950 #side-sortables #category-adder {
     1950#side-sortables .category-adder {
    19511951        margin: 0;
    19521952}
    19531953
    1954 #post-body #category-add input, #category-add select {
     1954#post-body .category-add input, .category-add select {
    19551955        width: 30%;
    19561956}
    19571957
    1958 #side-sortables #category-add input {
     1958#side-sortables .category-add input {
    19591959        width: 94%;
    19601960}
    19611961
    1962 #side-sortables #category-add select {
     1962#side-sortables .category-add select {
    19631963        width: 100%;
    19641964}
    19651965
    1966 #category-add input#category-add-sumbit {
     1966#side-sortables .category-add input.category-add-sumbit, #post-body .category-add input.category-add-sumbit {
    19671967        width: auto;
    19681968}
    19691969
    1970 #post-body ul#category-tabs {
     1970#post-body ul.category-tabs {
    19711971        float: left;
    19721972        width: 120px;
    19731973        text-align: right;
     
    19761976        padding: 0;
    19771977}
    19781978
    1979 #post-body ul#category-tabs li {
     1979#post-body ul.category-tabs li {
    19801980        padding: 8px;
    19811981}
    19821982
    1983 #post-body ul#category-tabs li.tabs {
     1983#post-body ul.category-tabs li.tabs {
    19841984        -moz-border-radius: 3px 0 0 3px;
    19851985        -webkit-border-top-left-radius: 3px;
    19861986        -webkit-border-bottom-left-radius: 3px;
     
    19901990        border-bottom-left-radius: 3px;
    19911991}
    19921992
    1993 #post-body ul#category-tabs li.tabs a {
     1993#post-body ul.category-tabs li.tabs a {
    19941994        font-weight: bold;
    19951995        text-decoration: none;
    19961996}
    19971997
    1998 #categorydiv div.tabs-panel,
     1998.categorydiv div.tabs-panel,
    19991999#linkcategorydiv div.tabs-panel {
    20002000        height: 150px;
    20012001        overflow: auto;
     
    20042004        border-width: 1px;
    20052005}
    20062006
    2007 #post-body #categorydiv div.tabs-panel,
     2007#post-body .categorydiv div.tabs-panel,
    20082008#post-body #linkcategorydiv div.tabs-panel {
    20092009        margin: 0 5px 0 125px;
    20102010}
    20112011
    2012 #side-sortables #category-tabs li {
     2012#side-sortables .category-tabs li {
    20132013        display: inline;
    20142014        padding-right: 8px;
    20152015}
    20162016
    2017 #side-sortables #category-tabs a {
     2017#side-sortables .category-tabs a {
    20182018        text-decoration: none;
    20192019}
    20202020
    2021 #side-sortables #category-tabs {
     2021#side-sortables .category-tabs {
    20222022        margin-bottom: 3px;
    20232023}
    20242024
    2025 #categorydiv ul,
     2025.categorydiv ul,
    20262026#linkcategorydiv ul {
    20272027        list-style: none;
    20282028        padding: 0;
    20292029        margin: 0;
    20302030}
    20312031
    2032 #categorydiv ul.categorychecklist ul,
     2032.categorydiv ul.categorychecklist ul,
    20332033#linkcategorydiv ul.categorychecklist ul {
    20342034        margin-left: 18px;
    20352035}
     
    20402040        line-height: 19px;
    20412041}
    20422042
    2043 #category-adder h4 {
     2043.category-adder h4 {
    20442044        margin-top: 4px;
    20452045        margin-bottom: 0px;
    20462046}
    20472047
    2048 #categorydiv .tabs-panel {
     2048.categorydiv .tabs-panel {
    20492049        border-width: 3px;
    20502050        border-style: solid;
    20512051}
    20522052
    2053 ul#category-tabs {
     2053ul.category-tabs {
    20542054        margin-top: 12px;
    20552055}
    20562056
    2057 ul#category-tabs li.tabs {
     2057ul.category-tabs li.tabs {
    20582058        border-style: solid solid none;
    20592059        border-width: 1px 1px 0;
    20602060}
    20612061
    2062 #post-body #category-tabs li.tabs {
     2062#post-body .category-tabs li.tabs {
    20632063        border-style: solid none solid solid;
    20642064        border-width: 1px 0 1px 1px;
    20652065        margin-right: -1px;
    20662066}
    20672067
    2068 ul#category-tabs li {
     2068ul.category-tabs li {
    20692069        padding: 5px 8px;
    20702070        -moz-border-radius: 3px 3px 0 0;
    20712071        -webkit-border-top-left-radius: 3px;
  • wp-includes/category-template.php

     
    331331 */
    332332function wp_dropdown_categories( $args = '' ) {
    333333        $defaults = array(
     334                'taxonomy' => 'category',
    334335                'show_option_all' => '', 'show_option_none' => '',
    335336                'orderby' => 'id', 'order' => 'ASC',
    336337                'show_last_update' => 0, 'show_count' => 0,
     
    351352        if ( (int) $tab_index > 0 )
    352353                $tab_index_attribute = " tabindex=\"$tab_index\"";
    353354
    354         $categories = get_categories( $r );
     355        $categories = get_terms( $taxonomy, $r );
    355356        $name = esc_attr($name);
    356357        $class = esc_attr($class);
    357358
  • wp-includes/post.php

     
    19241924                $tags = array();
    19251925
    19261926        $tags = is_array($tags) ? $tags : explode( ',', trim($tags, " \n\t\r\0\x0B,") );
     1927
     1928        $taxonomy_obj = get_taxonomy($taxonomy);
     1929        if($taxonomy_obj->hierarchical)
     1930        {
     1931                $tags = array_map('intval', $tags);
     1932                $tags = array_unique($tags);
     1933        }
     1934
    19271935        wp_set_object_terms($post_id, $tags, $taxonomy, $append);
    19281936}
    19291937
  • wp-includes/taxonomy.php

     
    192192        $args['name'] = $taxonomy;
    193193        $args['object_type'] = $object_type;
    194194        $wp_taxonomies[$taxonomy] = (object) $args;
     195
     196        //register meta_box
     197        add_filter('wp_ajax_add-'.$taxonomy, '_wp_ajax_add_heirarichal_term');
    195198}
    196199
    197200//