WordPress.org

Make WordPress Core

Ticket #33723: 33723.diff

File 33723.diff, 3.8 KB (added by swissspidy, 6 years ago)
  • src/wp-includes/post-thumbnail-template.php

    diff --git src/wp-includes/post-thumbnail-template.php src/wp-includes/post-thumbnail-template.php
    index 7b8d1a2..c6bd8b8 100644
     
    1313 * Check if post has an image attached.
    1414 *
    1515 * @since 2.9.0
     16 * @since 4.4.0 Added the ability to pass a post object to `$post`.
    1617 *
    17  * @param int $post_id Optional. Post ID.
     18 * @param int|WP_Post $post Optional. Post ID or post object.
    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/**
    2526 * Retrieve Post Thumbnail ID.
    2627 *
    2728 * @since 2.9.0
     29 * @since 4.4.0 Added the ability to pass a post object to `$post`.
    2830 *
    29  * @param int|null $post_id Optional. Post ID.
     31 * @param int|null|WP_Post $post Optional. Post ID or object
    3032 * @return mixed
    3133 */
    32 function get_post_thumbnail_id( $post_id = null ) {
    33         $post_id = ( null === $post_id ) ? get_the_ID() : $post_id;
     34function get_post_thumbnail_id( $post = null ) {
     35        $post = get_post( $post );
     36        $post_id = is_a( $post, 'WP_Post' ) ? $post->ID : null;
    3437        return get_post_meta( $post_id, '_thumbnail_id', true );
    3538}
    3639
    function update_post_thumbnail_cache( $wp_query = null ) { 
    9699 * size is used by default, though a different size can be specified instead as needed.
    97100 *
    98101 * @since 2.9.0
     102 * @since 4.4.0 Added the ability to pass a post object to `$post`.
    99103 *
    100  * @param int $post_id       Post ID. Default is the ID of the `$post` global.
     104 * @param int $post          Post ID or post object. Default to the current post.
    101105 * @param string|array $size Optional. Registered image size to use, or flat array of height
    102106 *                           and width values. Default 'post-thumbnail'.
    103107 * @param string|array $attr Optional. Query string or array of attributes. Default empty.
    104108 * @return string
    105109 */
    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 );
     110function get_the_post_thumbnail( $post = null, $size = 'post-thumbnail', $attr = '' ) {
     111        $post = get_post( $post );
     112        $post_thumbnail_id = get_post_thumbnail_id( $post );
    109113
    110114        /**
    111115         * Filter the post thumbnail size.
    function get_the_post_thumbnail( $post_id = null, $size = 'post-thumbnail', $att 
    129133                 * @param string $post_thumbnail_id The post thumbnail ID.
    130134                 * @param string $size              The post thumbnail size.
    131135                 */
    132                 do_action( 'begin_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size );
     136                do_action( 'begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size );
    133137                if ( in_the_loop() )
    134138                        update_post_thumbnail_cache();
    135139                $html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr );
    function get_the_post_thumbnail( $post_id = null, $size = 'post-thumbnail', $att 
    143147                 * @param string $post_thumbnail_id The post thumbnail ID.
    144148                 * @param string $size              The post thumbnail size.
    145149                 */
    146                 do_action( 'end_fetch_post_thumbnail_html', $post_id, $post_thumbnail_id, $size );
     150                do_action( 'end_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size );
    147151
    148152        } else {
    149153                $html = '';
    function get_the_post_thumbnail( $post_id = null, $size = 'post-thumbnail', $att 
    159163         * @param string $size              The post thumbnail size.
    160164         * @param string $attr              Query string of attributes.
    161165         */
    162         return apply_filters( 'post_thumbnail_html', $html, $post_id, $post_thumbnail_id, $size, $attr );
     166        return apply_filters( 'post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr );
    163167}