WordPress.org

Make WordPress Core

Ticket #16894: 16894.4.diff

File 16894.4.diff, 2.2 KB (added by boonebgorges, 4 years ago)
  • src/wp-includes/class-wp-comment-query.php

    diff --git src/wp-includes/class-wp-comment-query.php src/wp-includes/class-wp-comment-query.php
    index ec35a2a..b7f210a 100644
    class WP_Comment_Query { 
    161161         *     @type array        $type__in            Include comments from a given array of comment types. Default empty.
    162162         *     @type array        $type__not_in        Exclude comments from a given array of comment types. Default empty.
    163163         *     @type int          $user_id             Include comments for a specific user ID. Default empty.
     164         *     @type bool         $update_comment_meta_cache Whether to prime the metadata cache for found comments.
     165         *                                                   Default: true.
    164166         * }
    165167         */
    166168        public function __construct( $query = '' ) {
    class WP_Comment_Query { 
    201203                        'meta_value' => '',
    202204                        'meta_query' => '',
    203205                        'date_query' => null, // See WP_Date_Query
     206                        'update_comment_meta_cache' => true,
    204207                );
    205208
    206209                if ( ! empty( $query ) ) {
    class WP_Comment_Query { 
    698701
    699702                wp_cache_add( $cache_key, $comments, 'comment' );
    700703                if ( '*' === $fields ) {
    701                         update_comment_cache( $comments );
     704                        update_comment_cache( $comments, $this->query_vars['update_comment_meta_cache'] );
    702705                }
    703706
    704707                $this->comments = $comments;
  • src/wp-includes/comment-functions.php

    diff --git src/wp-includes/comment-functions.php src/wp-includes/comment-functions.php
    index 08ddfd2..eeb4499 100644
    function clean_comment_cache($ids) { 
    23572357 * cache using the comment group with the key using the ID of the comments.
    23582358 *
    23592359 * @since 2.3.0
     2360 * @since 4.4.0 Introduced the `$update_meta_cache` parameter.
    23602361 *
    23612362 * @param array $comments Array of comment row objects
    23622363 */
    2363 function update_comment_cache($comments) {
     2364function update_comment_cache( $comments, $update_meta_cache = true ) {
    23642365        foreach ( (array) $comments as $comment )
    23652366                wp_cache_add($comment->comment_ID, $comment, 'comment');
     2367
     2368        if ( $update_meta_cache ) {
     2369                $comment_ids = wp_list_pluck( $comments, 'comment_ID' );
     2370                update_meta_cache( 'comment', $comment_ids );
     2371        }
    23662372}
    23672373
    23682374//