Export and import of post tags. fixes #4682
git-svn-id: https://develop.svn.wordpress.org/trunk@6149 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
5aecb8912f
commit
4f4bb50529
@ -141,6 +141,27 @@ function wxr_tag_description($t) {
|
|||||||
echo '<wp:tag_description>' . wxr_cdata($t->description) . '</wp:tag_description>';
|
echo '<wp:tag_description>' . wxr_cdata($t->description) . '</wp:tag_description>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wxr_post_taxonomy() {
|
||||||
|
$categories = get_the_category();
|
||||||
|
$tags = get_the_tags();
|
||||||
|
$cat_names = array();
|
||||||
|
$tag_names = array();
|
||||||
|
$the_list = '';
|
||||||
|
$filter = 'rss';
|
||||||
|
|
||||||
|
if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
|
||||||
|
$cat_name = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
|
||||||
|
$the_list .= "\n\t\t<category><![CDATA[$cat_name]]></category>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
|
||||||
|
$tag_name = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
|
||||||
|
$the_list .= "\n\t\t<category domain=\"tag\"><![CDATA[$tag_name]]></category>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $the_list;
|
||||||
|
}
|
||||||
|
|
||||||
print '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
|
print '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@ -201,7 +222,7 @@ print '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
|
|||||||
<link><?php the_permalink_rss() ?></link>
|
<link><?php the_permalink_rss() ?></link>
|
||||||
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
|
<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
|
||||||
<dc:creator><?php the_author() ?></dc:creator>
|
<dc:creator><?php the_author() ?></dc:creator>
|
||||||
<?php the_category_rss() ?>
|
<?php wxr_post_taxonomy() ?>
|
||||||
|
|
||||||
<guid isPermaLink="false"><?php the_guid(); ?></guid>
|
<guid isPermaLink="false"><?php the_guid(); ?></guid>
|
||||||
<description></description>
|
<description></description>
|
||||||
|
@ -316,6 +316,15 @@ class WP_Import {
|
|||||||
$post_content = str_replace('<br>', '<br />', $post_content);
|
$post_content = str_replace('<br>', '<br />', $post_content);
|
||||||
$post_content = str_replace('<hr>', '<hr />', $post_content);
|
$post_content = str_replace('<hr>', '<hr />', $post_content);
|
||||||
|
|
||||||
|
preg_match_all('|<category domain="tag">(.*?)</category>|is', $post, $tags);
|
||||||
|
$tags = $tags[1];
|
||||||
|
|
||||||
|
$tag_index = 0;
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$tags[$tag_index] = $wpdb->escape($this->unhtmlentities(str_replace(array ('<![CDATA[', ']]>'), '', $tag)));
|
||||||
|
$tag_index++;
|
||||||
|
}
|
||||||
|
|
||||||
preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
|
preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
|
||||||
$categories = $categories[1];
|
$categories = $categories[1];
|
||||||
|
|
||||||
@ -372,6 +381,25 @@ class WP_Import {
|
|||||||
}
|
}
|
||||||
wp_set_post_categories($post_id, $post_cats);
|
wp_set_post_categories($post_id, $post_cats);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add tags.
|
||||||
|
if (count($tags) > 0) {
|
||||||
|
$post_tags = array();
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
|
||||||
|
$tag_obj = get_term_by('slug', $slug, 'post_tag');
|
||||||
|
$tag_id = 0;
|
||||||
|
if ( ! empty($tag_obj) )
|
||||||
|
$tag_id = $tag_obj->term_id;
|
||||||
|
if ( $tag_id == 0 ) {
|
||||||
|
$tag = $wpdb->escape($tag);
|
||||||
|
$tag_id = wp_insert_term($tag, 'post_tag');
|
||||||
|
$tag_id = $tag_id['term_id'];
|
||||||
|
}
|
||||||
|
$post_tags[] = $tag_id;
|
||||||
|
}
|
||||||
|
wp_set_post_tags($post_id, $post_tags);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now for comments
|
// Now for comments
|
||||||
|
Loading…
x
Reference in New Issue
Block a user