Make WordPress Core

Ticket #16894: 16894.2.diff

File 16894.2.diff, 1.6 KB (added by wonderboymusic, 9 years ago)
  • src/wp-includes/comment-functions.php

     
    451451 *  is true.
    452452 */
    453453function get_comment_meta($comment_id, $key = '', $single = false) {
     454        global $in_comment_loop;
     455
     456        if ( $in_comment_loop ) {
     457                update_comment_meta_cache();
     458        }
     459
    454460        return get_metadata('comment', $comment_id, $key, $single);
    455461}
    456462
    457463/**
     464 * Update cache for comment meta in the current comment loop
     465 *
     466 * @since 4.4.0
     467 *
     468 * @param object $wp_query Optional. A WP_Query instance. Defaults to the $wp_query global.
     469 */
     470function update_comment_meta_cache( $wp_query = null ) {
     471        if ( ! $wp_query ) {
     472                $wp_query = $GLOBALS['wp_query'];
     473        }
     474
     475        if ( $wp_query->comment_meta_cached ) {
     476                return;
     477        }
     478
     479        $comment_ids = wp_list_pluck( $wp_query->comments, 'comment_ID' );
     480
     481        update_meta_cache( 'comment', $comment_ids );
     482
     483        $wp_query->comment_meta_cached = true;
     484}
     485
     486/**
    458487 * Update comment meta field based on comment ID.
    459488 *
    460489 * Use the $prev_value parameter to differentiate between meta fields with the
  • src/wp-includes/query.php

     
    12931293         public $thumbnails_cached = false;
    12941294
    12951295        /**
     1296         * Set if comment meta has already been cached
     1297         *
     1298         * @since 4.4.0
     1299         * @access public
     1300         * @var bool
     1301         */
     1302         public $comment_meta_cached = false;
     1303
     1304        /**
    12961305         * Cached list of search stopwords.
    12971306         *
    12981307         * @since 3.7.0