Improve lazyloading of comment meta in WP_Query loops.

Lazy-loading logic is moved to a method on `WP_Query`. This makes it possible
for comment feeds to take advantage of metadata lazyloading, in addition to
comments loaded via `comments_template()`.

This new technique parallels the termmeta lazyloading technique introduced in
[34704].

Fixes #34047.

git-svn-id: https://develop.svn.wordpress.org/trunk@34711 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2015-09-30 01:34:54 +00:00
parent 686ef2bd79
commit 283c38c022
5 changed files with 151 additions and 25 deletions

View File

@@ -1320,6 +1320,10 @@ function comments_template( $file = '/comments.php', $separate_comments = false
* @param int $post_ID Post ID.
*/
$wp_query->comments = apply_filters( 'comments_array', $comments_flat, $post->ID );
// Set up lazy-loading for comment metadata.
add_action( 'get_comment_metadata', array( $wp_query, 'lazyload_comment_meta' ), 10, 2 );
$comments = &$wp_query->comments;
$wp_query->comment_count = count($wp_query->comments);
$wp_query->max_num_comment_pages = $comment_query->max_num_pages;