From 95c3de8a9f06f40e0f0fb399513afcfed71415de Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Sun, 14 Apr 2013 16:59:52 +0000 Subject: [PATCH] Link post format images if a URL is provided. Make the URL available via get_the_post_format_url(). props wonderboymusic, obenland. fixes #23964. git-svn-id: https://develop.svn.wordpress.org/trunk@23992 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/media.php | 19 ++++++++++++++----- wp-includes/post-formats.php | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index e626f54817..25fa507aea 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -2400,8 +2400,13 @@ function get_the_post_format_image( $attached_size = 'full', &$post = null ) { return $post->format_content; $meta = get_post_format_meta( $post->ID ); + + $link_fmt = '%s'; + if ( ! empty( $meta['url'] ) ) + $link_fmt = '%s'; + if ( ! empty( $meta['image'] ) ) { - $post->format_content = wp_get_attachment_image( $meta['image'], $attached_size ); + $post->format_content = sprintf( $link_fmt, wp_get_attachment_image( $meta['image'], $attached_size ) ); return $post->format_content; } @@ -2412,8 +2417,11 @@ function get_the_post_format_image( $attached_size = 'full', &$post = null ) { $urls = array(); foreach ( $sizes as $size ) { - $urls[] = reset( wp_get_attachment_image_src( $media->ID, $size ) ); - $urls[] = get_attachment_link( $media->ID ); + $image = wp_get_attachment_image_src( $media->ID, $size ); + if ( $image ) { + $urls[] = reset( $image ); + $urls[] = get_attachment_link( $media->ID ); + } } $count = 1; @@ -2443,7 +2451,8 @@ function get_the_post_format_image( $attached_size = 'full', &$post = null ) { } $post->split_content = $content; - $post->format_content = wp_get_attachment_image( $media->ID, $attached_size ); + $image = wp_get_attachment_image( $media->ID, $attached_size ); + $post->format_content = sprintf( $link_fmt, $image ); return $post->format_content; } @@ -2452,7 +2461,7 @@ function get_the_post_format_image( $attached_size = 'full', &$post = null ) { if ( ! empty( $htmls ) ) { $html = reset( $htmls ); $post->split_content = $content; - $post->format_content = $html; + $post->format_content = sprintf( $link_fmt, $html ); return $post->format_content; } } diff --git a/wp-includes/post-formats.php b/wp-includes/post-formats.php index 977d960f05..bd164af498 100644 --- a/wp-includes/post-formats.php +++ b/wp-includes/post-formats.php @@ -707,7 +707,7 @@ function get_the_post_format_url( $id = 0 ) { if ( empty( $post ) ) return ''; - if ( in_array( get_post_format( $post->ID ), array( 'link', 'quote' ) ) ) { + if ( in_array( get_post_format( $post->ID ), array( 'image', 'link', 'quote' ) ) ) { $meta = get_post_format_meta( $post->ID ); if ( ! empty( $meta['url'] ) ) return apply_filters( 'get_the_post_format_url', esc_url_raw( $meta['url'] ), $post );