Make WordPress Core

Changes between Version 1 and Version 2 of Ticket #49236, comment 26


Ignore:
Timestamp:
08/04/2020 08:39:39 PM (4 years ago)
Author:
westonruter
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #49236, comment 26

    v1 v2  
    1818So I think I prefer the second alternative you proposed, where `UPDATE` is done followed by `clean_comment_cache()`, although with one adjustment: add a safeguard in the `WHERE` to double-confirm that the `comment_type` is indeed empty. Like so:
    1919
    20 
    2120{{{#!diff
    2221--- a/src/wp-includes/comment.php
     
    3635                        ORDER BY comment_ID DESC
    3736                        LIMIT %d",
    38 @@ -3851,6 +3851,18 @@ function _wp_batch_update_comment_type() {
     37@@ -3851,6 +3851,20 @@ function _wp_batch_update_comment_type() {
    3938                )
    4039        );
    4140 
    42 +       $in_comment_ids = implode( ',', wp_parse_id_list( $comment_ids ) );
     41+       if ( count( $comment_ids ) > 0 ) {
     42+               $in_comment_ids = implode( ',', wp_parse_id_list( $comment_ids ) );
    4343+
    44 +       $wpdb->query(
    45 +               $wpdb->prepare(
    46 +                       "UPDATE {$wpdb->comments}
    47 +                       SET comment_type = 'comment'
    48 +                       WHERE comment_type = '' AND comment_ID IN ({$in_comment_ids})"
    49 +               )
    50 +       );
     44+               $wpdb->query(
     45+                       $wpdb->prepare(
     46+                               "UPDATE {$wpdb->comments}
     47+                               SET comment_type = 'comment'
     48+                               WHERE comment_type = '' AND comment_ID IN ({$in_comment_ids})"
     49+                       )
     50+               );
    5151+
    52 +       clean_comment_cache( $comment_ids );
     52+               clean_comment_cache( $comment_ids );
     53+       }
    5354+
    5455        delete_option( $lock_name );