8889841chome/clixcotz/iec.clix.co.tz/wp-content/plugins/wpcat2tag-importer/wpcat2tag-importer.php 0000644 00000046305 15051346744 0025664 0 ustar 00 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' ) ); ?>
' . __('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 ''.__('You have no categories to convert!', 'wpcat2tag-importer').'
'; } } function categories_form() { $hier = _get_term_hierarchy( 'category' ); echo 'convert_tags(); return; } $this->populate_tags(); $tags_num = count( $this->all_tags ); if ( $tags_num > 0 ) { 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 ''.__('You have no tags to convert!', 'wpcat2tag-importer').'
'; } } function tags_form() { ?> 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 '' . sprintf( __('Uh, oh. Something didn’t work. Please try again.', 'wpcat2tag-importer'), admin_url('admin.php?import=wpcat2tag&tab=formats') ) . '
'; echo '' . $term_info->get_error_message() . ' '; printf( __( 'Please try again.', 'wpcat2tag-importer' ), 'admin.php?import=wpcat2tag&tab=cats' ) . "
\n"; return; } 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 '' . sprintf(__('Uh, oh. Something didn’t work. Please try again.', 'wpcat2tag-importer'), 'admin.php?import=wpcat2tag&tab=cats') . '
'; echo ''; echo $term_info->get_error_message() . ' '; printf( __( 'Please try again.', 'wpcat2tag-importer' ), 'admin.php?import=wpcat2tag&tab=cats' ); 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 '' . sprintf(__('Uh, oh. Something didn’t work. Please try again.', 'wpcat2tag-importer'), 'admin.php?import=wpcat2tag&tab=tags') . '
'; echo ''; echo $term_info->get_error_message() . ' '; printf( __( 'Please try again.', 'wpcat2tag-importer' ), 'admin.php?import=wpcat2tag&tab=tags' ); 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' );