WordPress.org

Make WordPress Core

Ticket #15447: 15447.6.diff

File 15447.6.diff, 1.9 KB (added by greuben, 9 years ago)
  • wp-includes/post-thumbnail-template.php

     
    4848}
    4949
    5050/**
     51 * Update cache for thumbnails in the current loop
     52 *
     53 * @sicne 3.2
     54 */
     55function update_post_thumbnail_cache() {
     56        global $wp_query;
     57
     58        if ( $wp_query->thumbnails_cached )
     59                return;
     60
     61        $thumb_ids = array();
     62        foreach ( $wp_query->posts as $post ) {
     63                if ( $id = get_post_thumbnail_id( $post->ID ) )
     64                        $thumb_ids[] = $id;
     65        }
     66
     67        if ( ! empty ( $thumb_ids ) ) {
     68                get_posts( array(
     69                                'update_post_term_cache' => false,
     70                                'include' => $thumb_ids,
     71                                'post_type' => 'attachment',
     72                                'post_status' => 'inherit',
     73                                'nopaging' => true
     74                ) );
     75        }
     76
     77        $wp_query->thumbnails_cached = true;
     78}
     79
     80/**
    5181 * Retrieve Post Thumbnail.
    5282 *
    5383 * @since 2.9.0
     
    6292        $size = apply_filters( 'post_thumbnail_size', $size );
    6393        if ( $post_thumbnail_id ) {
    6494                do_action( 'begin_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size ); // for "Just In Time" filtering of all of wp_get_attachment_image()'s filters
     95                if ( in_the_loop() )
     96                        update_post_thumbnail_cache();
    6597                $html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr );
    6698                do_action( 'end_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size );
    6799        } else {
  • wp-includes/query.php

     
    12581258        var $query_vars_changed = true;
    12591259
    12601260        /**
     1261         * Set if post thumbnails are cached
     1262         *
     1263         * @since 3.2
     1264         * @access public
     1265         * @var bool
     1266         */
     1267         var $thumbnails_cached = false;
     1268
     1269        /**
    12611270         * Resets query flags to false.
    12621271         *
    12631272         * The query flags are what page info WordPress was able to figure out.