WordPress.org

Plugin Directory

Changeset 324376 for wpcat2tag-importer


Ignore:
Timestamp:
12/19/10 22:15:42 (3 years ago)
Author:
duck_
Message:

leave default category in place

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wpcat2tag-importer/trunk/wpcat2tag-importer.php

    r324364 r324376  
    66Author: wordpressdotorg 
    77Author URI: http://wordpress.org/ 
    8 Version: 0.5.1 
     8Version: 0.5.2 
    99License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
    1010*/ 
     
    1212/* == Todo == 
    1313 * - ensure following expected behaviour in all cases... what is expected behaviour? remove+delete the old cat/tag/format? 
    14  *          ^^^ what to do on default category? (should probably leave it in place) 
    1514 * - cache cleaning (think wp_delete_term does most, if not all) 
    1615 * - more UI cleanup (indent for child cats, what should convert to selectors look like?, ...) 
     
    250249        if ( ! $term_info = term_exists( $_POST['convert_to_slug'], $convert_to ) ) 
    251250            $term_info = wp_insert_term( $_POST['convert_to_slug'], $convert_to ); 
     251             
     252        if ( is_wp_error($term_info) ) { 
     253            echo '<p>' . $term_info->get_error_message() . ' '; 
     254            printf( __( 'Please <a href="%s">try again</a>.', 'wpcat2tag-importer' ), 'admin.php?import=wpcat2tag&amp;tab=cats' ) . "</p>\n"; 
     255            return; 
     256        } 
    252257 
    253258        echo '<ul>'; 
     
    303308            return; 
    304309        } 
     310         
     311        $default = get_option( 'default_category' ); 
    305312 
    306313        if ( ! isset($_POST['convert_to']) || 'format' != $_POST['convert_to'] ) { 
     
    331338                    if ( ! $term_info = term_exists( $category->slug, 'post_tag' ) ) 
    332339                        $term_info = wp_insert_term( $category->name, 'post_tag', array( 'description' => $category->description ) ); 
     340                         
     341                    if ( is_wp_error($term_info) ) { 
     342                        echo $term_info->get_error_message() . "</li>\n"; 
     343                        continue; 
     344                    } 
    333345                } 
    334346 
    335                 $this->_convert_term( array( 'term_id' => $category->term_id, 'taxonomy' => 'category', 'term_taxonomy_id' => $category->term_taxonomy_id ), $term_info['term_taxonomy_id'] ); 
     347                // if this is the default category then leave it in place and just add the new tag/format 
     348                if ( $default == $category->term_id ) { 
     349                    $posts = get_objects_in_term( $category->term_id, 'category' ); 
     350                    foreach ( $posts as $post ) { 
     351                        $values[] = $wpdb->prepare( "(%d, %d, 0)", $post, $term_info['term_taxonomy_id'] ); 
     352                        clean_post_cache( $post ); 
     353                    } 
     354                     
     355                    $wpdb->query( "INSERT INTO {$wpdb->term_relationships} (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) ); 
     356                    $wpdb->update( $wpdb->term_taxonomy, array( 'count' => $category->count ), array( 'term_id' => $term_info['term_id'], 'taxonomy' => $convert_to ) ); 
     357                // otherwise just convert it 
     358                } else { 
     359                    $this->_convert_term( array( 'term_id' => $category->term_id, 'taxonomy' => 'category', 'term_taxonomy_id' => $category->term_taxonomy_id ), $term_info['term_taxonomy_id'] ); 
     360                } 
    336361 
    337362                echo __( 'Converted successfully.', 'wpcat2tag-importer' ) . "</li>\n"; 
     
    380405                    if ( ! $term_info = term_exists( $tag->slug, 'category' ) ) 
    381406                        $term_info = wp_insert_term( $tag->name, 'category', array( 'description' => $tag->description ) ); 
     407                         
     408                    if ( is_wp_error($term_info) ) { 
     409                        echo $term_info->get_error_message() . "</li>\n"; 
     410                        continue; 
     411                    } 
    382412                } 
    383413 
Note: See TracChangeset for help on using the changeset viewer.