Changeset 48310
- Timestamp:
- 07/05/2020 10:15:40 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post-thumbnail-template.php
r47160 r48310 44 44 * @since 2.9.0 45 45 * @since 4.4.0 `$post` can be a post ID or WP_Post object. 46 * 47 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. 48 * @return int|string Post thumbnail ID or empty string if the post does not exist. 46 * @since 5.5.0 The return value for a non-existing post 47 * was changed to false instead of an empty string. 48 * 49 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. 50 * @return int|false Post thumbnail ID (which can be 0 if the thumbnail is not set), 51 * or false if the post does not exist. 49 52 */ 50 53 function get_post_thumbnail_id( $post = null ) { 51 54 $post = get_post( $post ); 55 52 56 if ( ! $post ) { 53 return ''; 54 } 57 return false; 58 } 59 55 60 return (int) get_post_meta( $post->ID, '_thumbnail_id', true ); 56 61 } … … 98 103 99 104 $thumb_ids = array(); 105 100 106 foreach ( $wp_query->posts as $post ) { 101 107 $id = get_post_thumbnail_id( $post->ID ); … … 134 140 function get_the_post_thumbnail( $post = null, $size = 'post-thumbnail', $attr = '' ) { 135 141 $post = get_post( $post ); 142 136 143 if ( ! $post ) { 137 144 return ''; 138 145 } 146 139 147 $post_thumbnail_id = get_post_thumbnail_id( $post ); 140 148 … … 166 174 */ 167 175 do_action( 'begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size ); 176 168 177 if ( in_the_loop() ) { 169 178 update_post_thumbnail_cache(); 170 179 } 180 171 181 $html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr ); 172 182 … … 186 196 $html = ''; 187 197 } 198 188 199 /** 189 200 * Filters the post thumbnail HTML. … … 213 224 function get_the_post_thumbnail_url( $post = null, $size = 'post-thumbnail' ) { 214 225 $post_thumbnail_id = get_post_thumbnail_id( $post ); 226 215 227 if ( ! $post_thumbnail_id ) { 216 228 return false; 217 229 } 230 218 231 return wp_get_attachment_image_url( $post_thumbnail_id, $size ); 219 232 } … … 230 243 function the_post_thumbnail_url( $size = 'post-thumbnail' ) { 231 244 $url = get_the_post_thumbnail_url( null, $size ); 245 232 246 if ( $url ) { 233 247 echo esc_url( $url ); … … 245 259 function get_the_post_thumbnail_caption( $post = null ) { 246 260 $post_thumbnail_id = get_post_thumbnail_id( $post ); 261 247 262 if ( ! $post_thumbnail_id ) { 248 263 return ''; -
trunk/src/wp-includes/post.php
r48214 r48310 7015 7015 * 7016 7016 * @param int|WP_Post $post Post ID or post object. Defaults to global $post. 7017 * @return int|false Post parent ID (which can be 0 if there is no parent), or false if the post does not exist. 7017 * @return int|false Post parent ID (which can be 0 if there is no parent), 7018 * or false if the post does not exist. 7018 7019 */ 7019 7020 function wp_get_post_parent_id( $post ) { -
trunk/tests/phpunit/tests/post/thumbnails.php
r46586 r48310 55 55 56 56 function test_get_post_thumbnail_id() { 57 $this->assert Empty(get_post_thumbnail_id( self::$post ) );58 $this->assert Empty(get_post_thumbnail_id( self::$post->ID ) );59 $this->assert Empty( 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() ); 60 60 61 61 set_post_thumbnail( self::$post, self::$attachment_id );
Note: See TracChangeset
for help on using the changeset viewer.