diff --git a/wp-admin/import/wp-cat2tag.php b/wp-admin/import/wp-cat2tag.php index 6811195768..c703032378 100644 --- a/wp-admin/import/wp-cat2tag.php +++ b/wp-admin/import/wp-cat2tag.php @@ -16,22 +16,27 @@ class WP_Categories_to_Tags { function populate_all_categories() { global $wpdb; - $this->all_categories = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE (type & ~ " . TAXONOMY_TAG . ") != 0 ORDER BY cat_name ASC"); + $this->all_categories = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE (type & ~ " . TAXONOMY_TAG . ") != 0 AND category_count > 0 ORDER BY cat_name ASC"); } function welcome() { - print '
'; - print '

' . __('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.') . '

'; - print '

' . __('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.') . '

'; + $this->populate_all_categories(); - $this->categories_form(); + print '
'; + + if (count($this->all_categories) > 0) { + print '

' . __('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.') . '

'; + print '

' . __('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.') . '

'; + + $this->categories_form(); + } else { + print '

You have no categories to convert!

'; + } print '
'; } function categories_form() { - $this->populate_all_categories(); - print '
'; print ''; - print '

'; + + print '

'; print '
'; } @@ -138,11 +144,45 @@ class WP_Categories_to_Tags { print ''; } + function convert_all_confirm() { + print '
'; + + print '

' . __('Confirm') . '

'; + + print '

' . __('You are about to convert all categories to tags. Are you sure you want to continue?') . '

'; + + print '
'; + print '

    

'; + print '
'; + + print '
'; + } + + function convert_all() { + global $wpdb; + + $cats = $wpdb->get_results("SELECT * FROM $wpdb->categories WHERE (type & ~ " . TAXONOMY_TAG . ") != 0 AND category_count > 0"); + + $_POST['cats_to_convert'] = array(); + + foreach ($cats as $cat) { + $_POST['cats_to_convert'][] = $cat->cat_ID; + } + + $this->convert_them(); + } + function init() { - if (!isset($_GET['step'])) { - $step = 1; + echo ''; + + if (isset($_POST['maybe_convert_all_cats'])) { + $step = 3; + } elseif (isset($_POST['yes_convert_all_cats'])) { + $step = 4; + } elseif (isset($_POST['no_dont_do_it'])) { + die('no_dont_do_it'); } else { - $step = (int) $_GET['step']; + $step = (isset($_GET['step'])) ? (int) $_GET['step'] : 1; } $this->header(); @@ -160,6 +200,14 @@ class WP_Categories_to_Tags { case 2 : $this->convert_them(); break; + + case 3 : + $this->convert_all_confirm(); + break; + + case 4 : + $this->convert_all(); + break; } }