From 5df077df8a9c07f42f51ab5a398486787a02af74 Mon Sep 17 00:00:00 2001 From: antpb Date: Sun, 7 Nov 2021 19:29:00 +0000 Subject: [PATCH] Media: Add filter for post thumbnail url. Introduces new filter `post_thumbnail_url` which allows overriding the default url returned from `wp_get_attachement_image_url()`. Props ibenic, SergeyBiryukov, jackreichert, audrasjb. Fixes #40547. Built from https://develop.svn.wordpress.org/trunk@52027 git-svn-id: http://core.svn.wordpress.org/trunk@51619 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post-thumbnail-template.php | 14 +++++++++++++- wp-includes/version.php | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/wp-includes/post-thumbnail-template.php b/wp-includes/post-thumbnail-template.php index 162d7872b2..6c8fa584a1 100644 --- a/wp-includes/post-thumbnail-template.php +++ b/wp-includes/post-thumbnail-template.php @@ -227,7 +227,19 @@ function get_the_post_thumbnail_url( $post = null, $size = 'post-thumbnail' ) { return false; } - return wp_get_attachment_image_url( $post_thumbnail_id, $size ); + $thumbnail_url = wp_get_attachment_image_url( $post_thumbnail_id, $size ); + + /** + * Filters the post thumbnail URL. + * + * @since 5.9.0 + * + * @param string|false $thumbnail_url Post thumbnail URL or false if the post does not exist. + * @param int|WP_Post|null $post Post ID or WP_Post object. Default is global `$post`. + * @param string|int[] $size Registered image size to retrieve the source for or a flat array + * of height and width dimensions. Default 'post-thumbnail'. + */ + return apply_filters( 'post_thumbnail_url', $thumbnail_url, $post, $size ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 1413c8c08d..b9423ad53a 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-52026'; +$wp_version = '5.9-alpha-52027'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.