Make WordPress Core

Ticket #12235: 12235.diff

File 12235.diff, 2.2 KB (added by flixos90, 9 years ago)
  • src/wp-includes/post-thumbnail-template.php

     
    210210                echo esc_url( $url );
    211211        }
    212212}
     213
     214/**
     215 * Returns the post thumbnail caption.
     216 *
     217 * @since 4.6.0
     218 *
     219 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
     220 * @return string|false Post thumbnail caption or false if no caption is available.
     221 */
     222function get_the_post_thumbnail_caption( $post = null ) {
     223        $post_thumbnail_id = get_post_thumbnail_id( $post );
     224        if ( ! $post_thumbnail_id ) {
     225                return false;
     226        }
     227        return wp_get_attachment_caption( $post_thumbnail_id );
     228}
     229
     230/**
     231 * Displays the post thumbnail caption.
     232 *
     233 * @since 4.6.0
     234 *
     235 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
     236 */
     237function the_post_thumbnail_caption( $post = null ) {
     238        $caption = get_the_post_thumbnail_caption( $post );
     239        if ( $caption ) {
     240                echo esc_html( $caption );
     241        }
     242}
  • src/wp-includes/post.php

     
    50875087}
    50885088
    50895089/**
     5090 * Retrieves caption for an attachment.
     5091 *
     5092 * @since 4.6.0
     5093 *
     5094 * @param int $post_id Optional. Attachment ID. Default 0.
     5095 * @return string|false False on failure. Attachment caption on success.
     5096 */
     5097function wp_get_attachment_caption( $post_id = 0 ) {
     5098        $post_id = (int) $post_id;
     5099        if ( ! $post = get_post( $post_id ) ) {
     5100                return false;
     5101        }
     5102
     5103        if ( 'attachment' !== $post->post_type ) {
     5104                return false;
     5105        }
     5106
     5107        $caption = $post->post_excerpt;
     5108
     5109        /**
     5110         * Filters the attachment caption.
     5111         *
     5112         * @since 4.6.0
     5113         *
     5114         * @param string $caption Caption for the given attachment.
     5115         * @param int    $post_id Attachment ID.
     5116         */
     5117        $caption = apply_filters( 'wp_get_attachment_caption', $caption, $post->ID );
     5118
     5119        if ( empty( $caption ) ) {
     5120                return false;
     5121        }
     5122
     5123        return $caption;
     5124}
     5125
     5126/**
    50905127 * Retrieve thumbnail for an attachment.
    50915128 *
    50925129 * @since 2.1.0