diff --git a/src/wp-includes/post-thumbnail-template.php b/src/wp-includes/post-thumbnail-template.php index 8202f4eb6a..85fb0e31d9 100644 --- a/src/wp-includes/post-thumbnail-template.php +++ b/src/wp-includes/post-thumbnail-template.php @@ -45,14 +45,14 @@ function has_post_thumbnail( $post = null ) { * @since 4.4.0 `$post` can be a post ID or WP_Post object. * * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. - * @return string|int Post thumbnail ID or empty string. + * @return int|string Post thumbnail ID or empty string if the post does not exist. */ function get_post_thumbnail_id( $post = null ) { $post = get_post( $post ); if ( ! $post ) { return ''; } - return get_post_meta( $post->ID, '_thumbnail_id', true ); + return (int) get_post_meta( $post->ID, '_thumbnail_id', true ); } /** diff --git a/tests/phpunit/tests/customize/manager.php b/tests/phpunit/tests/customize/manager.php index 34fb866059..2d44bfc406 100644 --- a/tests/phpunit/tests/customize/manager.php +++ b/tests/phpunit/tests/customize/manager.php @@ -711,7 +711,7 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase { $this->assertEquals( 'sample-page-template.php', get_page_template_slug( $posts_by_name['about'] ) ); $this->assertEquals( '', get_page_template_slug( $posts_by_name['blog'] ) ); $this->assertEquals( $posts_by_name['waffles'], get_post_thumbnail_id( $posts_by_name['custom'] ) ); - $this->assertEquals( '', get_post_thumbnail_id( $posts_by_name['blog'] ) ); + $this->assertEquals( 0, get_post_thumbnail_id( $posts_by_name['blog'] ) ); $attachment_metadata = wp_get_attachment_metadata( $posts_by_name['waffles'] ); $this->assertEquals( 'Waffles', get_post( $posts_by_name['waffles'] )->post_title ); $this->assertEquals( 'waffles', get_post_meta( $posts_by_name['waffles'], '_customize_draft_post_name', true ) );