WordPress.org

Make WordPress Core

Ticket #33723: 33723.patch

File 33723.patch, 4.9 KB (added by Rahe, 6 years ago)
  • wp-includes/post-thumbnail-template.php

    diff --git i/wp-includes/post-thumbnail-template.php w/wp-includes/post-thumbnail-template.php
    index 7b8d1a2..624d913 100644
    i w  
    1414 *
    1515 * @since 2.9.0
    1616 *
    17  * @param int $post_id Optional. Post ID.
     17 * @param int|WP_Post $post Optional. Post ID or WP_Post
     18 *
    1819 * @return bool Whether post has an image attached.
    1920 */
    20 function has_post_thumbnail( $post_id = null ) {
    21         return (bool) get_post_thumbnail_id( $post_id );
     21function has_post_thumbnail( $post = null ) {
     22        return (bool) get_post_thumbnail_id( $post );
    2223}
    2324
    2425/**
    function has_post_thumbnail( $post_id = null ) { 
    2627 *
    2728 * @since 2.9.0
    2829 *
    29  * @param int|null $post_id Optional. Post ID.
     30 * @param int|null|WP_Post $post Optional. Post ID or WP_Post
     31 *
    3032 * @return mixed
    3133 */
    32 function get_post_thumbnail_id( $post_id = null ) {
    33         $post_id = ( null === $post_id ) ? get_the_ID() : $post_id;
    34         return get_post_meta( $post_id, '_thumbnail_id', true );
     34function get_post_thumbnail_id( $post = null ) {
     35        $post = get_post( $post );
     36        return get_post_meta( $post->ID, '_thumbnail_id', true );
    3537}
    3638
    3739/**
    function the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ) { 
    6668 * @param WP_Query $wp_query Optional. A WP_Query instance. Defaults to the $wp_query global.
    6769 */
    6870function update_post_thumbnail_cache( $wp_query = null ) {
    69         if ( ! $wp_query )
     71        if ( ! $wp_query ) {
    7072                $wp_query = $GLOBALS['wp_query'];
     73        }
    7174
    72         if ( $wp_query->thumbnails_cached )
     75        if ( $wp_query->thumbnails_cached ) {
    7376                return;
     77        }
    7478
    7579        $thumb_ids = array();
    7680        foreach ( $wp_query->posts as $post ) {
    77                 if ( $id = get_post_thumbnail_id( $post->ID ) )
     81                if ( $id = get_post_thumbnail_id( $post->ID ) ) {
    7882                        $thumb_ids[] = $id;
     83                }
    7984        }
    8085
    8186        if ( ! empty ( $thumb_ids ) ) {
    function update_post_thumbnail_cache( $wp_query = null ) { 
    97102 *
    98103 * @since 2.9.0
    99104 *
    100  * @param int $post_id       Post ID. Default is the ID of the `$post` global.
     105 * @param int|null|WP_Post $post Post ID or WP Post. Default is the ID of the `$post` global.
    101106 * @param string|array $size Optional. Registered image size to use, or flat array of height
    102107 *                           and width values. Default 'post-thumbnail'.
    103108 * @param string|array $attr Optional. Query string or array of attributes. Default empty.
     109 *
    104110 * @return string
    105111 */
    106 function get_the_post_thumbnail( $post_id = null, $size = 'post-thumbnail', $attr = '' ) {
    107         $post_id = ( null === $post_id ) ? get_the_ID() : $post_id;
    108         $post_thumbnail_id = get_post_thumbnail_id( $post_id );
     112function get_the_post_thumbnail( $post = null, $size = 'post-thumbnail', $attr = '' ) {
     113        $post       = get_post( $post );
     114        $post_thumbnail_id = get_post_thumbnail_id( $post );
    109115
    110116        /**
    111117         * Filter the post thumbnail size.
    function get_the_post_thumbnail( $post_id = null, $size = 'post-thumbnail', $att 
    125131                 *
    126132                 * @since 2.9.0
    127133                 *
    128                  * @param string $post_id           The post ID.
     134                 * @param string $post_id The post ID.
    129135                 * @param string $post_thumbnail_id The post thumbnail ID.
    130                  * @param string $size              The post thumbnail size.
     136                 * @param string $size The post thumbnail size.
    131137                 */
    132                 do_action( 'begin_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size );
    133                 if ( in_the_loop() )
     138                do_action( 'begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size );
     139                if ( in_the_loop() ) {
    134140                        update_post_thumbnail_cache();
     141                }
    135142                $html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr );
    136143
    137144                /**
    function get_the_post_thumbnail( $post_id = null, $size = 'post-thumbnail', $att 
    139146                 *
    140147                 * @since 2.9.0
    141148                 *
    142                  * @param string $post_id           The post ID.
     149                 * @param string $post_id The post ID.
    143150                 * @param string $post_thumbnail_id The post thumbnail ID.
    144                  * @param string $size              The post thumbnail size.
     151                 * @param string $size The post thumbnail size.
    145152                 */
    146                 do_action( 'end_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size );
     153                do_action( 'end_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size );
    147154
    148155        } else {
    149156                $html = '';
    150157        }
     158
    151159        /**
    152160         * Filter the post thumbnail HTML.
    153161         *
    154162         * @since 2.9.0
    155163         *
    156          * @param string $html              The post thumbnail HTML.
    157          * @param string $post_id           The post ID.
     164         * @param string $html The post thumbnail HTML.
     165         * @param string $post_id The post ID.
    158166         * @param string $post_thumbnail_id The post thumbnail ID.
    159          * @param string $size              The post thumbnail size.
    160          * @param string $attr              Query string of attributes.
     167         * @param string $size The post thumbnail size.
     168         * @param string $attr Query string of attributes.
    161169         */
    162         return apply_filters( 'post_thumbnail_html', $html, $post_id, $post_thumbnail_id, $size, $attr );
     170
     171        return apply_filters( 'post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr );
    163172}