From 8eceaca349e2701545565e8fa252b9b3f0e2cdfd Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 18 Sep 2007 17:50:21 +0000 Subject: [PATCH] Import tags. see #4682 git-svn-id: http://svn.automattic.com/wordpress/trunk@6129 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/import/wordpress.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/wp-admin/import/wordpress.php b/wp-admin/import/wordpress.php index 4ed6e8dd13..df1b67bd06 100644 --- a/wp-admin/import/wordpress.php +++ b/wp-admin/import/wordpress.php @@ -88,6 +88,7 @@ class WP_Import { $this->posts = array(); $this->categories = array(); + $this->tags = array(); $num = 0; $doing_entry = false; @@ -101,6 +102,11 @@ class WP_Import { $this->categories[] = $category[1]; continue; } + if ( false !== strpos($importline, '') ) { + preg_match('|(.*?)|is', $importline, $tag); + $this->tags[] = $tag[1]; + continue; + } if ( false !== strpos($importline, '') ) { $this->posts[$num] = ''; $doing_entry = true; @@ -246,6 +252,27 @@ class WP_Import { } } + function process_tags() { + global $wpdb; + + $tag_names = (array) get_terms('post_tag', 'fields=names'); + + while ( $c = array_shift($this->tags) ) { + $tag_name = trim($this->get_tag( $c, 'wp:tag_name' )); + + // If the category exists we leave it alone + if ( in_array($tag_name, $tag_names) ) + continue; + + $slug = $this->get_tag( $c, 'wp:tag_slug' ); + $description = $this->get_tag( $c, 'wp:tag_description' ); + + $tagarr = compact('slug', 'description'); + + $tag_ID = wp_insert_term($tag_name, 'post_tag', $tagarr); + } + } + function process_posts() { $i = -1; echo '
    '; @@ -391,6 +418,7 @@ class WP_Import { $this->get_authors_from_post(); $this->get_entries(); $this->process_categories(); + $this->process_tags(); $result = $this->process_posts(); if ( is_wp_error( $result ) ) return $result;