Make WordPress Core

Ticket #23983: 23983.2.diff

File 23983.2.diff, 825 bytes (added by audrasjb, 5 years ago)

Media: Add a hook to filter get_post_thumbnail_id() result

  • src/wp-includes/post-thumbnail-template.php

    diff --git a/src/wp-includes/post-thumbnail-template.php b/src/wp-includes/post-thumbnail-template.php
    index 162d7872b2..ef71b54bd8 100644
    a b function get_post_thumbnail_id( $post = null ) {  
    5757                return false;
    5858        }
    5959
    60         return (int) get_post_meta( $post->ID, '_thumbnail_id', true );
     60        $thumbnail_id = (int) get_post_meta( $post->ID, '_thumbnail_id', true );
     61
     62        /**
     63         * Filters post thumbnail ID.
     64         *
     65         * @since 5.9.0
     66         *
     67         * @param int|false        $thumbnail_id Post thumbnail ID or false if the post does not exist.
     68         * @param int|WP_Post|null $post         Post ID or WP_Post object. Default is global `$post`.
     69         */
     70        return (int) apply_filters( 'post_thumbnail_id', $thumbnail_id, $post );
    6171}
    6272
    6373/**