From 78d274099aafc3071550dbac2f15e3371b50d6d1 Mon Sep 17 00:00:00 2001 From: antpb Date: Sun, 7 Nov 2021 20:37:58 +0000 Subject: [PATCH] Media: Add filter for post thumbnail id. Introduces new filter `post_thumbnail_id` which allows overriding the default id returned from `get_post_thumbnail_id()`. Props engelen, alexvorn2, gilbitron, sebastianpisula, SergeyBiryukov, leogermani, rzen, joemcgill, audrasjb. Fixes #23983. Built from https://develop.svn.wordpress.org/trunk@52028 git-svn-id: http://core.svn.wordpress.org/trunk@51620 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post-thumbnail-template.php | 12 +++++++++++- wp-includes/version.php | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/wp-includes/post-thumbnail-template.php b/wp-includes/post-thumbnail-template.php index 6c8fa584a1..79b9a55d3a 100644 --- a/wp-includes/post-thumbnail-template.php +++ b/wp-includes/post-thumbnail-template.php @@ -57,7 +57,17 @@ function get_post_thumbnail_id( $post = null ) { return false; } - return (int) get_post_meta( $post->ID, '_thumbnail_id', true ); + $thumbnail_id = (int) get_post_meta( $post->ID, '_thumbnail_id', true ); + + /** + * Filters post thumbnail ID. + * + * @since 5.9.0 + * + * @param int|false $thumbnail_id Post thumbnail ID or false if the post does not exist. + * @param int|WP_Post|null $post Post ID or WP_Post object. Default is global `$post`. + */ + return (int) apply_filters( 'post_thumbnail_id', $thumbnail_id, $post ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index b9423ad53a..a2a5857dd3 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-52027'; +$wp_version = '5.9-alpha-52028'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.