8889841chome/clixcotz/iec.clix.co.tz/wp-content/plugins/wpcat2tag-importer/wpcat2tag-importer.php000064400000046305150513467440025664 0ustar00 array( 'label' => __( 'Categories', 'wpcat2tag-importer' ), 'url' => admin_url( 'admin.php?import=wpcat2tag&tab=cats' ) ), 'tags' => array( 'label' => __( 'Tags', 'wpcat2tag-importer' ), 'url' => admin_url( 'admin.php?import=wpcat2tag&tab=tags' ) ) ); if ( function_exists( 'set_post_format' ) ) $tabs['formats'] = array( 'label' => __( 'Formats', 'wpcat2tag-importer' ), 'url' => admin_url( 'admin.php?import=wpcat2tag&tab=formats' ) ); ?>

'; } function populate_cats() { $categories = get_categories( array('get' => 'all') ); foreach ( $categories as $category ) { $this->all_categories[] = $category; if ( term_exists( $category->slug, 'post_tag' ) ) $this->hybrids_ids[] = $category->term_id; } } function populate_tags() { $tags = get_terms( array('post_tag'), array('get' => 'all') ); foreach ( $tags as $tag ) { $this->all_tags[] = $tag; if ( term_exists( $tag->slug, 'category' ) ) $this->hybrids_ids[] = $tag->term_id; } } function categories_tab() { if ( isset($_POST['cats_to_convert']) ) { $this->convert_categories(); return; } $this->populate_cats(); $cat_num = count( $this->all_categories ); if ( $cat_num > 0 ) { 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.', 'wpcat2tag-importer') . '

'; echo '

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

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

'.__('You have no categories to convert!', 'wpcat2tag-importer').'

'; } } function categories_form() { $hier = _get_term_hierarchy( 'category' ); echo '
'; wp_nonce_field( 'import-cat2tag' ); echo ''; if ( ! empty($this->hybrids_ids) ) echo '

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

'; if ( current_theme_supports( 'post-formats' ) ) : $post_formats = get_theme_support( 'post-formats' ); if ( is_array( $post_formats[0] ) ) : ?>



convert_tags(); return; } $this->populate_tags(); $tags_num = count( $this->all_tags ); if ( $tags_num > 0 ) { 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.', 'wpcat2tag-importer') . '

'; echo '

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

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

'.__('You have no tags to convert!', 'wpcat2tag-importer').'

'; } } 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.', 'wpcat2tag-importer') . '

'; ?>



convert_formats(); return; } $formats = get_terms( array('post_format'), array('get'=>'all') ); $format_count = count( $formats ); if ( $format_count > 0 ) { ?>



' . __( 'You have no posts set to a specific format.', 'wpcat2tag-importer' ) . '

'; } } function convert_formats() { check_admin_referer( 'import-cat2tag' ); if ( ! is_array($_POST['post_formats']) || empty($_POST['convert_to_slug']) || ('cat' != $_POST['convert_to'] && 'tag' != $_POST['convert_to']) ) { echo '
'; echo '

' . sprintf( __('Uh, oh. Something didn’t work. Please try again.', 'wpcat2tag-importer'), admin_url('admin.php?import=wpcat2tag&tab=formats') ) . '

'; echo '
'; return; } $convert_to = 'tag' == $_POST['convert_to'] ? 'post_tag' : 'category'; if ( ! $term_info = term_exists( $_POST['convert_to_slug'], $convert_to ) ) $term_info = wp_insert_term( $_POST['convert_to_slug'], $convert_to ); if ( is_wp_error($term_info) ) { echo '

' . $term_info->get_error_message() . ' '; printf( __( 'Please try again.', 'wpcat2tag-importer' ), 'admin.php?import=wpcat2tag&tab=cats' ) . "

\n"; return; } echo ''; echo '

' . sprintf( __( 'We’re all done here, but you can always convert more.', 'wpcat2tag-importer' ), admin_url( 'admin.php?import=wpcat2tag&tab=formats' ) ) . '

'; } function _category_children( $parent, $hier ) { echo ''; } function convert_categories() { global $wpdb; check_admin_referer( 'import-cat2tag' ); if ( ! is_array($_POST['cats_to_convert']) ) { echo '
'; echo '

' . sprintf(__('Uh, oh. Something didn’t work. Please try again.', 'wpcat2tag-importer'), 'admin.php?import=wpcat2tag&tab=cats') . '

'; echo '
'; return; } $default = get_option( 'default_category' ); if ( ! isset($_POST['convert_to']) || 'format' != $_POST['convert_to'] ) { $convert_to = 'post_tag'; } else { $convert_to = 'post_format'; $term_info = $this->_get_format_info( sanitize_key($_POST['post_format']) ); if ( is_wp_error($term_info) ) { echo '

'; echo $term_info->get_error_message() . ' '; printf( __( 'Please try again.', 'wpcat2tag-importer' ), 'admin.php?import=wpcat2tag&tab=cats' ); echo '

'; return; } } echo ''; echo '

' . sprintf( __( 'We’re all done here, but you can always convert more.', 'wpcat2tag-importer' ), admin_url( 'admin.php?import=wpcat2tag&tab=cats' ) ) . '

'; } function convert_tags() { check_admin_referer( 'import-cat2tag' ); if ( ! is_array($_POST['tags_to_convert']) ) { echo '
'; echo '

' . sprintf(__('Uh, oh. Something didn’t work. Please try again.', 'wpcat2tag-importer'), 'admin.php?import=wpcat2tag&tab=tags') . '

'; echo '
'; return; } if ( ! isset($_POST['convert_to']) || 'format' != $_POST['convert_to'] ) { $convert_to = 'category'; } else { $convert_to = 'post_format'; $term_info = $this->_get_format_info( sanitize_key($_POST['post_format']) ); if ( is_wp_error($term_info) ) { echo '

'; echo $term_info->get_error_message() . ' '; printf( __( 'Please try again.', 'wpcat2tag-importer' ), 'admin.php?import=wpcat2tag&tab=tags' ); echo '

'; return; } } echo ''; echo '

' . sprintf( __( 'We’re all done here, but you can always convert more.', 'wpcat2tag-importer' ), admin_url( 'admin.php?import=wpcat2tag&tab=tags' ) ) . '

'; } /** * Convert all term relationships to a new term, delete the old term if possible. * * The old term will not be deleted if it's the default category or if it's a part * of any other taxonomies. * * @param array $from term_id, taxonomy and term_taxonomy_id of the term+taxonomy pair converting from * @param int $to_ttid The term_taxonomy_id of the term+taxonomy pair we are converting to */ function _convert_term( $from, $to_ttid ) { global $wpdb; // transfer all the term relationships $wpdb->update( $wpdb->term_relationships, array( 'term_taxonomy_id' => $to_ttid ), array( 'term_taxonomy_id' => $from['term_taxonomy_id'] ) ); // remove the old term wp_delete_term( $from['term_id'], $from['taxonomy'] ); } function _get_format_info( $format ) { if ( current_theme_supports( 'post-formats' ) && ! empty( $format ) ) { $post_formats = get_theme_support( 'post-formats' ); if ( is_array( $post_formats ) ) { $post_formats = $post_formats[0]; if ( ! in_array( $format, $post_formats ) ) return new WP_Error( 'invalid_format', sprintf( __( 'Bad post format %s.', 'wpcat2tag-importer' ), esc_html($format) ) ); } } else { return new WP_Error( 'invalid_format', __( 'Either your theme does not support post formats or you supplied an invalid format.', 'wpcat2tag-importer' ) ); } $format = 'post-format-' . $format; if ( ! $term_info = term_exists( $format, 'post_format' ) ) $term_info = wp_insert_term( $format, 'post_format' ); return $term_info; } function init() { if ( ! current_user_can( 'manage_categories' ) ) wp_die( __( 'Cheatin’ uh?', 'wpcat2tag-importer' ) ); $tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'cats'; $this->header( $tab ); if ( 'cats' == $tab ) $this->categories_tab(); else if ( 'tags' == $tab ) $this->tags_tab(); else if ( 'formats' == $tab && function_exists( 'set_post_format' ) ) $this->formats_tab(); $this->footer(); } } $wp_cat2tag_importer = new WP_Categories_to_Tags(); register_importer('wpcat2tag', __('Categories and Tags Converter', 'wpcat2tag-importer'), __('Convert existing categories to tags or tags to categories, selectively.', 'wpcat2tag-importer'), array(&$wp_cat2tag_importer, 'init')); } // class_exists( 'WP_Importer' ) function wpcat2tag_importer_init() { load_plugin_textdomain( 'wpcat2tag-importer', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); } add_action( 'init', 'wpcat2tag_importer_init' );