'; if ( ! current_user_can('manage_categories') ) { echo '
'; echo '

' . __('Cheatin’ uh?') . '

'; echo '
'; } else { ?>

'; } function populate_cats() { $categories = get_categories('get=all'); foreach ( $categories as $category ) { $this->all_categories[] = $category; if ( is_term( $category->slug, 'post_tag' ) ) $this->hybrids_ids[] = $category->term_id; } } function populate_tags() { $tags = get_terms( array('post_tag'), 'get=all' ); foreach ( $tags as $tag ) { $this->all_tags[] = $tag; if ( is_term( $tag->slug, 'category' ) ) $this->hybrids_ids[] = $tag->term_id; } } function categories_tab() { $this->populate_cats(); $cat_num = count($this->all_categories); echo '
'; if ( $cat_num > 0 ) { screen_icon(); echo '

' . sprintf( _n( 'Convert Category to Tag.', 'Convert Categories (%d) to Tags.', $cat_num ), $cat_num ) . '

'; echo '
'; echo '

' . __('Hey there. Here you can selectively convert existing categories to tags. To get started, check the categories you wish to be converted, then click the Convert button.') . '

'; echo '

' . __('Keep in mind that if you convert a category with child categories, the children become top-level orphans.') . '

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

'.__('You have no categories to convert!').'

'; } } function categories_form() { ?>

hybrids_ids) ) echo '

' . __('* This category is also a tag. Converting it will add that tag to all posts that are currently in the category.') . '

'; ?>

populate_tags(); $tags_num = count($this->all_tags); echo '
'; if ( $tags_num > 0 ) { screen_icon(); echo '

' . sprintf( _n( 'Convert Tag to Category.', 'Convert Tags (%d) to Categories.', $tags_num ), $tags_num ) . '

'; echo '
'; echo '

' . __('Here you can selectively convert existing tags to categories. To get started, check the tags you wish to be converted, then click the Convert button.') . '

'; echo '

' . __('The newly created categories will still be associated with the same posts.') . '

'; $this->tags_form(); } else { echo '

'.__('You have no tags to convert!').'

'; } } function tags_form() { ?>

hybrids_ids) ) echo '

' . __('* This tag is also a category. When converted, all posts associated with the tag will also be in the category.') . '

'; ?>

categories_to_convert)) { ?>

try again.'), 'admin.php?import=wp-cat2tag'); ?>

categories_to_convert) ) $this->categories_to_convert = $_POST['cats_to_convert']; $hier = _get_term_hierarchy('category'); $hybrid_cats = $clear_parents = $parents = false; $clean_term_cache = $clean_cat_cache = array(); $default_cat = get_option('default_category'); echo ''; if ( ! empty($clean_term_cache) ) { $clean_term_cache = array_unique(array_values($clean_term_cache)); clean_term_cache($clean_term_cache, 'post_tag'); } if ( ! empty($clean_cat_cache) ) { $clean_cat_cache = array_unique(array_values($clean_cat_cache)); clean_term_cache($clean_cat_cache, 'category'); } if ( $clear_parents ) delete_option('category_children'); if ( $hybrid_cats ) echo '

' . 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 Manage Categories page.'), 'categories.php') . '

'; echo '

' . sprintf( __('We’re all done here, but you can always convert more.'), 'admin.php?import=wp-cat2tag' ) . '

'; } function convert_tags() { global $wpdb; if ( (!isset($_POST['tags_to_convert']) || !is_array($_POST['tags_to_convert'])) && empty($this->tags_to_convert)) { echo '
'; echo '

' . sprintf(__('Uh, oh. Something didn’t work. Please try again.'), 'admin.php?import=wp-cat2tag&step=3') . '

'; echo '
'; return; } if ( empty($this->tags_to_convert) ) $this->tags_to_convert = $_POST['tags_to_convert']; $hybrid_tags = $clear_parents = false; $clean_cat_cache = $clean_term_cache = array(); $default_cat = get_option('default_category'); echo ''; if ( $hybrid_tags ) echo '

' . 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 Manage Tags page.'), 'edit-tags.php') . '

'; echo '

' . sprintf( __('We’re all done here, but you can always convert more.'), 'admin.php?import=wp-cat2tag&step=3' ) . '

'; } function init() { $step = (isset($_GET['step'])) ? (int) $_GET['step'] : 1; $this->header(); if ( current_user_can('manage_categories') ) { switch ($step) { case 1 : $this->categories_tab(); break; case 2 : check_admin_referer('import-cat2tag'); $this->convert_categories(); break; case 3 : $this->tags_tab(); break; case 4 : check_admin_referer('import-cat2tag'); $this->convert_tags(); break; } } $this->footer(); } function WP_Categories_to_Tags() { // Do nothing. } } $wp_cat2tag_importer = new WP_Categories_to_Tags(); register_importer('wp-cat2tag', __('Categories and Tags Converter'), __('Convert existing categories to tags or tags to categories, selectively.'), array(&$wp_cat2tag_importer, 'init')); ?>