WordPress.org

Make WordPress Core

Changeset 5251


Ignore:
Timestamp:
04/12/2007 05:46:36 AM (11 years ago)
Author:
rob1n
Message:

Add ability to convert all categories to tags. fixes #4135

File:
1 edited

Legend:

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

    r5229 r5251  
    1717        global $wpdb;
    1818       
    19         $this->all_categories = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE (type & ~ " . TAXONOMY_TAG . ") != 0 ORDER BY cat_name ASC");
     19        $this->all_categories = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE (type & ~ " . TAXONOMY_TAG . ") != 0 AND category_count > 0 ORDER BY cat_name ASC");
    2020    }
    2121   
    2222    function welcome() {
     23        $this->populate_all_categories();
     24       
    2325        print '<div class="narrow">';
    24         print '<p>' . __('Howdy! This converter allows you to selectively convert existing categories to tags. To get started, check the checkboxes of the categories you wish to be converted, then click the Convert button.') . '</p>';
    25         print '<p>' . __('Keep in mind that if you convert a category with child categories, those child categories get their parent setting removed, so they\'re in the root.') . '</p>';
    26        
    27         $this->categories_form();
     26       
     27        if (count($this->all_categories) > 0) {
     28            print '<p>' . __('Howdy! This converter allows you to selectively convert existing categories to tags. To get started, check the checkboxes of the categories you wish to be converted, then click the Convert button.') . '</p>';
     29            print '<p>' . __('Keep in mind that if you convert a category with child categories, those child categories get their parent setting removed, so they\'re in the root.') . '</p>';
     30       
     31            $this->categories_form();
     32        } else {
     33            print '<p>You have no categories to convert!</p>';
     34        }
    2835       
    2936        print '</div>';
     
    3138   
    3239    function categories_form() {
    33         $this->populate_all_categories();
    34        
    3540        print '<form action="admin.php?import=wp-cat2tag&amp;step=2" method="post">';
    3641        print '<ul style="list-style:none">';
     
    5156       
    5257        print '</ul>';
    53         print '<p class="submit"><input type="submit" name="submit" value="' . __('Convert &raquo;') . '" /></p>';
     58       
     59        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>';
    5460        print '</form>';
    5561    }
     
    139145    }
    140146   
     147    function convert_all_confirm() {
     148        print '<div class="narrow">';
     149       
     150        print '<h3>' . __('Confirm') . '</h3>';
     151       
     152        print '<p>' . __('You are about to convert all categories to tags. Are you sure you want to continue?') . '</p>';
     153       
     154        print '<form action="admin.php?import=wp-cat2tag" method="post">';
     155        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>';
     156        print '</form>';
     157       
     158        print '</div>';
     159    }
     160   
     161    function convert_all() {
     162        global $wpdb;
     163       
     164        $cats = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE (type & ~ " . TAXONOMY_TAG . ") != 0 AND category_count > 0");
     165       
     166        $_POST['cats_to_convert'] = array();
     167       
     168        foreach ($cats as $cat) {
     169            $_POST['cats_to_convert'][] = $cat->cat_ID;
     170        }
     171       
     172        $this->convert_them();
     173    }
     174   
    141175    function init() {
    142         if (!isset($_GET['step'])) {
    143             $step = 1;
    144         } else {
    145             $step = (int) $_GET['step'];
     176        echo '<!--'; print_r($_POST); print_r($_GET); echo '-->';
     177       
     178        if (isset($_POST['maybe_convert_all_cats'])) {
     179            $step = 3;
     180        } elseif (isset($_POST['yes_convert_all_cats'])) {
     181            $step = 4;
     182        } elseif (isset($_POST['no_dont_do_it'])) {
     183            die('no_dont_do_it');
     184        } else {
     185            $step = (isset($_GET['step'])) ? (int) $_GET['step'] : 1;
    146186        }
    147187       
     
    161201                    $this->convert_them();
    162202                break;
     203               
     204                case 3 :
     205                    $this->convert_all_confirm();
     206                break;
     207               
     208                case 4 :
     209                    $this->convert_all();
     210                break;
    163211            }
    164212        }
Note: See TracChangeset for help on using the changeset viewer.