Make WordPress Core


Ignore:
Timestamp:
01/10/2008 09:39:35 AM (17 years ago)
Author:
matt
Message:

New experimental category interface, fixes #5618. Hat tip: mdawaffe.

File:
1 edited

Legend:

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

    r6584 r6588  
    158158        die('-1');
    159159    $names = explode(',', $_POST['newcat']);
     160    if ( 0 > $parent = (int) $_POST['newcat_parent'] )
     161        $parent = 0;
     162
     163    $checked_categories = array_map( 'absint', (array) $_POST['post_category'] );
     164
    160165    $x = new WP_Ajax_Response();
    161166    foreach ( $names as $cat_name ) {
     
    164169        if ( '' === $category_nicename )
    165170            continue;
    166         $cat_id = wp_create_category( $cat_name );
    167         $cat_name = wp_specialchars(stripslashes($cat_name));
     171        $cat_id = wp_create_category( $cat_name, $parent );
     172        $checked_categories[] = $cat_id;
     173        if ( $parent ) // Do these all at once in a second
     174            continue;
     175        $category = get_category( $cat_id );
     176        $category->_is_checked = true;
     177        ob_start();
     178            dropdown_categories( 0, $category );
     179        $data = ob_get_contents();
     180        ob_end_clean();
    168181        $x->add( array(
    169182            'what' => 'category',
    170183            'id' => $cat_id,
    171             'data' => "<li id='category-$cat_id'><label for='in-category-$cat_id' class='selectit'><input value='$cat_id' type='checkbox' checked='checked' name='post_category[]' id='in-category-$cat_id'/> $cat_name</label></li>",
     184            'data' => $data,
    172185            'position' => -1
    173186        ) );
     187    }
     188    if ( $parent ) { // Foncy - replace the parent and all its children
     189        $parent = get_category( $parent );
     190        ob_start();
     191            dropdown_categories( 0, $parent );
     192        $data = ob_get_contents();
     193        ob_end_clean();
     194        $x->add( array(
     195            'what' => 'category',
     196            'id' => $parent->term_id,
     197            'old_id' => $parent->term_id,
     198            'data' => $data,
     199            'position' => -1
     200        ) );
     201
    174202    }
    175203    $x->send();
Note: See TracChangeset for help on using the changeset viewer.