diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 1b1f01c571..70da2f2e2a 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -143,6 +143,10 @@ add_filter( 'the_excerpt', 'wpautop' ); add_filter( 'the_excerpt', 'shortcode_unautop'); add_filter( 'get_the_excerpt', 'wp_trim_excerpt' ); +add_filter( 'the_post_thumbnail_caption', 'wptexturize' ); +add_filter( 'the_post_thumbnail_caption', 'convert_smilies' ); +add_filter( 'the_post_thumbnail_caption', 'convert_chars' ); + add_filter( 'comment_text', 'wptexturize' ); add_filter( 'comment_text', 'convert_chars' ); add_filter( 'comment_text', 'make_clickable', 9 ); diff --git a/wp-includes/post-thumbnail-template.php b/wp-includes/post-thumbnail-template.php index 2b95f4fb70..4722565d96 100644 --- a/wp-includes/post-thumbnail-template.php +++ b/wp-includes/post-thumbnail-template.php @@ -210,3 +210,44 @@ function the_post_thumbnail_url( $size = 'post-thumbnail' ) { echo esc_url( $url ); } } + +/** + * Returns the post thumbnail caption. + * + * @since 4.6.0 + * + * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. + * @return string Post thumbnail caption. + */ +function get_the_post_thumbnail_caption( $post = null ) { + $post_thumbnail_id = get_post_thumbnail_id( $post ); + if ( ! $post_thumbnail_id ) { + return ''; + } + + $caption = wp_get_attachment_caption( $post_thumbnail_id ); + + if ( ! $caption ) { + $caption = ''; + } + + return $caption; +} + +/** + * Displays the post thumbnail caption. + * + * @since 4.6.0 + * + * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`. + */ +function the_post_thumbnail_caption( $post = null ) { + /** + * Filters the displayed post thumbnail caption. + * + * @since 4.6.0 + * + * @param string $caption Caption for the given attachment. + */ + echo apply_filters( 'the_post_thumbnail_caption', get_the_post_thumbnail_caption( $post ) ); +} diff --git a/wp-includes/post.php b/wp-includes/post.php index 61f9018cd7..aa15f7239d 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -4936,6 +4936,37 @@ function wp_get_attachment_url( $post_id = 0 ) { return $url; } +/** + * Retrieves the caption for an attachment. + * + * @since 4.6.0 + * + * @param int $post_id Optional. Attachment ID. Default 0. + * @return string|false False on failure. Attachment caption on success. + */ +function wp_get_attachment_caption( $post_id = 0 ) { + $post_id = (int) $post_id; + if ( ! $post = get_post( $post_id ) ) { + return false; + } + + if ( 'attachment' !== $post->post_type ) { + return false; + } + + $caption = $post->post_excerpt; + + /** + * Filters the attachment caption. + * + * @since 4.6.0 + * + * @param string $caption Caption for the given attachment. + * @param int $post_id Attachment ID. + */ + return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID ); +} + /** * Retrieve thumbnail for an attachment. * diff --git a/wp-includes/version.php b/wp-includes/version.php index e61b1fafcd..4aee09819f 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-alpha-37914'; +$wp_version = '4.6-alpha-37915'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.