diff --git a/wp-admin/import/wp-cat2tag.php b/wp-admin/import/wp-cat2tag.php
index 5f2869e153..1c5d43a1c9 100644
--- a/wp-admin/import/wp-cat2tag.php
+++ b/wp-admin/import/wp-cat2tag.php
@@ -96,10 +96,11 @@ class WP_Categories_to_Tags {
function convert_them() {
global $wpdb;
- if (!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_to_convert'])) {
+ if ( (!isset($_POST['cats_to_convert']) || !is_array($_POST['cats_to_convert'])) && empty($this->categories_to_convert)) {
print '
';
print '
' . sprintf(__('Uh, oh. Something didn\'t work. Please try again.'), 'admin.php?import=wp-cat2tag') . '
';
print '
';
+ return;
}
@@ -109,16 +110,22 @@ class WP_Categories_to_Tags {
print '';
- foreach ($this->categories_to_convert as $cat_id) {
+ foreach ( (array) $this->categories_to_convert as $cat_id) {
$cat_id = (int) $cat_id;
- print '- ' . __('Converting category') . ' #' . $cat_id . '... ';
+ print '
- ' . sprintf(__('Converting category #%s ... '), $cat_id);
if (!$this->_category_exists($cat_id)) {
_e('Category doesn\'t exist!');
} else {
$category =& get_category($cat_id);
+ if ( tag_exists($wpdb->escape($category->name)) ) {
+ _e('Category is already a tag.');
+ print '
';
+ continue;
+ }
+
// Set the category itself to $type from above
$wpdb->query("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag' WHERE term_id = '{$category->term_id}' AND taxonomy = 'category'");
@@ -155,8 +162,8 @@ class WP_Categories_to_Tags {
function convert_all() {
global $wpdb;
- $wpdb->query("UPDATE $wpdb->term_taxonomy SET taxonomy = 'post_tag', parent = 0 WHERE taxonomy = 'category'");
- clean_category_cache($category->term_id);
+ $this->categories_to_convert = get_categories('fields=ids&get=all');
+ $this->convert_them();
}
function init() {