';
if ( ! current_user_can('manage_categories') ) {
echo '
';
echo '
' . __('Cheatin’ uh?', 'wptaxconvertaffinitomics') . '
';
echo '
';
} else { ?>
taxes as $name => $tax) {
if ($name == $current)
$classes = 'nav-tab nav-tab-active';
else
$classes = 'nav-tab';
?>
label; ?>
';
}
function populate_taxes() {
$taxonomies = get_taxonomies(array('public' => true),'names');
foreach ( $taxonomies as $taxonomy ) {
if ($taxonomy !== 'post_format')
$this->taxes[$taxonomy] = get_taxonomy($taxonomy);
}
}
function populate_tax($tax) {
$terms = get_terms( array($tax), array('get' => 'all') );
foreach ( $terms as $term ) {
$this->all_terms[$tax][] = $term;
if ( is_array(term_exists( $term->slug )) )
$this->hybrids_ids[] = $term->term_id;
}
}
function tabs($tax) {
$this->populate_tax($tax);
$num = count($this->all_terms[$tax]);
$details = $this->taxes[$tax];
echo '
';
if ( $num > 0 ) {
screen_icon();
echo '
' . __( 'Convert or Copy '.$details->label, 'wptaxconvertaffinitomics') . '
';
echo '
';
if ($details->label == 'Categories'){
echo '
' . __('
Copy or convert WordPress Categories into Affinitomic Descriptors.
', 'wptaxconvert') . '
';
} else if ($details->label == 'Tags') {
echo '
' . __('
Copy or convert WordPress Tags into Affinitomic Draws.
', 'wptaxconvert') . '
';
} else {
echo '
' . __('
Here you can selectively copy or convert existing terms from one taxonomy to another.
To get started, choose the original taxonomy (above), choose option to copy or convert,
select the terms (below), then click the Go button.', 'wptaxconvert') . '
';
}
echo '
' . __('
Keep in mind that "converted" terms are deleted from original taxonomy, and if you convert a term with children,
the children become top-level orphans.', 'wptaxconvert') . '
';
$this->terms_form($tax);
} else {
echo '
'.__('You have no terms to convert', 'wptaxconvertaffinitomics').'
';
}
}
function terms_form($tax) { ?>
terms_to_convert) || (!isset($_POST['taxes'])) ) { ?>
try again.', 'wptaxconvertaffinitomics'), 'admin.php?import=wptaxconvertaffinitomics&tax='.$tax); ?>
terms_to_convert) )
$this->terms_to_convert = $_POST['terms_to_convert'];
$taxonomy = $this->taxes[$tax];
$convert = $_POST['convert'];
if ($convert)
$c_label = 'Convert';
else
$c_label = 'Copy';
$new_taxes = $_POST['taxes'];
$num = count($new_taxes);
$hier = _get_term_hierarchy($tax);
$hybrid_cats = $clear_parents = $parents = false;
$clean_term_cache = array();
$default_cat = get_option('default_category');
echo '
';
foreach ( (array) $this->terms_to_convert as $term_id) {
$term_id = (int) $term_id;
$exists = term_exists($term_id,$tax);
// check if the term exists in the current taxonomy (it always should!)
if ( empty($exists) ) {
echo '- ' . sprintf( __('Term %s doesn’t exist in '.$taxonomy->label.'!', 'wptaxconvertaffinitomics'), $term_id ) . "
\n";
} else {
// if the term exist do the copy/convert
// $term is the existing term
$term = get_term($term_id,$tax);
echo '- ' . sprintf(__($c_label.'ing term %s ... ', 'wptaxconvertaffinitomics'), $term->name);
// repeat process for each new taxonomy selected
foreach ($new_taxes as $new_tax) {
// check if the term is already in the new taxonomy & if not create it
if ( ! ($id = term_exists( $term->slug, $new_tax ) ) )
$id = wp_insert_term($term->name, $new_tax, array('slug' => $term->slug));
// if the term couldn't be created return the error message
if ( is_wp_error($id) ) {
echo $id->get_error_message() . "
\n";
continue;
}
// if the original term has posts, assign them to the new term
$id = $id['term_taxonomy_id'];
$posts = get_objects_in_term($term->term_id, $tax);
$term_order = 0;
foreach ( $posts as $post ) {
$type = get_post_type($post);
if (in_array($type, $taxonomy->object_type))
$values[] = $wpdb->prepare( "(%d, %d, %d)", $post, $id, $term_order);
clean_post_cache($post);
}
if ( $values ) {
$wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)");
$wpdb->update($wpdb->term_taxonomy, array('count' => $term->count), array('term_id' => $term->term_id, 'taxonomy' => $new_tax) );
echo __('Term added to posts.* ', 'wptaxconvertaffinitomics');
if (!$convert)
$hybrid_cats = true;
$clean_term_cache[] = $term->term_id;
}
// Convert term
if ($convert) {
$del = wp_delete_term($term_id,$tax);
// Set all parents to 0 (root-level) if their parent was the converted tag
$wpdb->update($wpdb->term_taxonomy, array('parent' => 0), array('parent' => $term_id, 'taxonomy' => $tax) );
if ( $parents ) $clear_parents = true;
$clean_cat_cache[] = $term->term_id;
}
echo __($c_label.' successful.', 'wptaxconvertaffinitomics') . "\n";
}
}
}
echo '
';
if ( ! empty($clean_term_cache) ) {
$clean_term_cache = array_unique(array_values($clean_term_cache));
clean_term_cache($clean_term_cache, $new_tax);
}
if ( $clear_parents ) delete_option('category_children');
if ( $hybrid_cats )
echo '
' . __('* This term is now in multiple taxonomies. The converter has added the new term to all posts with the original taxonomy term.', 'wptaxconvertaffinitomics') . '
';
echo '
' . sprintf( __('We’re all done here, but you can always convert more.', 'wptaxconvertaffinitomics'), 'admin.php?import=wptaxconvertaffinitomics' ) . '
';
}
function init() {
$tax = (isset($_GET['tax'])) ? $_GET['tax'] : 'category';
$step = (isset($_GET['step'])) ? (int) $_GET['step'] : 1;
$this->header($tax);
if ( current_user_can('manage_categories') ) {
if ($step == 1)
$this->tabs($tax);
elseif ($step == 2)
$this->process($tax);
}
$this->footer();
}
function WP_Affinitomics_Taxonomy_Converter() {
// Do nothing.
}
}
$wp_taxconvert_affinitomics = new WP_Affinitomics_Taxonomy_Converter();
register_importer('wptaxconvertaffinitomics', __('Affinitomics Taxonomy Converter', 'wptaxconvertaffinitomics'), __('Automatically import your existing taxonomies into Affinitomics.', 'wptaxconvertaffinitomics'), array(&$wp_taxconvert_affinitomics, 'init'));
} // class_exists( 'WP_Importer' )
function wptaxconvertaffinitomics_init() {
load_plugin_textdomain( 'wptaxconvertaffinitomics', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
add_action( 'init', 'wptaxconvertaffinitomics_init' );