WordPress.org

Make WordPress Core

Changeset 47160


Ignore:
Timestamp:
02/02/2020 03:06:31 AM (5 months ago)
Author:
SergeyBiryukov
Message:

Post Thumbnails: Make sure get_post_thumbnail_id() returns an integer, to match the documented return value.

This makes the function more consistent with get_the_ID() or wp_get_post_parent_id(), both returning an integer.

Props 0v3rth3d4wn.
Fixes #40096.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post-thumbnail-template.php

    r45739 r47160  
    4646 *
    4747 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
    48  * @return string|int Post thumbnail ID or empty string.
     48 * @return int|string Post thumbnail ID or empty string if the post does not exist.
    4949 */
    5050function get_post_thumbnail_id( $post = null ) {
     
    5353        return '';
    5454    }
    55     return get_post_meta( $post->ID, '_thumbnail_id', true );
     55    return (int) get_post_meta( $post->ID, '_thumbnail_id', true );
    5656}
    5757
  • trunk/tests/phpunit/tests/customize/manager.php

    r47122 r47160  
    712712        $this->assertEquals( '', get_page_template_slug( $posts_by_name['blog'] ) );
    713713        $this->assertEquals( $posts_by_name['waffles'], get_post_thumbnail_id( $posts_by_name['custom'] ) );
    714         $this->assertEquals( '', get_post_thumbnail_id( $posts_by_name['blog'] ) );
     714        $this->assertEquals( 0, get_post_thumbnail_id( $posts_by_name['blog'] ) );
    715715        $attachment_metadata = wp_get_attachment_metadata( $posts_by_name['waffles'] );
    716716        $this->assertEquals( 'Waffles', get_post( $posts_by_name['waffles'] )->post_title );
Note: See TracChangeset for help on using the changeset viewer.