Make WordPress Core

Changeset 52028


Ignore:
Timestamp:
11/07/2021 08:36:11 PM (2 years ago)
Author:
antpb
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post-thumbnail-template.php

    r52027 r52028  
    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
Note: See TracChangeset for help on using the changeset viewer.