author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:28:13 +0200 | |
changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Post Thumbnail Template Functions. |
|
4 |
* |
|
5 | 5 |
* Support for post thumbnails. |
6 |
* Theme's functions.php must call add_theme_support( 'post-thumbnails' ) to use these. |
|
0 | 7 |
* |
8 |
* @package WordPress |
|
9 |
* @subpackage Template |
|
10 |
*/ |
|
11 |
||
12 |
/** |
|
9 | 13 |
* Determines whether a post has an image attached. |
14 |
* |
|
15 |
* For more information on this and similar theme functions, check out |
|
16 |
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ |
|
17 |
* Conditional Tags} article in the Theme Developer Handbook. |
|
0 | 18 |
* |
19 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* @since 4.4.0 `$post` can be a post ID or WP_Post object. |
0 | 21 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* @return bool Whether the post has an image attached. |
0 | 24 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
function has_post_thumbnail( $post = null ) { |
9 | 26 |
$thumbnail_id = get_post_thumbnail_id( $post ); |
27 |
$has_thumbnail = (bool) $thumbnail_id; |
|
28 |
||
29 |
/** |
|
30 |
* Filters whether a post has a post thumbnail. |
|
31 |
* |
|
32 |
* @since 5.1.0 |
|
33 |
* |
|
34 |
* @param bool $has_thumbnail true if the post has a post thumbnail, otherwise false. |
|
35 |
* @param int|WP_Post|null $post Post ID or WP_Post object. Default is global `$post`. |
|
36 |
* @param int|string $thumbnail_id Post thumbnail ID or empty string. |
|
37 |
*/ |
|
38 |
return (bool) apply_filters( 'has_post_thumbnail', $has_thumbnail, $post, $thumbnail_id ); |
|
0 | 39 |
} |
40 |
||
41 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
* Retrieve post thumbnail ID. |
0 | 43 |
* |
44 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
* @since 4.4.0 `$post` can be a post ID or WP_Post object. |
0 | 46 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
* @return string|int Post thumbnail ID or empty string. |
0 | 49 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
function get_post_thumbnail_id( $post = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
$post = get_post( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
53 |
return ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
return get_post_meta( $post->ID, '_thumbnail_id', true ); |
0 | 56 |
} |
57 |
||
58 |
/** |
|
5 | 59 |
* Display the post thumbnail. |
60 |
* |
|
61 |
* When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' image size |
|
62 |
* is registered, which differs from the 'thumbnail' image size managed via the |
|
63 |
* Settings > Media screen. |
|
64 |
* |
|
65 |
* When using the_post_thumbnail() or related functions, the 'post-thumbnail' image |
|
66 |
* size is used by default, though a different size can be specified instead as needed. |
|
0 | 67 |
* |
68 |
* @since 2.9.0 |
|
69 |
* |
|
5 | 70 |
* @see get_the_post_thumbnail() |
71 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
* @param string|array $size Optional. Image size to use. Accepts any valid image size, or |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
* an array of width and height values in pixels (in that order). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
* Default 'post-thumbnail'. |
5 | 75 |
* @param string|array $attr Optional. Query string or array of attributes. Default empty. |
0 | 76 |
*/ |
77 |
function the_post_thumbnail( $size = 'post-thumbnail', $attr = '' ) { |
|
78 |
echo get_the_post_thumbnail( null, $size, $attr ); |
|
79 |
} |
|
80 |
||
81 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
* Update cache for thumbnails in the current loop. |
0 | 83 |
* |
5 | 84 |
* @since 3.2.0 |
0 | 85 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
* @global WP_Query $wp_query |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
* @param WP_Query $wp_query Optional. A WP_Query instance. Defaults to the $wp_query global. |
0 | 89 |
*/ |
90 |
function update_post_thumbnail_cache( $wp_query = null ) { |
|
9 | 91 |
if ( ! $wp_query ) { |
0 | 92 |
$wp_query = $GLOBALS['wp_query']; |
9 | 93 |
} |
0 | 94 |
|
9 | 95 |
if ( $wp_query->thumbnails_cached ) { |
0 | 96 |
return; |
9 | 97 |
} |
0 | 98 |
|
99 |
$thumb_ids = array(); |
|
100 |
foreach ( $wp_query->posts as $post ) { |
|
9 | 101 |
if ( $id = get_post_thumbnail_id( $post->ID ) ) { |
0 | 102 |
$thumb_ids[] = $id; |
9 | 103 |
} |
0 | 104 |
} |
105 |
||
9 | 106 |
if ( ! empty( $thumb_ids ) ) { |
0 | 107 |
_prime_post_caches( $thumb_ids, false, true ); |
108 |
} |
|
109 |
||
110 |
$wp_query->thumbnails_cached = true; |
|
111 |
} |
|
112 |
||
113 |
/** |
|
5 | 114 |
* Retrieve the post thumbnail. |
115 |
* |
|
116 |
* When a theme adds 'post-thumbnail' support, a special 'post-thumbnail' image size |
|
117 |
* is registered, which differs from the 'thumbnail' image size managed via the |
|
118 |
* Settings > Media screen. |
|
119 |
* |
|
120 |
* When using the_post_thumbnail() or related functions, the 'post-thumbnail' image |
|
121 |
* size is used by default, though a different size can be specified instead as needed. |
|
0 | 122 |
* |
123 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
* @since 4.4.0 `$post` can be a post ID or WP_Post object. |
0 | 125 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
126 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
* @param string|array $size Optional. Image size to use. Accepts any valid image size, or |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
* an array of width and height values in pixels (in that order). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
* Default 'post-thumbnail'. |
5 | 130 |
* @param string|array $attr Optional. Query string or array of attributes. Default empty. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
* @return string The post thumbnail image tag. |
0 | 132 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
function get_the_post_thumbnail( $post = null, $size = 'post-thumbnail', $attr = '' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
$post = get_post( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
if ( ! $post ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
return ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
$post_thumbnail_id = get_post_thumbnail_id( $post ); |
0 | 139 |
|
140 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
* Filters the post thumbnail size. |
0 | 142 |
* |
143 |
* @since 2.9.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
* @since 4.9.0 Added the `$post_id` parameter. |
0 | 145 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
* @param string|array $size The post thumbnail size. Image size or array of width and height |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
147 |
* values (in that order). Default 'post-thumbnail'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
* @param int $post_id The post ID. |
0 | 149 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
$size = apply_filters( 'post_thumbnail_size', $size, $post->ID ); |
0 | 151 |
|
152 |
if ( $post_thumbnail_id ) { |
|
153 |
||
154 |
/** |
|
155 |
* Fires before fetching the post thumbnail HTML. |
|
156 |
* |
|
157 |
* Provides "just in time" filtering of all filters in wp_get_attachment_image(). |
|
158 |
* |
|
159 |
* @since 2.9.0 |
|
160 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
* @param int $post_id The post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
* @param string $post_thumbnail_id The post thumbnail ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
* @param string|array $size The post thumbnail size. Image size or array of width |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
164 |
* and height values (in that order). Default 'post-thumbnail'. |
0 | 165 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
166 |
do_action( 'begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size ); |
9 | 167 |
if ( in_the_loop() ) { |
0 | 168 |
update_post_thumbnail_cache(); |
9 | 169 |
} |
0 | 170 |
$html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr ); |
171 |
||
172 |
/** |
|
173 |
* Fires after fetching the post thumbnail HTML. |
|
174 |
* |
|
175 |
* @since 2.9.0 |
|
176 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
* @param int $post_id The post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
* @param string $post_thumbnail_id The post thumbnail ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
* @param string|array $size The post thumbnail size. Image size or array of width |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
* and height values (in that order). Default 'post-thumbnail'. |
0 | 181 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
do_action( 'end_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size ); |
0 | 183 |
|
184 |
} else { |
|
185 |
$html = ''; |
|
186 |
} |
|
187 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
* Filters the post thumbnail HTML. |
0 | 189 |
* |
190 |
* @since 2.9.0 |
|
191 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
* @param string $html The post thumbnail HTML. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
* @param int $post_id The post ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
* @param string $post_thumbnail_id The post thumbnail ID. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
195 |
* @param string|array $size The post thumbnail size. Image size or array of width and height |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
196 |
* values (in that order). Default 'post-thumbnail'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
* @param string $attr Query string of attributes. |
0 | 198 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
return apply_filters( 'post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
200 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
201 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
* Return the post thumbnail URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
205 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
208 |
* @param string|array $size Optional. Registered image size to retrieve the source for or a flat |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
209 |
* array of height and width dimensions. Default 'post-thumbnail'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
* @return string|false Post thumbnail URL or false if no URL is available. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
function get_the_post_thumbnail_url( $post = null, $size = 'post-thumbnail' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
$post_thumbnail_id = get_post_thumbnail_id( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
if ( ! $post_thumbnail_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
215 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
return wp_get_attachment_image_url( $post_thumbnail_id, $size ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
220 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
* Display the post thumbnail URL. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
224 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
* @param string|array $size Optional. Image size to use. Accepts any valid image size, |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
* or an array of width and height values in pixels (in that order). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
* Default 'post-thumbnail'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
229 |
function the_post_thumbnail_url( $size = 'post-thumbnail' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
230 |
$url = get_the_post_thumbnail_url( null, $size ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
if ( $url ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
echo esc_url( $url ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
} |
0 | 234 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
* Returns the post thumbnail caption. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
240 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
241 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
242 |
* @return string Post thumbnail caption. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
243 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
function get_the_post_thumbnail_caption( $post = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
$post_thumbnail_id = get_post_thumbnail_id( $post ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
if ( ! $post_thumbnail_id ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
return ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
248 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
249 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
$caption = wp_get_attachment_caption( $post_thumbnail_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
252 |
if ( ! $caption ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
$caption = ''; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
255 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
256 |
return $caption; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
257 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
258 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
259 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
260 |
* Displays the post thumbnail caption. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
261 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
262 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
function the_post_thumbnail_caption( $post = null ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
* Filters the displayed post thumbnail caption. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
* @param string $caption Caption for the given attachment. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
echo apply_filters( 'the_post_thumbnail_caption', get_the_post_thumbnail_caption( $post ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
} |