Changeset 34167
- Timestamp:
- 09/15/2015 03:45:23 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post-thumbnail-template.php
r32618 r34167 14 14 * 15 15 * @since 2.9.0 16 * @since 4.4.0 `$post` can be a post ID or WP_Post object. 16 17 * 17 * @param int $post_id Optional. Post ID.18 * @return bool Whether post has an image attached.18 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. 19 * @return bool Whether the post has an image attached. 19 20 */ 20 function has_post_thumbnail( $post _id= null ) {21 return (bool) get_post_thumbnail_id( $post _id);21 function has_post_thumbnail( $post = null ) { 22 return (bool) get_post_thumbnail_id( $post ); 22 23 } 23 24 24 25 /** 25 * Retrieve Post Thumbnail ID.26 * Retrieve post thumbnail ID. 26 27 * 27 28 * @since 2.9.0 29 * @since 4.4.0 `$post` can be a post ID or WP_Post object. 28 30 * 29 * @param int| null $post_id Optional. Post ID.30 * @return mixed31 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. 32 * @return string|int Post thumbnail ID or empty string. 31 33 */ 32 function get_post_thumbnail_id( $post_id = null ) { 33 $post_id = ( null === $post_id ) ? get_the_ID() : $post_id; 34 return get_post_meta( $post_id, '_thumbnail_id', true ); 34 function get_post_thumbnail_id( $post = null ) { 35 $post = get_post( $post ); 36 if ( ! $post ) { 37 return ''; 38 } 39 return get_post_meta( $post->ID, '_thumbnail_id', true ); 35 40 } 36 41 … … 58 63 59 64 /** 60 * Update cache for thumbnails in the current loop 65 * Update cache for thumbnails in the current loop. 61 66 * 62 67 * @since 3.2.0 … … 97 102 * 98 103 * @since 2.9.0 104 * @since 4.4.0 `$post` can be a post ID or WP_Post object. 99 105 * 100 * @param int $post_id Post ID. Default is the ID of the `$post` global.106 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. 101 107 * @param string|array $size Optional. Registered image size to use, or flat array of height 102 108 * and width values. Default 'post-thumbnail'. 103 109 * @param string|array $attr Optional. Query string or array of attributes. Default empty. 104 * @return string 110 * @return string The post thumbnail image tag. 105 111 */ 106 function get_the_post_thumbnail( $post_id = null, $size = 'post-thumbnail', $attr = '' ) { 107 $post_id = ( null === $post_id ) ? get_the_ID() : $post_id; 108 $post_thumbnail_id = get_post_thumbnail_id( $post_id ); 112 function get_the_post_thumbnail( $post = null, $size = 'post-thumbnail', $attr = '' ) { 113 $post = get_post( $post ); 114 if ( ! $post ) { 115 return ''; 116 } 117 $post_thumbnail_id = get_post_thumbnail_id( $post ); 109 118 110 119 /** … … 126 135 * @since 2.9.0 127 136 * 128 * @param string$post_id The post ID.137 * @param int $post_id The post ID. 129 138 * @param string $post_thumbnail_id The post thumbnail ID. 130 139 * @param string $size The post thumbnail size. 131 140 */ 132 do_action( 'begin_fetch_post_thumbnail_html', $post _id, $post_thumbnail_id, $size );141 do_action( 'begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size ); 133 142 if ( in_the_loop() ) 134 143 update_post_thumbnail_cache(); … … 140 149 * @since 2.9.0 141 150 * 142 * @param string$post_id The post ID.151 * @param int $post_id The post ID. 143 152 * @param string $post_thumbnail_id The post thumbnail ID. 144 153 * @param string $size The post thumbnail size. 145 154 */ 146 do_action( 'end_fetch_post_thumbnail_html', $post _id, $post_thumbnail_id, $size );155 do_action( 'end_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size ); 147 156 148 157 } else { … … 155 164 * 156 165 * @param string $html The post thumbnail HTML. 157 * @param string$post_id The post ID.166 * @param int $post_id The post ID. 158 167 * @param string $post_thumbnail_id The post thumbnail ID. 159 168 * @param string $size The post thumbnail size. 160 169 * @param string $attr Query string of attributes. 161 170 */ 162 return apply_filters( 'post_thumbnail_html', $html, $post _id, $post_thumbnail_id, $size, $attr );171 return apply_filters( 'post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr ); 163 172 }
Note: See TracChangeset
for help on using the changeset viewer.