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: http://core.svn.wordpress.org/trunk@23992 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Mark Jaquith 2013-04-14 16:59:52 +00:00
parent 3cefaf138e
commit df5e61ad54
2 changed files with 15 additions and 6 deletions

View File

@ -2400,8 +2400,13 @@ function get_the_post_format_image( $attached_size = 'full', &$post = null ) {
return $post->format_content; return $post->format_content;
$meta = get_post_format_meta( $post->ID ); $meta = get_post_format_meta( $post->ID );
$link_fmt = '%s';
if ( ! empty( $meta['url'] ) )
$link_fmt = '<a href="' . esc_url( $meta['url'] ) . '">%s</a>';
if ( ! empty( $meta['image'] ) ) { 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; return $post->format_content;
} }
@ -2412,9 +2417,12 @@ function get_the_post_format_image( $attached_size = 'full', &$post = null ) {
$urls = array(); $urls = array();
foreach ( $sizes as $size ) { foreach ( $sizes as $size ) {
$urls[] = reset( wp_get_attachment_image_src( $media->ID, $size ) ); $image = wp_get_attachment_image_src( $media->ID, $size );
if ( $image ) {
$urls[] = reset( $image );
$urls[] = get_attachment_link( $media->ID ); $urls[] = get_attachment_link( $media->ID );
} }
}
$count = 1; $count = 1;
$matches = array(); $matches = array();
@ -2443,7 +2451,8 @@ function get_the_post_format_image( $attached_size = 'full', &$post = null ) {
} }
$post->split_content = $content; $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; return $post->format_content;
} }
@ -2452,7 +2461,7 @@ function get_the_post_format_image( $attached_size = 'full', &$post = null ) {
if ( ! empty( $htmls ) ) { if ( ! empty( $htmls ) ) {
$html = reset( $htmls ); $html = reset( $htmls );
$post->split_content = $content; $post->split_content = $content;
$post->format_content = $html; $post->format_content = sprintf( $link_fmt, $html );
return $post->format_content; return $post->format_content;
} }
} }

View File

@ -707,7 +707,7 @@ function get_the_post_format_url( $id = 0 ) {
if ( empty( $post ) ) if ( empty( $post ) )
return ''; 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 ); $meta = get_post_format_meta( $post->ID );
if ( ! empty( $meta['url'] ) ) if ( ! empty( $meta['url'] ) )
return apply_filters( 'get_the_post_format_url', esc_url_raw( $meta['url'] ), $post ); return apply_filters( 'get_the_post_format_url', esc_url_raw( $meta['url'] ), $post );