Get the Image - Version 0.6.2

Version Description

Download this release

Release Info

Developer greenshady
Plugin Icon 128x128 Get the Image
Version 0.6.2
Comparing to
See all releases

Code changes from version 0.6.1 to 0.6.2

Files changed (3) hide show
  1. get-the-image.php +38 -23
  2. readme.html +1 -1
  3. readme.txt +7 -2
get-the-image.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Get The Image
4
  * Plugin URI: http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin
5
  * Description: This is a highly intuitive script that can grab an image by custom field input, post attachment, or extracting it from the post's content.
6
- * Version: 0.6.1
7
  * Author: Justin Tadlock
8
  * Author URI: http://justintadlock.com
9
  *
@@ -23,7 +23,7 @@
23
  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24
  *
25
  * @package GetTheImage
26
- * @version 0.6.1
27
  * @author Justin Tadlock <justin@justintadlock.com>
28
  * @copyright Copyright (c) 2008 - 2010, Justin Tadlock
29
  * @link http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin
@@ -99,14 +99,17 @@ function get_the_image( $args = array() ) {
99
  /* Extract the array to allow easy use of variables. */
100
  extract( $args );
101
 
 
 
 
102
  /* Check for a cached image. */
103
- $image_cache = wp_cache_get( 'get_the_image' );
104
 
105
  if ( !is_array( $image_cache ) )
106
  $image_cache = array();
107
 
108
  /* If there is no cached image, let's see if one exists. */
109
- if ( !isset( $image_cache[$post_id][$size] ) || empty( $cache ) ) {
110
 
111
  /* If a custom field key (array) is defined, check for images by custom field. */
112
  if ( !empty( $meta_key ) )
@@ -132,25 +135,33 @@ function get_the_image( $args = array() ) {
132
  if ( empty( $image ) && !empty( $default_image ) )
133
  $image = image_by_default( $args );
134
 
135
- /* If $meta_key_save was set, save the image to a custom field. */
136
- if ( !empty( $image ) && !empty( $meta_key_save ) )
137
- get_the_image_meta_key_save( $args, $image );
 
 
 
138
 
139
- /* If an image is returned, run it through the display function. */
140
- if ( !empty( $image ) )
141
- $image = display_the_image( $args, $image );
 
 
 
 
 
142
 
143
- $image_cache[$post_id][$size] = $image;
144
- wp_cache_set( 'get_the_image', $image_cache );
145
  }
146
  else {
147
- $image = $image_cache[$post_id][$size];
148
  }
149
 
150
  /* Allow plugins/theme to override the final output. */
151
  $image = apply_filters( 'get_the_image', $image );
152
 
153
- /* Display the image if $echo is set to true and the $format isn't an array. Else, return the image. */
154
  if ( 'array' == $format ) {
155
  $atts = wp_kses_hair( $image, array( 'http' ) );
156
 
@@ -160,10 +171,14 @@ function get_the_image( $args = array() ) {
160
  $out['url'] = $out['src']; // @deprecated 0.5 Use 'src' instead of 'url'.
161
  return $out;
162
  }
163
- elseif ( !empty( $echo ) )
164
- echo $image;
165
- else
166
  return $image;
 
 
 
 
167
  }
168
 
169
  /* Internal Functions */
@@ -324,7 +339,7 @@ function image_by_default( $args = array() ) {
324
  function display_the_image( $args = array(), $image = false ) {
325
 
326
  /* If there is no image URL, return false. */
327
- if ( empty( $image['url'] ) )
328
  return false;
329
 
330
  /* Extract the arguments for easy-to-use variables. */
@@ -355,7 +370,7 @@ function display_the_image( $args = array(), $image = false ) {
355
  do_action( 'begin_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $size );
356
 
357
  /* Add the image attributes to the <img /> element. */
358
- $html = '<img src="' . $image['url'] . '" alt="' . esc_attr( strip_tags( $image_alt ) ) . '" class="' . esc_attr( $class ) . '"' . $width . $height . ' />';
359
 
360
  /* If $link_to_post is set to true, link the image to its post. */
361
  if ( $link_to_post )
@@ -384,7 +399,7 @@ function display_the_image( $args = array(), $image = false ) {
384
  function get_the_image_meta_key_save( $args = array(), $image = array() ) {
385
 
386
  /* If the $meta_key_save argument is empty or there is no image $url given, return. */
387
- if ( empty( $args['meta_key_save'] ) || empty( $image['url'] ) )
388
  return;
389
 
390
  /* Get the current value of the meta key. */
@@ -392,11 +407,11 @@ function get_the_image_meta_key_save( $args = array(), $image = array() ) {
392
 
393
  /* If there is no value for the meta key, set a new value with the image $url. */
394
  if ( empty( $meta ) )
395
- add_post_meta( $args['post_id'], $args['meta_key_save'], $image['url'] );
396
 
397
  /* If the current value doesn't match the image $url, update it. */
398
- elseif ( $meta !== $image['url'] )
399
- update_post_meta( $args['post_id'], $args['meta_key_save'], $image['url'], $meta );
400
  }
401
 
402
  /**
3
  * Plugin Name: Get The Image
4
  * Plugin URI: http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin
5
  * Description: This is a highly intuitive script that can grab an image by custom field input, post attachment, or extracting it from the post's content.
6
+ * Version: 0.6.2
7
  * Author: Justin Tadlock
8
  * Author URI: http://justintadlock.com
9
  *
23
  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24
  *
25
  * @package GetTheImage
26
+ * @version 0.6.2
27
  * @author Justin Tadlock <justin@justintadlock.com>
28
  * @copyright Copyright (c) 2008 - 2010, Justin Tadlock
29
  * @link http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin
99
  /* Extract the array to allow easy use of variables. */
100
  extract( $args );
101
 
102
+ /* Get cache key based on $args. */
103
+ $key = md5( serialize( compact( array_keys( $args ) ) ) );
104
+
105
  /* Check for a cached image. */
106
+ $image_cache = wp_cache_get( $post_id, 'get_the_image' );
107
 
108
  if ( !is_array( $image_cache ) )
109
  $image_cache = array();
110
 
111
  /* If there is no cached image, let's see if one exists. */
112
+ if ( !isset( $image_cache[$key] ) || empty( $cache ) ) {
113
 
114
  /* If a custom field key (array) is defined, check for images by custom field. */
115
  if ( !empty( $meta_key ) )
135
  if ( empty( $image ) && !empty( $default_image ) )
136
  $image = image_by_default( $args );
137
 
138
+ /* If an image was found. */
139
+ if ( !empty( $image ) ) {
140
+
141
+ /* Change $image['url'] to $image['src']. */
142
+ if ( isset( $image['url'] ) ) // 'url' key deprecated 0.6.2
143
+ $image['src'] = $image['url'];
144
 
145
+ /* If $meta_key_save was set, save the image to a custom field. */
146
+ if ( !empty( $meta_key_save ) )
147
+ get_the_image_meta_key_save( $args, $image );
148
+
149
+ /* If an image is returned, run it through the display function. */
150
+ if ( !empty( $image ) )
151
+ $image = display_the_image( $args, $image );
152
+ }
153
 
154
+ $image_cache[$key] = $image;
155
+ wp_cache_set( $post_id, $image_cache, 'get_the_image' );
156
  }
157
  else {
158
+ $image = $image_cache[$key];
159
  }
160
 
161
  /* Allow plugins/theme to override the final output. */
162
  $image = apply_filters( 'get_the_image', $image );
163
 
164
+ /* If $format is set to 'array', return an array of image attributes. */
165
  if ( 'array' == $format ) {
166
  $atts = wp_kses_hair( $image, array( 'http' ) );
167
 
171
  $out['url'] = $out['src']; // @deprecated 0.5 Use 'src' instead of 'url'.
172
  return $out;
173
  }
174
+
175
+ /* Or, if $echo is set to false, return the formatted image. */
176
+ elseif ( empty( $echo ) ) {
177
  return $image;
178
+ }
179
+
180
+ /* Display the image if we get to this point. */
181
+ echo $image;
182
  }
183
 
184
  /* Internal Functions */
339
  function display_the_image( $args = array(), $image = false ) {
340
 
341
  /* If there is no image URL, return false. */
342
+ if ( empty( $image['src'] ) )
343
  return false;
344
 
345
  /* Extract the arguments for easy-to-use variables. */
370
  do_action( 'begin_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $size );
371
 
372
  /* Add the image attributes to the <img /> element. */
373
+ $html = '<img src="' . $image['src'] . '" alt="' . esc_attr( strip_tags( $image_alt ) ) . '" class="' . esc_attr( $class ) . '"' . $width . $height . ' />';
374
 
375
  /* If $link_to_post is set to true, link the image to its post. */
376
  if ( $link_to_post )
399
  function get_the_image_meta_key_save( $args = array(), $image = array() ) {
400
 
401
  /* If the $meta_key_save argument is empty or there is no image $url given, return. */
402
+ if ( empty( $args['meta_key_save'] ) || empty( $image['src'] ) )
403
  return;
404
 
405
  /* Get the current value of the meta key. */
407
 
408
  /* If there is no value for the meta key, set a new value with the image $url. */
409
  if ( empty( $meta ) )
410
+ add_post_meta( $args['post_id'], $args['meta_key_save'], $image['src'] );
411
 
412
  /* If the current value doesn't match the image $url, update it. */
413
+ elseif ( $meta !== $image['src'] )
414
+ update_post_meta( $args['post_id'], $args['meta_key_save'], $image['src'], $meta );
415
  }
416
 
417
  /**
readme.html CHANGED
@@ -203,7 +203,7 @@ img.thumbnail { }</code></pre>
203
 
204
  <p>This plugin is copyrighted to <a href="http://justintadlock.com" title="Justin Tadlock">Justin Tadlock</a>.</p>
205
 
206
- <p>2008&thinsp;&ndash;&thinsp;2010 &copy; Justin Tadlock. All rights reserved.</p>
207
 
208
  </body>
209
  </html>
203
 
204
  <p>This plugin is copyrighted to <a href="http://justintadlock.com" title="Justin Tadlock">Justin Tadlock</a>.</p>
205
 
206
+ <p>2008&thinsp;&ndash;&thinsp;2011 &copy; Justin Tadlock. All rights reserved.</p>
207
 
208
  </body>
209
  </html>
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: greenshady
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3687060
4
  Tags: image, images, thumbnail
5
  Requires at least: 2.9
6
- Tested up to: 3.0.1
7
- Stable tag: 0.6.1
8
 
9
  An easy-to-use image script for adding things such as thumbnails and feature images.
10
 
@@ -56,6 +56,11 @@ You can view this plugin in action on my <a href="http://justintadlock.com" titl
56
 
57
  == Changelog ==
58
 
 
 
 
 
 
59
  **Version 0.6.1**
60
 
61
  * Updated inline documentation of the code.
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3687060
4
  Tags: image, images, thumbnail
5
  Requires at least: 2.9
6
+ Tested up to: 3.1.1
7
+ Stable tag: 0.6.2
8
 
9
  An easy-to-use image script for adding things such as thumbnails and feature images.
10
 
56
 
57
  == Changelog ==
58
 
59
+ **Version 0.6.2**
60
+
61
+ * Updated the cache to save by post ID instead of a single object.
62
+ * Minor code adjustments.
63
+
64
  **Version 0.6.1**
65
 
66
  * Updated inline documentation of the code.