Export and import custom taxonomies. Props chrisscott. fixes #10012

git-svn-id: https://develop.svn.wordpress.org/trunk@12109 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2009-10-26 13:57:55 +00:00
parent 022ee3f66d
commit ba1f1d3780
2 changed files with 83 additions and 1 deletions
+44
View File
@@ -27,6 +27,7 @@ class WP_Import {
var $author_ids = array ();
var $tags = array ();
var $categories = array ();
var $terms = array ();
var $j = -1;
var $fetch_attachments = false;
@@ -122,6 +123,11 @@ class WP_Import {
$this->tags[] = $tag[1];
continue;
}
if ( false !== strpos($importline, '<wp:term>') ) {
preg_match('|<wp:term>(.*?)</wp:term>|is', $importline, $term);
$this->terms[] = $term[1];
continue;
}
if ( false !== strpos($importline, '<item>') ) {
$this->post = '';
$doing_entry = true;
@@ -337,6 +343,43 @@ class WP_Import {
$tag_ID = wp_insert_term($tag_name, 'post_tag', $tagarr);
}
}
function process_terms() {
global $wpdb, $wp_taxonomies;
$custom_taxonomies = $wp_taxonomies;
// get rid of the standard taxonomies
unset( $custom_taxonomies['category'] );
unset( $custom_taxonomies['post_tag'] );
unset( $custom_taxonomies['link_category'] );
$custom_taxonomies = array_keys( $custom_taxonomies );
$current_terms = (array) get_terms( $custom_taxonomies, 'get=all' );
$taxonomies = array();
foreach ( $current_terms as $term ) {
if ( isset( $_terms[$term->taxonomy] ) ) {
$taxonomies[$term->taxonomy] = array_merge( $taxonomies[$term->taxonomy], array($term->name) );
} else {
$taxonomies[$term->taxonomy] = array($term->name);
}
}
while ( $c = array_shift($this->terms) ) {
$term_name = trim($this->get_tag( $c, 'wp:term_name' ));
$term_taxonomy = trim($this->get_tag( $c, 'wp:term_taxonomy' ));
// If the term exists in the taxonomy we leave it alone
if ( isset($taxonomies[$term_taxonomy] ) && in_array( $term_name, $taxonomies[$term_taxonomy] ) )
continue;
$slug = $this->get_tag( $c, 'wp:term_slug' );
$description = $this->get_tag( $c, 'wp:term_description' );
$termarr = compact('slug', 'description');
$term_ID = wp_insert_term($term_name, $this->get_tag( $c, 'wp:term_taxonomy' ), $termarr);
}
}
function process_author($post) {
$author = $this->get_tag( $post, 'dc:creator' );
@@ -748,6 +791,7 @@ class WP_Import {
$this->get_entries();
$this->process_categories();
$this->process_tags();
$this->process_terms();
$result = $this->process_posts();
wp_suspend_cache_invalidation(false);
$this->backfill_parents();