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. git-svn-id: https://develop.svn.wordpress.org/trunk@47160 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
139fe26f1f
commit
fd3083e3f5
@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 ) );
|
||||
|
Loading…
Reference in New Issue
Block a user