Index: parsers.php
===================================================================
--- parsers.php (revision 316385)
+++ parsers.php (working copy)
@@ -42,7 +42,6 @@
echo '
' . __( 'There was an error when reading this WXR file', 'wordpress-importer' ) . '
';
echo __( 'Details are shown above. The importer will now try again with a different parser...', 'wordpress-importer' ) . '
';
}
-
// use regular expressions if nothing else available or this is bad XML
$parser = new WXR_Parser_Regex;
return $parser->parse( $file );
@@ -174,6 +173,15 @@
}
foreach ( $wp->comment as $comment ) {
+ if(isset($comment->comment_meta)) {
+ $comment_meta = array();
+ foreach ( $comment->comment_meta as $cmeta ) {
+ $comment_meta[] = array(
+ 'key' => (string) $cmeta->c_meta_key,
+ 'value' => (string) $cmeta->c_meta_value,
+ );
+ }
+ }
$post['comments'][] = array(
'comment_id' => (int) $comment->comment_id,
'comment_author' => (string) $comment->comment_author,
@@ -187,6 +195,7 @@
'comment_type' => (string) $comment->comment_type,
'comment_parent' => (string) $comment->comment_parent,
'comment_user_id' => (int) $comment->comment_user_id,
+ 'comment_meta' => $comment_meta
);
}
@@ -214,7 +223,7 @@
'wp:is_sticky', 'wp:term_id', 'wp:category_nicename', 'wp:category_parent', 'wp:cat_name', 'wp:category_description',
'wp:tag_slug', 'wp:tag_name', 'wp:tag_description', 'wp:term_taxonomy', 'wp:term_parent',
'wp:term_name', 'wp:term_description', 'wp:author_login', 'wp:author_email', 'wp:author_display_name',
- 'wp:author_first_name', 'wp:author_last_name',
+ 'wp:author_first_name', 'wp:author_last_name','wp:comment_meta'
);
var $wp_sub_tags = array(
'wp:comment_id', 'wp:comment_author', 'wp:comment_author_email', 'wp:comment_author_url',
@@ -224,7 +233,7 @@
function parse( $file ) {
$this->is_wxr_file = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = false;
- $this->authors = $this->posts = $this->term = $this->category = $this->tag = array();
+ $this->authors = $this->posts = $this->term = $this->category = $this->tag = $this->c_meta = array();
$xml = xml_parser_create( 'UTF-8' );
xml_parser_set_option( $xml, XML_OPTION_SKIP_WHITE, 1 );
@@ -312,6 +321,17 @@
$this->data['postmeta'][] = $this->sub_data;
$this->sub_data = false;
break;
+ case 'wp:comment_meta':
+ if ( ! empty( $this->sub_data ) && ! empty( $this->c_meta ) )
+ $this->sub_data['comment_meta'][] = $this->c_meta;
+ $this->c_meta = false;
+ break;
+ case 'wp:c_meta_key' :
+ $this->c_meta['key'] = !empty($this->cdata) ? $this->cdata : false;
+ break;
+ case 'wp:c_meta_value' :
+ $this->c_meta['value'] = !empty($this->cdata) ? $this->cdata : false;
+ break;
case 'item':
$this->posts[] = $this->data;
$this->data = false;
@@ -534,6 +554,16 @@
$comments = $comments[1];
if ( $comments ) {
foreach ( $comments as $comment ) {
+ preg_match_all( '|(.+?)|is', $comment, $commentmeta );
+ $commentmeta = $commentmeta[1];
+ if ( $commentmeta ) {
+ foreach ( $commentmeta as $c ) {
+ $comment_meta[] = array(
+ 'key' => $this->get_tag( $c, 'wp:c_meta_key' ),
+ 'value' => $this->get_tag( $c, 'wp:c_meta_value' ),
+ );
+ }
+ }
$post_comments[] = array(
'comment_id' => $this->get_tag( $comment, 'wp:comment_id' ),
'comment_author' => $this->get_tag( $comment, 'wp:comment_author' ),
@@ -546,6 +576,7 @@
'comment_approved' => $this->get_tag( $comment, 'wp:comment_approved' ),
'comment_type' => $this->get_tag( $comment, 'wp:comment_type' ),
'comment_parent' => $this->get_tag( $comment, 'wp:comment_parent' ),
+ 'comment_meta' => $comment_meta
);
}
}
Index: wordpress-importer.php
===================================================================
--- wordpress-importer.php (revision 316385)
+++ wordpress-importer.php (working copy)
@@ -574,19 +574,32 @@
$newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
$newcomments[$comment_id]['comment_type'] = ! empty( $comment['comment_type'] ) ? $comment['comment_type'] : 'comment';
$newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
+ $newcomments[$comment_id]['comment_meta'] = $comment['comment_meta'];
}
ksort( $newcomments );
foreach ( $newcomments as $key => $comment ) {
// if this is a new post we can skip the comment_exists() check
if ( ! $post_exists || ! comment_exists( $comment['comment_author'], $comment['comment_date'] ) ) {
if ( isset( $inserted_comments[$comment['comment_parent']] ) )
$comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
$comment = wp_filter_comment( $comment );
$inserted_comments[$key] = wp_insert_comment( $comment );
+ // add/update comment meta
+ if ( isset( $comment['comment_meta'] ) ) {
+ foreach ( $comment['comment_meta'] as $cmeta ) {
+ $meta_key = apply_filters( 'import_comment_meta_key', $cmeta['key'] );
+ if ( $meta_key ) {
+ // export gets meta straight from the DB so could have a serialized string
+ $value = maybe_unserialize( $cmeta['value'] );
+ update_comment_meta($inserted_comments[$key], $meta_key, $value );
+ do_action( 'import_comment_meta', $inserted_comments[$key], $meta_key, $value );
+ }
+ }
+ }
$num_comments++;
}
- }
+ }
unset( $newcomments, $inserted_comments, $post['comments'] );
}