Ticket #24404: post-format-image-no-link.patch
File post-format-image-no-link.patch, 2.4 KB (added by , 12 years ago) |
---|
-
wp-includes/media.php
2420 2420 * 2421 2421 * @param string $attached_size If an attached image is found, the size to display it. 2422 2422 * @param WP_Post $post Optional. Used instead of global $post when passed. 2423 * @param bool $link Wrap the returned image in its link, if available. 2423 2424 * @return string HTML for the image. Blank string if no image is found. 2424 2425 */ 2425 function get_the_post_format_image( $attached_size = 'full', &$post = null ) {2426 function get_the_post_format_image( $attached_size = 'full', &$post = null, $link = true ) { 2426 2427 if ( empty( $post ) ) 2427 2428 $post = get_post(); 2428 2429 … … 2430 2431 return ''; 2431 2432 2432 2433 $cache_key = "image:{$attached_size}"; 2434 if ( ! $link ) 2435 $cache_key .= '-nolink'; 2433 2436 2434 2437 if ( isset( $post->format_content[ $cache_key ] ) ) 2435 2438 return $post->format_content[ $cache_key ]; … … 2441 2444 $meta = get_post_format_meta( $post->ID ); 2442 2445 2443 2446 $link_fmt = '%s'; 2444 if ( ! empty( $meta['url'] ) )2447 if ( $link && ! empty( $meta['url'] ) ) 2445 2448 $link_fmt = '<a href="' . esc_url( $meta['url'] ) . '">%s</a>'; 2446 2449 2447 2450 if ( ! empty( $meta['image'] ) ) { … … 2452 2455 $image = sprintf( $link_fmt, $image ); 2453 2456 } elseif ( has_shortcode( $meta['image'], 'caption' ) ) { 2454 2457 // wrap <img> in <a> 2455 if ( ! empty( $meta['url'] ) && false === strpos( $meta['image'], '<a ' ) ) {2458 if ( $link && ! empty( $meta['url'] ) && false === strpos( $meta['image'], '<a ' ) ) { 2456 2459 $meta['image'] = preg_replace( 2457 2460 '#(<img[^>]+>)#', 2458 2461 sprintf( '<a href="%s">$1</a>', esc_url( $meta['url'] ) ), … … 2488 2491 $image = str_replace( $matched_html, wp_get_attachment_image( $attachment_id, $attached_size ), $image ); 2489 2492 } 2490 2493 2491 if ( false === strpos( $image, '<a ' ) )2494 if ( $link && false === strpos( $image, '<a ' ) ) 2492 2495 $post->format_content[ $cache_key ] = sprintf( $link_fmt, $image ); 2493 2496 else 2494 2497 $post->format_content[ $cache_key ] = $image; … … 2548 2551 $post->format_content[ $cache_key ] = sprintf( $link_fmt, $image ); 2549 2552 } else { 2550 2553 $post->format_content[ $cache_key ] = $matched; 2551 if ( ! empty( $meta['url'] ) && false === stripos( $matched, '<a ' ) )2554 if ( $link && ! empty( $meta['url'] ) && false === stripos( $matched, '<a ' ) ) 2552 2555 $post->format_content[ $cache_key ] = sprintf( $link_fmt, $matched ); 2553 2556 } 2554 2557 return $post->format_content[ $cache_key ];