Import tags. see #4682
git-svn-id: http://svn.automattic.com/wordpress/trunk@6129 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1d146b6153
commit
8eceaca349
|
@ -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, '<wp:tag>') ) {
|
||||
preg_match('|<wp:tag>(.*?)</wp:tag>|is', $importline, $tag);
|
||||
$this->tags[] = $tag[1];
|
||||
continue;
|
||||
}
|
||||
if ( false !== strpos($importline, '<item>') ) {
|
||||
$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 '<ol>';
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue