Ticket #8019: wordpress.php.diff

File wordpress.php.diff, 3.5 KB (added by joostdevalk, 3 years ago)

Patch

  • wordpress.php

     
    508508                preg_match_all('|<wp:comment>(.*?)</wp:comment>|is', $post, $comments); 
    509509                $comments = $comments[1]; 
    510510                $num_comments = 0; 
    511                 if ( $comments) { foreach ($comments as $comment) { 
    512                         $comment_author       = $this->get_tag( $comment, 'wp:comment_author'); 
    513                         $comment_author_email = $this->get_tag( $comment, 'wp:comment_author_email'); 
    514                         $comment_author_IP    = $this->get_tag( $comment, 'wp:comment_author_IP'); 
    515                         $comment_author_url   = $this->get_tag( $comment, 'wp:comment_author_url'); 
    516                         $comment_date         = $this->get_tag( $comment, 'wp:comment_date'); 
    517                         $comment_date_gmt     = $this->get_tag( $comment, 'wp:comment_date_gmt'); 
    518                         $comment_content      = $this->get_tag( $comment, 'wp:comment_content'); 
    519                         $comment_approved     = $this->get_tag( $comment, 'wp:comment_approved'); 
    520                         $comment_type         = $this->get_tag( $comment, 'wp:comment_type'); 
    521                         $comment_parent       = $this->get_tag( $comment, 'wp:comment_parent'); 
    522  
    523                         // if this is a new post we can skip the comment_exists() check 
    524                         if ( !$post_exists || !comment_exists($comment_author, $comment_date) ) { 
    525                                 $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'); 
    526                                 wp_insert_comment($commentdata); 
    527                                 $num_comments++; 
     511                $inserted_comments = array(); 
     512                if ( $comments) {  
     513                        foreach ($comments as $comment) { 
     514                                $comment_id     = $this->get_tag( $comment, 'wp:comment_id'); 
     515                                $newcomments[$comment_id]['comment_post_ID']      = $comment_post_ID; 
     516                                $newcomments[$comment_id]['comment_author']       = $this->get_tag( $comment, 'wp:comment_author'); 
     517                                $newcomments[$comment_id]['comment_author_email'] = $this->get_tag( $comment, 'wp:comment_author_email'); 
     518                                $newcomments[$comment_id]['comment_author_IP']    = $this->get_tag( $comment, 'wp:comment_author_IP'); 
     519                                $newcomments[$comment_id]['comment_author_url']   = $this->get_tag( $comment, 'wp:comment_author_url'); 
     520                                $newcomments[$comment_id]['comment_date']         = $this->get_tag( $comment, 'wp:comment_date'); 
     521                                $newcomments[$comment_id]['comment_date_gmt']     = $this->get_tag( $comment, 'wp:comment_date_gmt'); 
     522                                $newcomments[$comment_id]['comment_content']      = $this->get_tag( $comment, 'wp:comment_content'); 
     523                                $newcomments[$comment_id]['comment_approved']     = $this->get_tag( $comment, 'wp:comment_approved'); 
     524                                $newcomments[$comment_id]['comment_type']         = $this->get_tag( $comment, 'wp:comment_type'); 
     525                                $newcomments[$comment_id]['comment_parent']       = $this->get_tag( $comment, 'wp:comment_parent'); 
    528526                        } 
    529                 } } 
     527                        // Sort by comment ID, to make sure comment parents exist (if there at all) 
     528                        ksort($newcomments); 
     529                        foreach ($newcomments as $key => $comment) { 
     530                                // if this is a new post we can skip the comment_exists() check 
     531                                if ( !$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date']) ) { 
     532                                        if (isset($inserted_comments[$comment['comment_parent']])) 
     533                                                $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']]; 
     534                                        $inserted_comments[$key] = wp_insert_comment($comment); 
     535                                        $num_comments++; 
     536                                } 
     537                        }  
     538                } 
    530539 
    531540                if ( $num_comments ) 
    532541                        printf(' '._n('(%s comment)', '(%s comments)', $num_comments), $num_comments);