Make WordPress Core


Ignore:
Timestamp:
07/05/2020 10:15:40 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Post Thumbnails: Change the return value of get_post_thumbnail_id() for a non-existing post to false instead of an empty string.

This further makes the function more consistent with get_the_ID() or wp_get_post_parent_id(), both returning false for a non-existing post.

Additionally, document that get_post_thumbnail_id() returns 0 if the thumbnail image is not set.

Follow-up to [47160].

Props theMikeD, dingo_d, netpassprodsr, SergeyBiryukov.
Fixes #49832. See #40096.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/thumbnails.php

    r46586 r48310  
    5555
    5656    function test_get_post_thumbnail_id() {
    57         $this->assertEmpty( get_post_thumbnail_id( self::$post ) );
    58         $this->assertEmpty( get_post_thumbnail_id( self::$post->ID ) );
    59         $this->assertEmpty( get_post_thumbnail_id() );
     57        $this->assertSame( 0, get_post_thumbnail_id( self::$post ) );
     58        $this->assertSame( 0, get_post_thumbnail_id( self::$post->ID ) );
     59        $this->assertFalse( get_post_thumbnail_id() );
    6060
    6161        set_post_thumbnail( self::$post, self::$attachment_id );
Note: See TracChangeset for help on using the changeset viewer.