Preserve parentage when importing comments. Props joostdevalk. fixes #8019
git-svn-id: http://svn.automattic.com/wordpress/trunk@12301 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
96c363a384
commit
bfd934032c
|
@ -559,26 +559,35 @@ class WP_Import {
|
||||||
preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments);
|
preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments);
|
||||||
$comments = $comments[1];
|
$comments = $comments[1];
|
||||||
$num_comments = 0;
|
$num_comments = 0;
|
||||||
if ( $comments) { foreach ($comments as $comment) {
|
$inserted_comments = array();
|
||||||
$comment_author = $this->get_tag( $comment, 'wp:comment_author');
|
if ( $comments) {
|
||||||
$comment_author_email = $this->get_tag( $comment, 'wp:comment_author_email');
|
foreach ($comments as $comment) {
|
||||||
$comment_author_IP = $this->get_tag( $comment, 'wp:comment_author_IP');
|
$comment_id = $this->get_tag( $comment, 'wp:comment_id');
|
||||||
$comment_author_url = $this->get_tag( $comment, 'wp:comment_author_url');
|
$newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
|
||||||
$comment_date = $this->get_tag( $comment, 'wp:comment_date');
|
$newcomments[$comment_id]['comment_author'] = $this->get_tag( $comment, 'wp:comment_author');
|
||||||
$comment_date_gmt = $this->get_tag( $comment, 'wp:comment_date_gmt');
|
$newcomments[$comment_id]['comment_author_email'] = $this->get_tag( $comment, 'wp:comment_author_email');
|
||||||
$comment_content = $this->get_tag( $comment, 'wp:comment_content');
|
$newcomments[$comment_id]['comment_author_IP'] = $this->get_tag( $comment, 'wp:comment_author_IP');
|
||||||
$comment_approved = $this->get_tag( $comment, 'wp:comment_approved');
|
$newcomments[$comment_id]['comment_author_url'] = $this->get_tag( $comment, 'wp:comment_author_url');
|
||||||
$comment_type = $this->get_tag( $comment, 'wp:comment_type');
|
$newcomments[$comment_id]['comment_date'] = $this->get_tag( $comment, 'wp:comment_date');
|
||||||
$comment_parent = $this->get_tag( $comment, 'wp:comment_parent');
|
$newcomments[$comment_id]['comment_date_gmt'] = $this->get_tag( $comment, 'wp:comment_date_gmt');
|
||||||
|
$newcomments[$comment_id]['comment_content'] = $this->get_tag( $comment, 'wp:comment_content');
|
||||||
// if this is a new post we can skip the comment_exists() check
|
$newcomments[$comment_id]['comment_approved'] = $this->get_tag( $comment, 'wp:comment_approved');
|
||||||
if ( !$post_exists || !comment_exists($comment_author, $comment_date) ) {
|
$newcomments[$comment_id]['comment_type'] = $this->get_tag( $comment, 'wp:comment_type');
|
||||||
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_approved', 'comment_type', 'comment_parent');
|
$newcomments[$comment_id]['comment_parent'] = $this->get_tag( $comment, 'wp:comment_parent');
|
||||||
$commentdata = wp_filter_comment($commentdata);
|
|
||||||
wp_insert_comment($commentdata);
|
|
||||||
$num_comments++;
|
|
||||||
}
|
}
|
||||||
} }
|
// Sort by comment ID, to make sure comment parents exist (if there at all)
|
||||||
|
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);
|
||||||
|
$num_comments++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( $num_comments )
|
if ( $num_comments )
|
||||||
printf(' '._n('(%s comment)', '(%s comments)', $num_comments), $num_comments);
|
printf(' '._n('(%s comment)', '(%s comments)', $num_comments), $num_comments);
|
||||||
|
|
Loading…
Reference in New Issue