--- a/wp/wp-includes/post-thumbnail-template.php Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-includes/post-thumbnail-template.php Mon Oct 14 18:28:13 2019 +0200
@@ -10,7 +10,11 @@
*/
/**
- * Check if post has an image attached.
+ * Determines whether a post has an image attached.
+ *
+ * For more information on this and similar theme functions, check out
+ * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
+ * Conditional Tags} article in the Theme Developer Handbook.
*
* @since 2.9.0
* @since 4.4.0 `$post` can be a post ID or WP_Post object.
@@ -19,7 +23,19 @@
* @return bool Whether the post has an image attached.
*/
function has_post_thumbnail( $post = null ) {
- return (bool) get_post_thumbnail_id( $post );
+ $thumbnail_id = get_post_thumbnail_id( $post );
+ $has_thumbnail = (bool) $thumbnail_id;
+
+ /**
+ * Filters whether a post has a post thumbnail.
+ *
+ * @since 5.1.0
+ *
+ * @param bool $has_thumbnail true if the post has a post thumbnail, otherwise false.
+ * @param int|WP_Post|null $post Post ID or WP_Post object. Default is global `$post`.
+ * @param int|string $thumbnail_id Post thumbnail ID or empty string.
+ */
+ return (bool) apply_filters( 'has_post_thumbnail', $has_thumbnail, $post, $thumbnail_id );
}
/**
@@ -72,19 +88,22 @@
* @param WP_Query $wp_query Optional. A WP_Query instance. Defaults to the $wp_query global.
*/
function update_post_thumbnail_cache( $wp_query = null ) {
- if ( ! $wp_query )
+ if ( ! $wp_query ) {
$wp_query = $GLOBALS['wp_query'];
+ }
- if ( $wp_query->thumbnails_cached )
+ if ( $wp_query->thumbnails_cached ) {
return;
+ }
$thumb_ids = array();
foreach ( $wp_query->posts as $post ) {
- if ( $id = get_post_thumbnail_id( $post->ID ) )
+ if ( $id = get_post_thumbnail_id( $post->ID ) ) {
$thumb_ids[] = $id;
+ }
}
- if ( ! empty ( $thumb_ids ) ) {
+ if ( ! empty( $thumb_ids ) ) {
_prime_post_caches( $thumb_ids, false, true );
}
@@ -145,8 +164,9 @@
* and height values (in that order). Default 'post-thumbnail'.
*/
do_action( 'begin_fetch_post_thumbnail_html', $post->ID, $post_thumbnail_id, $size );
- if ( in_the_loop() )
+ if ( in_the_loop() ) {
update_post_thumbnail_cache();
+ }
$html = wp_get_attachment_image( $post_thumbnail_id, $size, false, $attr );
/**