Ticket #6909: tag-to-cat2.patch

File tag-to-cat2.patch, 20.2 kB (added by azaozz, 5 months ago)
  • wp-admin/import/wp-cat2tag.php

    old new  
    2424        } 
    2525 
    2626        function populate_cats() { 
    27                 global $wpdb; 
    2827 
    2928                $categories = get_categories('get=all'); 
    3029                foreach ( $categories as $category ) { 
    3130                        $this->all_categories[] = $category; 
    32                         if ( tag_exists( $wpdb->escape($category->name) ) ) 
     31                        if ( is_term( $category->slug, 'post_tag' ) ) 
    3332                                $this->hybrids_ids[] = $category->term_id; 
    3433                } 
    3534        } 
    3635 
    3736        function populate_tags() { 
    38                 global $wpdb; 
    3937 
    4038                $tags = get_terms( array('post_tag'), 'get=all' ); 
    4139                foreach ( $tags as $tag ) { 
    4240                        $this->all_tags[] = $tag; 
    43                         if ( $this->_category_exists($tag->term_id) ) 
     41                        if ( is_term( $tag->slug, 'category' ) ) 
    4442                                $this->hybrids_ids[] = $tag->term_id; 
    4543                } 
    4644        } 
     
    5856                        echo '<p>' . __('Keep in mind that if you convert a category with child categories, the children become top-level orphans.') . '</p></div>'; 
    5957 
    6058                        $this->categories_form(); 
    61                 } elseif ( $hyb_num > 0 ) { 
    62                          echo '<p>' . __('You have no categories that can be converted. However some of your categories are both a tag and a category.') . '</p>'; 
    6359                } else { 
    6460                        echo '<p>'.__('You have no categories to convert!').'</p>'; 
    6561                } 
     
    9288</script> 
    9389 
    9490<form name="catlist" id="catlist" action="admin.php?import=wp-cat2tag&amp;step=2" method="post"> 
    95 <p><input type="button" class="button-secondary" value="<?php _e('Check All'); ?>" onclick="this.value=check_all_rows()"
     91<p><input type="button" class="button-secondary" value="<?php _e('Check All'); ?>" onclick="this.value=check_all_rows()" /
    9692<?php wp_nonce_field('import-cat2tag'); ?></p> 
    9793<ul style="list-style:none"> 
    98 <?php 
    99                 $hier = _get_term_hierarchy('category'); 
    10094 
     95<?php   $hier = _get_term_hierarchy('category'); 
     96 
    10197                foreach ($this->all_categories as $category) { 
    10298                        $category = sanitize_term( $category, 'category', 'display' ); 
    10399 
    104                         if ( (int) $category->parent == 0 ) { 
    105                                 if ( in_array( intval($category->term_id),  $this->hybrids_ids ) ) { 
    106 ?> 
    107         <li style="color:#777;padding-left:1.3em;"><?php echo $category->name . ' (' . $category->count . ') *'; ?></li> 
    108 <?php 
    109                                 } else { 
    110 ?> 
     100                        if ( (int) $category->parent == 0 ) { ?> 
     101 
    111102        <li><label><input type="checkbox" name="cats_to_convert[]" value="<?php echo intval($category->term_id); ?>" /> <?php echo $category->name . ' (' . $category->count . ')'; ?></label><?php 
    112103 
    113                                         if ( isset($hier[$category->term_id]) ) 
    114                                                 $this->_category_children($category, $hier); 
    115 ?></li> 
    116 <?php 
    117                                 } 
    118                         } 
    119                 } 
    120 ?> 
     104                                 if ( in_array( intval($category->term_id),  $this->hybrids_ids ) ) 
     105                                        echo ' <a href="#note"> * </a>'; 
     106                                 
     107                                if ( isset($hier[$category->term_id]) ) 
     108                                        $this->_category_children($category, $hier); ?></li> 
     109<?php           } 
     110                } ?> 
    121111</ul> 
    122112 
    123 <?php 
    124                 if ( ! empty($this->hybrids_ids) ) { 
    125                         echo '<p>' . __('* This category is also a tag. It cannot be convert again.') . '</p>'; 
    126                 } 
    127 ?> 
     113<?php   if ( ! empty($this->hybrids_ids) ) 
     114                        echo '<p><a name="note"></a>' . __('* This category is also a tag. Converting it will add that tag to all posts that are currently in the category.') . '</p>'; ?> 
     115 
    128116<p class="submit"><input type="submit" name="submit" class="button" value="<?php _e('Convert Categories to Tags'); ?>" /></p> 
    129117</form> 
    130118 
    131 <?php 
    132         } 
     119<?php } 
    133120 
    134121        function tags_tab() { 
    135122                $this->populate_tags(); 
     
    142129                        echo '<div class="narrow">'; 
    143130                        echo '<p>' . __('Here you can selectively converts existing tags to categories. To get started, check the tags you wish to be converted, then click the Convert button.') . '</p>'; 
    144131                        echo '<p>' . __('The newly created categories will still be associated with the same posts.') . '</p></div>'; 
    145                          
    146                          
     132 
    147133                        $this->tags_form(); 
    148                 } elseif ( $hyb_num > 0 ) { 
    149                          echo '<p>' . __('You have no tags that can be converted. However some of your tags are both a tag and a category.') . '</p>'; 
    150134                } else { 
    151135                        echo '<p>'.__('You have no tags to convert!').'</p>'; 
    152136                } 
     
    179163</script> 
    180164 
    181165<form name="taglist" id="taglist" action="admin.php?import=wp-cat2tag&amp;step=4" method="post"> 
    182 <p><input type="button" class="button-secondary" value="<?php _e('Check All'); ?>" onclick="this.value=check_all_tagrows()"
     166<p><input type="button" class="button-secondary" value="<?php _e('Check All'); ?>" onclick="this.value=check_all_tagrows()" /
    183167<?php wp_nonce_field('import-cat2tag'); ?></p> 
    184168<ul style="list-style:none"> 
    185 <?php 
    186                 foreach ( $this->all_tags as $tag ) { 
    187                         if ( in_array( intval($tag->term_id),  $this->hybrids_ids ) ) { 
    188 ?> 
    189         <li style="color:#777;padding-left:1.3em;"><?php echo attribute_escape($tag->name) . ' (' . $tag->count . ') *'; ?></li> 
    190 <?php 
    191                         } else { 
    192 ?> 
    193         <li><label><input type="checkbox" name="tags_to_convert[]" value="<?php echo intval($tag->term_id); ?>" /> <?php echo attribute_escape($tag->name) . ' (' . $tag->count . ')'; ?></label></li> 
    194169 
    195 <?php 
    196                        } 
    197                 } 
    198 ?> 
     170<?php  foreach ( $this->all_tags as $tag ) { ?> 
     171        <li><label><input type="checkbox" name="tags_to_convert[]" value="<?php echo intval($tag->term_id); ?>" /> <?php echo attribute_escape($tag->name) . ' (' . $tag->count . ')'; ?></label><?php if ( in_array( intval($tag->term_id),  $this->hybrids_ids ) ) echo ' <a href="#note"> * </a>'; ?></li> 
     172 
     173<?php  } ?> 
    199174</ul> 
    200175 
    201 <?php    
    202                 if ( ! empty($this->hybrids_ids) ) 
    203                         echo '<p>' . __('* This tag is also a category. It cannot be converted again.') . '</p>'; 
    204 ?> 
     176<?php   if ( ! empty($this->hybrids_ids) ) 
     177                        echo '<p><a name="note"></a>' . __('* This tag is also a category. When converted, all posts associated with the tag will also be in the category.') . '</p>'; ?> 
    205178 
    206179<p class="submit"><input type="submit" name="submit_tags" class="button" value="<?php _e('Convert Tags to Categories'); ?>" /></p> 
    207180</form> 
    208181 
    209 <?php 
    210         } 
     182<?php } 
    211183 
    212         function _category_children($parent, $hier) { 
    213 ?> 
     184        function _category_children($parent, $hier) { ?> 
    214185 
    215186                <ul style="list-style:none"> 
    216 <?php 
    217                 foreach ($hier[$parent->term_id] as $child_id) { 
    218                         $child =& get_category($child_id); 
    219                          
    220                         if ( in_array( intval($child->term_id), $this->hybrids_ids ) ) { 
    221 ?> 
    222                 <li style="color:#777;padding-left:1.3em;"><?php echo $child->name . ' (' . $child->count . ') *'; ?></li> 
    223 <?php 
    224                         } else { 
    225 ?> 
    226                 <li><label><input type="checkbox" name="cats_to_convert[]" value="<?php echo intval($child->term_id); ?>" /> <?php echo $child->name . ' (' . $child->count . ')'; ?></label> 
    227 <?php 
     187<?php   foreach ($hier[$parent->term_id] as $child_id) { 
     188                        $child =& get_category($child_id); ?> 
     189                <li><label><input type="checkbox" name="cats_to_convert[]" value="<?php echo intval($child->term_id); ?>" /> <?php echo $child->name . ' (' . $child->count . ')'; ?></label><?php 
    228190 
     191                        if ( in_array( intval($child->term_id), $this->hybrids_ids ) ) 
     192                                echo ' <a href="#note"> * </a>'; 
     193 
    229194                        if ( isset($hier[$child->term_id]) ) 
    230                                 $this->_category_children($child, $hier); 
    231 ?>              </li> 
    232 <?php 
    233                         } 
    234                 } 
    235 ?> 
    236                 </ul> 
    237 <?php 
     195                                $this->_category_children($child, $hier); ?></li> 
     196<?php   } ?> 
     197                </ul><?php 
    238198        } 
    239199 
    240200        function _category_exists($cat_id) { 
     
    252212        function convert_categories() { 
    253213                global $wpdb; 
    254214 
    255                 if ( (!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_to_convert'])) && empty($this->categories_to_convert)) { 
    256                         echo '<div class="narrow">'; 
    257                         echo '<p>' . sprintf(__('Uh, oh. Something didn&#8217;t work. Please <a href="%s">try again</a>.'), 'admin.php?import=wp-cat2tag') . '</p>'; 
    258                         echo '</div>'; 
    259                       return; 
     215                if ( (!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_to_convert'])) && empty($this->categories_to_convert)) { ?> 
     216                        <div class="narrow"> 
     217                        <p><?php printf(__('Uh, oh. Something didn&#8217;t work. Please <a href="%s">try again</a>.'), 'admin.php?import=wp-cat2tag'); ?></p> 
     218                        </div> 
     219<?php         return; 
    260220                } 
    261221 
    262222                if ( empty($this->categories_to_convert) ) 
    263223                        $this->categories_to_convert = $_POST['cats_to_convert']; 
     224 
    264225                $hier = _get_term_hierarchy('category'); 
     226                $hybrid_cats = $clear_parents = $parents = false; 
     227                $clean_term_cache = $clean_cat_cache = array(); 
     228                $default_cat = get_option('default_category'); 
    265229 
    266230                echo '<ul>'; 
    267231 
    268232                foreach ( (array) $this->categories_to_convert as $cat_id) { 
    269233                        $cat_id = (int) $cat_id; 
    270234 
    271                         echo '<li>' . sprintf(__('Converting category #%s ... '),  $cat_id); 
    272  
    273                         if (!$this->_category_exists($cat_id)) { 
    274                                 _e('Category doesn\'t exist!'); 
     235                        if ( ! $this->_category_exists($cat_id) ) { 
     236                                echo '<li>' . sprintf( __('Category %s doesn\'t exist!'),  $cat_id ) . "</li>\n"; 
    275237                        } else { 
    276238                                $category =& get_category($cat_id); 
     239                                echo '<li>' . sprintf(__('Converting category <strong>%s</strong> ... '),  $category->name); 
    277240 
    278                                 if ( tag_exists($wpdb->escape($category->name)) ) { 
    279                                         _e('Category is already a tag.'); 
    280                                         echo '</li>'; 
    281                                         continue; 
    282                                 } 
     241                                // If the category is the default, leave category in place and create tag. 
     242                                if ( $default_cat == $category->term_id ) { 
    283243 
    284                                 // If the category is the default, leave category in place and create tag. 
    285                                 if ( get_option('default_category') == $category->term_id ) { 
    286                                         $id = wp_insert_term($category->name, 'post_tag', array('slug' => $category->slug)); 
     244                                       if ( ! ($id = is_term( $category->slug, 'post_tag' ) ) ) 
     245                                               $id = wp_insert_term($category->name, 'post_tag', array('slug' => $category->slug)); 
     246                                         
    287247                                        $id = $id['term_taxonomy_id']; 
    288248                                        $posts = get_objects_in_term($category->term_id, 'category'); 
     249                                        $term_order = 0; 
     250 
    289251                                        foreach ( $posts as $post ) { 
    290                                                 if ( !$wpdb->get_var( $wpdb->prepare("SELECT object_id FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $post, $id) ) ) 
    291                                                         $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES (%d, %d)", $post, $id) ); 
     252                                                $values[] = $wpdb->prepare( "(%d, %d, %d)", $post, $id, $term_order); 
    292253                                                clean_post_cache($post); 
    293254                                        } 
    294                                 } else { 
    295                                         $tt_ids = $wpdb->get_col( $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'category'", $category->term_id) ); 
    296                                         if ( $tt_ids ) { 
    297                                                 $posts = $wpdb->get_col("SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . join(',', $tt_ids) . ") GROUP BY object_id"); 
    298                                                 foreach ( (array) $posts as $post ) 
    299                                                         clean_post_cache($post); 
     255                                         
     256                                        if ( $values ) { 
     257                                                $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)"); 
     258 
     259                                                $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_id = %d AND taxonomy = 'post_tag'", $category->count, $category->term_id) ); 
    300260                                        } 
    301261 
    302                                         // Change the category to a tag. 
    303                                         $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = %d AND taxonomy = 'category'", $category->term_id) ); 
     262                                        echo __('Converted successfully.') . "</li>\n"; 
     263                                        continue; 
     264                                } 
     265                                 
     266                                // if tag already exists, add it to all posts in the category 
     267                                if ( $tag_ttid = $wpdb->get_var( $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'post_tag'", $category->term_id) ) ) { 
     268                                        $objects_ids = get_objects_in_term($category->term_id, 'category'); 
     269                                        $tag_ttid = (int) $tag_ttid; 
     270                                        $term_order = 0; 
    304271 
    305                                         $terms = $wpdb->get_col( $wpdb->prepare("SELECT term_id FROM $wpdb->term_taxonomy WHERE parent = %d AND taxonomy = 'category'", $category->term_id) ); 
    306                                         foreach ( (array) $terms as $term ) 
    307                                                 clean_category_cache($term); 
     272                                        foreach ( $objects_ids as $object_id ) 
     273                                                $values[] = $wpdb->prepare( "(%d, %d, %d)", $object_id, $tag_ttid, $term_order); 
    308274 
    309                                         // Set all parents to 0 (root-level) if their parent was the converted tag 
    310                                         $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = %d AND taxonomy = 'category'", $category->term_id) ); 
     275                                        if ( $values ) { 
     276                                                $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)"); 
     277 
     278                                                $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tag_ttid) ); 
     279                                                $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_id = %d AND taxonomy = 'post_tag'", $count, $category->term_id) ); 
     280                                        } 
     281                                        echo __('Tag added to all posts in this category.') . " *</li>\n"; 
     282 
     283                                        $hybrid_cats = true; 
     284                                        $clean_term_cache[] = $category->term_id; 
     285                                        $clean_cat_cache[] = $category->term_id; 
     286 
     287                                        continue; 
    311288                                } 
    312                                 // Clean the cache 
    313                                 clean_category_cache($category->term_id); 
    314289 
    315                                 _e('Converted successfully.'); 
     290                                $tt_ids = $wpdb->get_col( $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'category'", $category->term_id) ); 
     291                                if ( $tt_ids ) { 
     292                                        $posts = $wpdb->get_col("SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . join(',', $tt_ids) . ") GROUP BY object_id"); 
     293                                        foreach ( (array) $posts as $post ) 
     294                                                clean_post_cache($post); 
     295                                } 
     296 
     297                                // Change the category to a tag. 
     298                                $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = %d AND taxonomy = 'category'", $category->term_id) ); 
     299 
     300                                // Set all parents to 0 (root-level) if their parent was the converted tag 
     301                                $parents = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET parent = 0 WHERE parent = %d AND taxonomy = 'category'", $category->term_id) ); 
     302 
     303                                if ( $parents ) $clear_parents = true; 
     304                                $clean_cat_cache[] = $category->term_id; 
     305                                echo __('Converted successfully.') . "</li>\n"; 
    316306                        } 
     307                } 
     308                echo '</ul>'; 
    317309 
    318                         echo '</li>'; 
     310                if ( ! empty($clean_term_cache) ) { 
     311                        $clean_term_cache = array_unique(array_values($clean_term_cache)); 
     312                        foreach ( $clean_term_cache as $id ) 
     313                                wp_cache_delete($id, 'post_tag'); 
    319314                } 
    320315 
    321                 echo '</ul>'; 
     316                if ( ! empty($clean_cat_cache) ) { 
     317                        $clean_cat_cache = array_unique(array_values($clean_cat_cache)); 
     318                        foreach ( $clean_cat_cache as $id ) 
     319                                wp_cache_delete($id, 'category'); 
     320                } 
     321 
     322                if ( $clear_parents ) delete_option('category_children'); 
     323 
     324                if ( $hybrid_cats ) 
     325                        echo '<p>' . sprintf( __('* This category is also a tag. The converter has added that tag to all posts currently in the category. If you want to remove it, please confirm that all tags were added successfully, then delete it from the <a href="%s">Manage Categories</a> page.'), 'categories.php') . '</p>'; 
    322326                echo '<p>' . sprintf( __('We&#8217;re all done here, but you can always <a href="%s">convert more</a>.'), 'admin.php?import=wp-cat2tag' ) . '</p>'; 
    323327        } 
    324328 
     
    332336                        return; 
    333337                } 
    334338 
    335                 if ( empty($this->categories_to_convert) ) 
     339                if ( empty($this->tags_to_convert) ) 
    336340                        $this->tags_to_convert = $_POST['tags_to_convert']; 
    337341 
    338                 $clean_cache = array(); 
     342                $hybrid_tags = $clear_parents = false; 
     343                $clean_cat_cache = $clean_term_cache = array(); 
     344                $default_cat = get_option('default_category'); 
    339345                echo '<ul>'; 
    340346 
    341347                foreach ( (array) $this->tags_to_convert as $tag_id) { 
    342348                        $tag_id = (int) $tag_id; 
    343349 
    344                         echo '<li>' . sprintf(__('Converting tag #%s ... '),  $tag_id); 
     350                        if ( $tag = get_term( $tag_id, 'post_tag' ) ) { 
     351                                printf('<li>' . __('Converting tag <strong>%s</strong> ... '),  $tag->name); 
    345352 
    346                         if ( ! is_term($tag_id, 'post_tag') ) { 
    347                                 _e('Tag doesn\'t exist!'); 
    348                         } else { 
     353                                if ( $cat_ttid = $wpdb->get_var( $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'category'", $tag->term_id) ) ) { 
     354                                        $objects_ids = get_objects_in_term($tag->term_id, 'post_tag'); 
     355                                        $cat_ttid = (int) $cat_ttid; 
     356                                        $term_order = 0; 
    349357 
    350                                 if ( is_term($tag_id, 'category') ) { 
    351                                         _e('This Tag is already a Category.'); 
    352                                         echo '</li>'; 
     358                                        foreach ( $objects_ids as $object_id ) { 
     359                                                $values[] = $wpdb->prepare( "(%d, %d, %d)", $object_id, $cat_ttid, $term_order); 
     360                                                clean_post_cache($object_id); 
     361                                        } 
     362 
     363                                        if ( $values ) { 
     364                                                $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)"); 
     365 
     366                                                if ( $default_cat != $tag->term_id ) { 
     367                                                        $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tag->term_id) ); 
     368                                                        $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_id = %d AND taxonomy = 'category'", $count, $tag->term_id) ); 
     369                                                } 
     370                                        } 
     371 
     372                                        $hybrid_tags = true; 
     373                                        $clean_term_cache[] = $tag->term_id; 
     374                                        $clean_cat_cache[] = $tag->term_id; 
     375                                        echo __('All posts were added to the category with the same name.') . " *</li>\n"; 
     376 
    353377                                        continue; 
    354378                                } 
    355379 
    356                                 $tt_ids = $wpdb->get_col( $wpdb->prepare("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'post_tag'", $tag_id) ); 
    357                                 if ( $tt_ids ) { 
    358                                                 $posts = $wpdb->get_col("SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . join(',', $tt_ids) . ") GROUP BY object_id"); 
    359                                         foreach ( (array) $posts as $post ) 
    360                                                 clean_post_cache($post); 
    361                                 } 
    362  
    363380                                // Change the tag to a category. 
    364                                 $parent = $wpdb->get_var( $wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'post_tag'", $tag_id) ); 
    365                                 if ( 0 == $parent || (0 < (int) $parent && $this->_category_exists($parent)) ) 
     381                                $parent = $wpdb->get_var( $wpdb->prepare("SELECT parent FROM $wpdb->term_taxonomy WHERE term_id = %d AND taxonomy = 'post_tag'", $tag->term_id) ); 
     382                                if ( 0 == $parent || (0 < (int) $parent && $this->_category_exists($parent)) ) { 
    366383                                        $reset_parent = ''; 
    367                                 else $reset_parent = ", parent = '0'"; 
     384                                        $clear_parents = true; 
     385                                } else 
     386                                        $reset_parent = ", parent = '0'"; 
    368387 
    369                                 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET taxonomy = 'category' $reset_parent WHERE term_id = %d AND taxonomy = 'post_tag'", $tag_id) ); 
     388                                $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET taxonomy = 'category' $reset_parent WHERE term_id = %d AND taxonomy = 'post_tag'", $tag->term_id) ); 
    370389 
    371                                 // Clean the cache 
    372                                 $clean_cache[] = $tag_id; 
     390                                $clean_term_cache[] = $tag->term_id; 
     391                                $clean_cat_cache[] = $cat['term_id']; 
     392                                echo __('Converted successfully.') . "</li>\n"; 
    373393 
    374                                 _e('Converted successfully.'); 
     394                        } else { 
     395                                printf( '<li>' . __('Tag #%s doesn\'t exist!') . "</li>\n",  $tag_id ); 
    375396                        } 
     397                } 
    376398 
    377                         echo '</li>'; 
     399                if ( ! empty($clean_term_cache) ) { 
     400                        $clean_term_cache = array_unique(array_values($clean_term_cache)); 
     401                        foreach ( $clean_term_cache as $id ) 
     402                                wp_cache_delete($id, 'post_tag'); 
    378403                } 
    379404 
    380                 clean_term_cache( $clean_cache, 'post_tag' ); 
    381                 delete_option('category_children'); 
    382                  
     405                if ( ! empty($clean_cat_cache) ) { 
     406                        $clean_cat_cache = array_unique(array_values($clean_cat_cache)); 
     407                        foreach ( $clean_cat_cache as $id ) 
     408                                wp_cache_delete($id, 'category'); 
     409                } 
     410 
     411                if ( $clear_parents ) delete_option('category_children'); 
     412 
    383413                echo '</ul>'; 
     414                if ( $hybrid_tags ) 
     415                        echo '<p>' . sprintf( __('* This tag is also a category. The converter has added all posts from it to the category. If you want to remove it, please confirm that all posts were added successfully, then delete it from the <a href="%s">Manage Tags</a> page.'), 'edit-tags.php') . '</p>'; 
    384416                echo '<p>' . sprintf( __('We&#8217;re all done here, but you can always <a href="%s">convert more</a>.'), 'admin.php?import=wp-cat2tag&amp;step=3' ) . '</p>'; 
    385417        } 
    386418 
     
    401433                                        check_admin_referer('import-cat2tag'); 
    402434                                        $this->convert_categories(); 
    403435                                break; 
    404                                  
     436 
    405437                                case 3 : 
    406438                                        $this->tags_tab(); 
    407439                                break; 
    408                                  
     440 
    409441                                case 4 : 
    410442                                        check_admin_referer('import-cat2tag'); 
    411443                                        $this->convert_tags(); 
  • wp-admin/wp-admin.css

    old new  
    547547        border-top-style: solid; 
    548548} 
    549549 
    550 #wphead a, #dashmenu a, #adminmenu a, #submenu a, #sidemenu a
     550#wphead a, #dashmenu a, #adminmenu a, #submenu a, #sidemenu a, #taglist a, #catlist a
    551551        text-decoration: none; 
    552552} 
    553553