Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/import/wp-cat2tag.php

    r6226 r6147  
    6464        print '</ul>';
    6565
    66         print '<p class="submit"><input type="submit" name="submit" value="' . __('Convert &raquo;') . '" /></p>';
     66        print '<p class="submit"><input type="submit" name="maybe_convert_all_cats" value="' . __('Convert All Categories') . '" /> <input type="submit" name="submit" value="' . __('Convert &raquo;') . '" /></p>';
    6767        print '</form>';
    6868    }
     
    141141                        if ( !$wpdb->get_var("SELECT object_id FROM $wpdb->term_relationships WHERE object_id = '$post' AND term_taxonomy_id = '$id'") )                       
    142142                            $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$post', '$id')");
    143                         clean_post_cache($post);
    144143                    }
    145144                } else {
    146                     $tt_ids = $wpdb->get_col("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'");
    147                     if ( $tt_ids ) {
    148                         $posts = $wpdb->get_col("SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id IN (" . join(',', $tt_ids) . ") GROUP BY object_id");
    149                         foreach ( (array) $posts as $post )
    150                             clean_post_cache($post);
    151                     }
    152 
    153145                    // Change the category to a tag.
    154146                    $wpdb->query("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'");
    155 
    156                     $terms = $wpdb->get_col("SELECT term_id FROM $wpdb->term_taxonomy WHERE parent = '{$category->term_id}' AND taxonomy = 'category'");
    157                     foreach ( (array) $terms as $term )
    158                         clean_category_cache($term);
    159147
    160148                    // Set all parents to 0 (root-level) if their parent was the converted tag
     
    173161    }
    174162
     163    function convert_all_confirm() {
     164        print '<div class="narrow">';
     165
     166        print '<h3>' . __('Confirm') . '</h3>';
     167
     168        print '<p>' . __('You are about to convert all categories to tags. Are you sure you want to continue?') . '</p>';
     169
     170        print '<form action="admin.php?import=wp-cat2tag" method="post">';
     171        wp_nonce_field('import-cat2tag');
     172        print '<p style="text-align:center" class="submit"><input type="submit" value="' . __('Yes') . '" name="yes_convert_all_cats" />&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" value="' . __('No') . '" name="no_dont_do_it" /></p>';
     173        print '</form>';
     174
     175        print '</div>';
     176    }
     177
     178    function convert_all() {
     179        global $wpdb;
     180
     181        $this->populate_all_categories();
     182        foreach ( $this->all_categories as $category )
     183            $this->categories_to_convert[] = $category->term_id;
     184        $this->convert_them();
     185    }
     186
    175187    function init() {
    176188
    177         $step = (isset($_GET['step'])) ? (int) $_GET['step'] : 1;
     189        if (isset($_POST['maybe_convert_all_cats'])) {
     190            $step = 3;
     191        } elseif (isset($_POST['yes_convert_all_cats'])) {
     192            $step = 4;
     193        } elseif (isset($_POST['no_dont_do_it'])) {
     194            die('no_dont_do_it');
     195        } else {
     196            $step = (isset($_GET['step'])) ? (int) $_GET['step'] : 1;
     197        }
    178198
    179199        $this->header();
     
    195215                    $this->convert_them();
    196216                break;
     217
     218                case 3 :
     219                    $this->convert_all_confirm();
     220                break;
     221
     222                case 4 :
     223                    $this->convert_all();
     224                break;
    197225            }
    198226        }
Note: See TracChangeset for help on using the changeset viewer.