Permalink
Browse files

Move the post thumbnail action hooks to within the get_the_image() fu…

…nction and only run them if the image is being displayed.

git-svn-id: http://svn.locallylost.com/themes/hybrid-core/trunk@967 dba0f204-706d-4bc1-bc29-8b92e0485636
  • Loading branch information...
1 parent 2c820a3 commit aebd7bb50221beaeb253015c896b723b4f2aaded greenshady committed Jan 1, 2012
Showing with 15 additions and 15 deletions.
  1. +15 −15 extensions/get-the-image.php
@@ -139,21 +139,21 @@ function get_the_image( $args = array() ) {
get_the_image_meta_key_save( $args, $image['src'] );
/* Format the image HTML. */
- $image = get_the_image_format( $args, $image );
+ $image_html = get_the_image_format( $args, $image );
/* Set the image cache for the specific post. */
- $image_cache[$key] = $image;
+ $image_cache[$key] = $image_html;
wp_cache_set( $post_id, $image_cache, 'get_the_image' );
}
}
/* If an image was already cached for the post and arguments, use it. */
else {
- $image = $image_cache[$key];
+ $image_html = $image_cache[$key];
}
/* Allow plugins/theme to override the final output. */
- $image = apply_filters( 'get_the_image', $image );
+ $image_html = apply_filters( 'get_the_image', $image_html );
/* If $format is set to 'array', return an array of image attributes. */
if ( 'array' == $format ) {
@@ -162,7 +162,7 @@ function get_the_image( $args = array() ) {
$out = array();
/* Get the image attributes. */
- $atts = wp_kses_hair( $image, array( 'http' ) );
+ $atts = wp_kses_hair( $image_html, array( 'http' ) );
/* Loop through the image attributes and add them in key/value pairs for the return array. */
foreach ( $atts as $att )
@@ -176,11 +176,19 @@ function get_the_image( $args = array() ) {
/* Or, if $echo is set to false, return the formatted image. */
elseif ( false === $echo ) {
- return $args['before'] . $image . $args['after'];
+ return $args['before'] . $image_html . $args['after'];
}
+ /* If there is a $post_thumbnail_id, do the actions associated with get_the_post_thumbnail(). */
+ if ( isset( $image['post_thumbnail_id'] ) )
+ do_action( 'begin_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $size );
+
/* Display the image if we get to this point. */
- echo $args['before'] . $image . $args['after'];
+ echo $args['before'] . $image_html . $args['after'];
+
+ /* If there is a $post_thumbnail_id, do the actions associated with get_the_post_thumbnail(). */
+ if ( isset( $image['post_thumbnail_id'] ) )
+ do_action( 'end_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $size );
}
/* Internal Functions */
@@ -405,10 +413,6 @@ function get_the_image_format( $args = array(), $image = false ) {
/* Join all the classes into a single string and make sure there are no duplicates. */
$class = join( ' ', array_unique( $classes ) );
- /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
- if ( !empty( $image['post_thumbnail_id'] ) )
- do_action( 'begin_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $size );
-
/* Add the image attributes to the <img /> element. */
$html = '<img src="' . $image['src'] . '" alt="' . esc_attr( strip_tags( $image_alt ) ) . '" class="' . esc_attr( $class ) . '"' . $width . $height . ' />';
@@ -418,10 +422,6 @@ function get_the_image_format( $args = array(), $image = false ) {
/* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
if ( !empty( $image['post_thumbnail_id'] ) )
- do_action( 'end_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $size );
-
- /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
- if ( !empty( $image['post_thumbnail_id'] ) )
$html = apply_filters( 'post_thumbnail_html', $html, $post_id, $image['post_thumbnail_id'], $size, '' );
return $html;

0 comments on commit aebd7bb

Please sign in to comment.