Make WordPress Core


Ignore:
Timestamp:
03/01/2010 03:48:01 PM (15 years ago)
Author:
ryan
Message:

Custom taxonomy support for inline edit. Props prettyboymp. see #9674

File:
1 edited

Legend:

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

    r13489 r13535  
    255255    $post_IDs = array_map( 'intval', (array) $post_data['post'] );
    256256
    257     $reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tags_input', 'post_category', 'sticky' );
     257    $reset = array( 'post_author', 'post_status', 'post_password', 'post_parent', 'page_template', 'comment_status', 'ping_status', 'keep_private', 'tax_input', 'post_category', 'sticky' );
    258258    foreach ( $reset as $field ) {
    259259        if ( isset($post_data[$field]) && ( '' == $post_data[$field] || -1 == $post_data[$field] ) )
     
    267267            unset($post_data['post_category']);
    268268    }
    269 
    270     if ( isset($post_data['tags_input']) ) {
    271         $new_tags = preg_replace( '/\s*,\s*/', ',', rtrim( trim($post_data['tags_input']), ' ,' ) );
    272         $new_tags = explode(',', $new_tags);
     269   
     270    $tax_input = array();
     271    if ( isset($post_data['tax_input'])) {
     272        foreach ( $post_data['tax_input'] as $tax_name => $terms ) {
     273            if ( empty($terms) )
     274                continue;
     275            $taxonomy = get_taxonomy( $tax_name );
     276            if ( $taxonomy->hierarchical )
     277                $tax_input[$tax_name] = array_map( 'absint', $terms );         
     278            else {
     279                $tax_input[$tax_name] = preg_replace( '/\s*,\s*/', ',', rtrim( trim($terms), ' ,' ) );
     280                $tax_input[$tax_name] = explode(',', $tax_input[$tax_name]);
     281            }
     282        }
    273283    }
    274284
     
    301311            continue;
    302312        }
    303 
    304         if ( isset($new_cats) ) {
     313       
     314        $tax_names = get_object_taxonomies( get_post($post_ID) );
     315       
     316        if ( isset($new_cats) && in_array( 'category', $tax_names ) ) {
    305317            $cats = (array) wp_get_post_categories($post_ID);
    306318            $post_data['post_category'] = array_unique( array_merge($cats, $new_cats) );
    307319        }
    308 
    309         if ( isset($new_tags) ) {
    310             $tags = wp_get_post_tags($post_ID, array('fields' => 'names'));
    311             $post_data['tags_input'] = array_unique( array_merge($tags, $new_tags) );
     320       
     321        foreach ( $tax_names as $tax_name ) {
     322            if( isset( $tax_input[$tax_name])  ) {
     323                $taxonomy = get_taxonomy( $tax_name );
     324                if( $taxonomy->hierarchical )
     325                    $terms = (array) wp_get_object_terms( $post_ID, $tax_name, array('fields' => 'ids') );
     326                else
     327                    $terms = (array) wp_get_object_terms( $post_ID, $tax_name, array('fields' => 'names') );
     328                $post_data['tax_input'][$tax_name] = array_merge( $terms, $tax_input[$tax_name] );
     329            }
    312330        }
    313331
Note: See TracChangeset for help on using the changeset viewer.