Get the Image - Version 0.6

Version Description

Download this release

Release Info

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

Code changes from version 0.5 to 0.6

Files changed (3) hide show
  1. get-the-image.php +77 -32
  2. readme.html +26 -12
  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.5
7
  * Author: Justin Tadlock
8
  * Author URI: http://justintadlock.com
9
  *
@@ -13,7 +13,7 @@
13
  * post (or any post type).
14
  *
15
  * @copyright 2008 - 2010
16
- * @version 0.5
17
  * @author Justin Tadlock
18
  * @link http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin
19
  * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
@@ -51,11 +51,10 @@ function get_the_image( $args = array() ) {
51
 
52
  /* Set the default arguments. */
53
  $defaults = array(
54
- 'custom_key' => array( 'Thumbnail', 'thumbnail' ),
55
  'post_id' => $post->ID,
56
  'attachment' => true,
57
  'the_post_thumbnail' => true, // WP 2.9+ image function
58
- 'default_size' => false, // Deprecated 0.5 in favor of $size
59
  'size' => 'thumbnail',
60
  'default_image' => false,
61
  'order_of_image' => 1,
@@ -65,6 +64,9 @@ function get_the_image( $args = array() ) {
65
  'width' => false,
66
  'height' => false,
67
  'format' => 'img',
 
 
 
68
  'echo' => true
69
  );
70
 
@@ -75,8 +77,12 @@ function get_the_image( $args = array() ) {
75
  $args = wp_parse_args( $args, $defaults );
76
 
77
  /* If $default_size is given, overwrite $size. */
78
- if ( !empty( $args['default_size'] ) )
79
- $args['size'] = $args['default_size'];
 
 
 
 
80
 
81
  /* If $format is set to 'array', don't link to the post. */
82
  if ( 'array' == $args['format'] )
@@ -86,43 +92,51 @@ function get_the_image( $args = array() ) {
86
  extract( $args );
87
 
88
  /* Check for a cached image. */
89
- $cache = wp_cache_get( 'get_the_image' );
90
 
91
- if ( !is_array( $cache ) )
92
- $cache = array();
93
 
94
  /* If there is no cached image, let's see if one exists. */
95
- if ( !isset( $cache[$post_id][$size] ) ) {
96
 
97
  /* If a custom field key (array) is defined, check for images by custom field. */
98
- if ( $custom_key )
99
  $image = image_by_custom_field( $args );
100
 
101
  /* If no image found and $the_post_thumbnail is set to true, check for a post image (WP feature). */
102
- if ( !$image && $the_post_thumbnail )
103
  $image = image_by_the_post_thumbnail( $args );
104
 
105
  /* If no image found and $attachment is set to true, check for an image by attachment. */
106
- if ( !$image && $attachment )
107
  $image = image_by_attachment( $args );
108
 
109
  /* If no image found and $image_scan is set to true, scan the post for images. */
110
- if ( !$image && $image_scan )
111
  $image = image_by_scan( $args );
112
 
 
 
 
 
113
  /* If no image found and a $default_image is set, get the default image. */
114
- if ( !$image && $default_image )
115
  $image = image_by_default( $args );
116
 
 
 
 
 
117
  /* If an image is returned, run it through the display function. */
118
- if ( $image )
119
  $image = display_the_image( $args, $image );
120
 
121
- $cache[$post_id][$size] = $image;
122
- wp_cache_set( 'get_the_image', $cache );
123
  }
124
  else {
125
- $image = $cache[$post_id][$size];
126
  }
127
 
128
  /* Allow plugins/theme to override the final output. */
@@ -138,7 +152,7 @@ function get_the_image( $args = array() ) {
138
  $out['url'] = $out['src']; // @deprecated 0.5 Use 'src' instead of 'url'.
139
  return $out;
140
  }
141
- elseif ( $echo )
142
  echo $image;
143
  else
144
  return $image;
@@ -157,13 +171,13 @@ function get_the_image( $args = array() ) {
157
  */
158
  function image_by_custom_field( $args = array() ) {
159
 
160
- /* If $custom_key is a string, we want to split it by spaces into an array. */
161
- if ( !is_array( $args['custom_key'] ) )
162
- $args['custom_key'] = preg_split( '#\s+#', $args['custom_key'] );
163
 
164
- /* If $custom_key is set, loop through each custom field key, searching for values. */
165
- if ( isset( $args['custom_key'] ) ) {
166
- foreach ( $args['custom_key'] as $custom ) {
167
  $image = get_metadata( 'post', $args['post_id'], $custom, true );
168
  if ( $image )
169
  break;
@@ -234,6 +248,9 @@ function image_by_attachment( $args = array() ) {
234
  if ( empty( $attachments ) && empty( $image ) )
235
  return false;
236
 
 
 
 
237
  /* Loop through each attachment. Once the $order_of_image (default is '1') is reached, break the loop. */
238
  foreach ( $attachments as $id => $attachment ) {
239
  if ( ++$i == $args['order_of_image'] ) {
@@ -299,15 +316,15 @@ function display_the_image( $args = array(), $image = false ) {
299
  extract( $args );
300
 
301
  /* If there is alt text, set it. Otherwise, default to the post title. */
302
- $image_alt = ( ( $image['alt'] ) ? $image['alt'] : apply_filters( 'the_title', get_post_field( 'post_title', $post_id ) ) );
303
 
304
  /* If there is a width or height, set them as HMTL-ready attributes. */
305
  $width = ( ( $width ) ? ' width="' . esc_attr( $width ) . '"' : '' );
306
  $height = ( ( $height ) ? ' height="' . esc_attr( $height ) . '"' : '' );
307
 
308
  /* Loop through the custom field keys and add them as classes. */
309
- if ( is_array( $custom_key ) ) {
310
- foreach ( $custom_key as $key )
311
  $classes[] = str_replace( ' ', '-', strtolower( $key ) );
312
  }
313
 
@@ -319,7 +336,7 @@ function display_the_image( $args = array(), $image = false ) {
319
  $class = join( ' ', array_unique( $classes ) );
320
 
321
  /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
322
- if ( $image['post_thumbnail_id'] )
323
  do_action( 'begin_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $size );
324
 
325
  /* Add the image attributes to the <img /> element. */
@@ -330,16 +347,44 @@ function display_the_image( $args = array(), $image = false ) {
330
  $html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( apply_filters( 'the_title', get_post_field( 'post_title', $post_id ) ) ) . '">' . $html . '</a>';
331
 
332
  /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
333
- if ( $image['post_thumbnail_id'] )
334
  do_action( 'end_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $size );
335
 
336
  /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
337
- if ( $image['post_thumbnail_id'] )
338
  $html = apply_filters( 'post_thumbnail_html', $html, $post_id, $image['post_thumbnail_id'], $size, '' );
339
 
340
  return $html;
341
  }
342
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
343
  /**
344
  * Deletes the image cache for users that are using a persistent-caching plugin.
345
  *
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
7
  * Author: Justin Tadlock
8
  * Author URI: http://justintadlock.com
9
  *
13
  * post (or any post type).
14
  *
15
  * @copyright 2008 - 2010
16
+ * @version 0.6
17
  * @author Justin Tadlock
18
  * @link http://justintadlock.com/archives/2008/05/27/get-the-image-wordpress-plugin
19
  * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
51
 
52
  /* Set the default arguments. */
53
  $defaults = array(
54
+ 'meta_key' => array( 'Thumbnail', 'thumbnail' ),
55
  'post_id' => $post->ID,
56
  'attachment' => true,
57
  'the_post_thumbnail' => true, // WP 2.9+ image function
 
58
  'size' => 'thumbnail',
59
  'default_image' => false,
60
  'order_of_image' => 1,
64
  'width' => false,
65
  'height' => false,
66
  'format' => 'img',
67
+ 'meta_key_save' => false,
68
+ 'callback' => null,
69
+ 'cache' => true,
70
  'echo' => true
71
  );
72
 
77
  $args = wp_parse_args( $args, $defaults );
78
 
79
  /* If $default_size is given, overwrite $size. */
80
+ if ( isset( $args['default_size'] ) )
81
+ $args['size'] = $args['default_size']; // Deprecated 0.5 in favor of $size
82
+
83
+ /* If $custom_key is set, overwrite $meta_key. */
84
+ if ( isset( $args['custom_key'] ) )
85
+ $args['meta_key'] = $args['custom_key']; // Deprecated 0.6 in favor of $meta_key
86
 
87
  /* If $format is set to 'array', don't link to the post. */
88
  if ( 'array' == $args['format'] )
92
  extract( $args );
93
 
94
  /* Check for a cached image. */
95
+ $image_cache = wp_cache_get( 'get_the_image' );
96
 
97
+ if ( !is_array( $image_cache ) )
98
+ $image_cache = array();
99
 
100
  /* If there is no cached image, let's see if one exists. */
101
+ if ( !isset( $image_cache[$post_id][$size] ) || empty( $cache ) ) {
102
 
103
  /* If a custom field key (array) is defined, check for images by custom field. */
104
+ if ( !empty( $meta_key ) )
105
  $image = image_by_custom_field( $args );
106
 
107
  /* If no image found and $the_post_thumbnail is set to true, check for a post image (WP feature). */
108
+ if ( empty( $image ) && !empty( $the_post_thumbnail ) )
109
  $image = image_by_the_post_thumbnail( $args );
110
 
111
  /* If no image found and $attachment is set to true, check for an image by attachment. */
112
+ if ( empty( $image ) && !empty( $attachment ) )
113
  $image = image_by_attachment( $args );
114
 
115
  /* If no image found and $image_scan is set to true, scan the post for images. */
116
+ if ( empty( $image ) && !empty( $image_scan ) )
117
  $image = image_by_scan( $args );
118
 
119
+ /* If no image found and a callback function was given. */
120
+ if ( empty( $image ) && !is_null( $callback ) && function_exists( $callback ) )
121
+ $image = call_user_func( $callback, $args );
122
+
123
  /* If no image found and a $default_image is set, get the default image. */
124
+ if ( empty( $image ) && !empty( $default_image ) )
125
  $image = image_by_default( $args );
126
 
127
+ /* If $meta_key_save was set, save the image to a custom field. */
128
+ if ( !empty( $image ) && !empty( $meta_key_save ) )
129
+ get_the_image_meta_key_save( $args, $image );
130
+
131
  /* If an image is returned, run it through the display function. */
132
+ if ( !empty( $image ) )
133
  $image = display_the_image( $args, $image );
134
 
135
+ $image_cache[$post_id][$size] = $image;
136
+ wp_cache_set( 'get_the_image', $image_cache );
137
  }
138
  else {
139
+ $image = $image_cache[$post_id][$size];
140
  }
141
 
142
  /* Allow plugins/theme to override the final output. */
152
  $out['url'] = $out['src']; // @deprecated 0.5 Use 'src' instead of 'url'.
153
  return $out;
154
  }
155
+ elseif ( !empty( $echo ) )
156
  echo $image;
157
  else
158
  return $image;
171
  */
172
  function image_by_custom_field( $args = array() ) {
173
 
174
+ /* If $meta_key is a string, we want to split it by spaces into an array. */
175
+ if ( !is_array( $args['meta_key'] ) )
176
+ $args['meta_key'] = preg_split( '#\s+#', $args['meta_key'] );
177
 
178
+ /* If $meta_key is set, loop through each custom field key, searching for values. */
179
+ if ( is_array( $args['meta_key'] ) ) {
180
+ foreach ( $args['meta_key'] as $custom ) {
181
  $image = get_metadata( 'post', $args['post_id'], $custom, true );
182
  if ( $image )
183
  break;
248
  if ( empty( $attachments ) && empty( $image ) )
249
  return false;
250
 
251
+ /* Set the default iterator to 0. */
252
+ $i = 0;
253
+
254
  /* Loop through each attachment. Once the $order_of_image (default is '1') is reached, break the loop. */
255
  foreach ( $attachments as $id => $attachment ) {
256
  if ( ++$i == $args['order_of_image'] ) {
316
  extract( $args );
317
 
318
  /* If there is alt text, set it. Otherwise, default to the post title. */
319
+ $image_alt = ( ( !empty( $image['alt'] ) ) ? $image['alt'] : apply_filters( 'the_title', get_post_field( 'post_title', $post_id ) ) );
320
 
321
  /* If there is a width or height, set them as HMTL-ready attributes. */
322
  $width = ( ( $width ) ? ' width="' . esc_attr( $width ) . '"' : '' );
323
  $height = ( ( $height ) ? ' height="' . esc_attr( $height ) . '"' : '' );
324
 
325
  /* Loop through the custom field keys and add them as classes. */
326
+ if ( is_array( $meta_key ) ) {
327
+ foreach ( $meta_key as $key )
328
  $classes[] = str_replace( ' ', '-', strtolower( $key ) );
329
  }
330
 
336
  $class = join( ' ', array_unique( $classes ) );
337
 
338
  /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
339
+ if ( !empty( $image['post_thumbnail_id'] ) )
340
  do_action( 'begin_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $size );
341
 
342
  /* Add the image attributes to the <img /> element. */
347
  $html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( apply_filters( 'the_title', get_post_field( 'post_title', $post_id ) ) ) . '">' . $html . '</a>';
348
 
349
  /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
350
+ if ( !empty( $image['post_thumbnail_id'] ) )
351
  do_action( 'end_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $size );
352
 
353
  /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
354
+ if ( !empty( $image['post_thumbnail_id'] ) )
355
  $html = apply_filters( 'post_thumbnail_html', $html, $post_id, $image['post_thumbnail_id'], $size, '' );
356
 
357
  return $html;
358
  }
359
 
360
+ /**
361
+ * Saves the image URL as the value of the meta key provided. This allows users to set a
362
+ * custom meta key for their image. By doing this, users can trim off database queries when
363
+ * grabbing attachments or get rid of expensive scans of the content when using the image
364
+ * scan feature.
365
+ *
366
+ * @since 0.6
367
+ * @param array $args Parameters for what image to get.
368
+ * @param array $image Array of image info ($image, $classes, $alt, $caption).
369
+ */
370
+ function get_the_image_meta_key_save( $args = array(), $image = array() ) {
371
+
372
+ /* If the $meta_key_save argument is empty or there is no image $url given, return. */
373
+ if ( empty( $args['meta_key_save'] ) || empty( $image['url'] ) )
374
+ return;
375
+
376
+ /* Get the current value of the meta key. */
377
+ $meta = get_post_meta( $args['post_id'], $args['meta_key_save'], true );
378
+
379
+ /* If there is no value for the meta key, set a new value with the image $url. */
380
+ if ( empty( $meta ) )
381
+ add_post_meta( $args['post_id'], $args['meta_key_save'], $image['url'] );
382
+
383
+ /* If the current value doesn't match the image $url, update it. */
384
+ elseif ( $meta !== $image['url'] )
385
+ update_post_meta( $args['post_id'], $args['meta_key_save'], $image['url'], $meta );
386
+ }
387
+
388
  /**
389
  * Deletes the image cache for users that are using a persistent-caching plugin.
390
  *
readme.html CHANGED
@@ -24,6 +24,7 @@
24
  <li>If no image is added by custom field, check for a <a href="http://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature" title="WordPress 2.9's post image feature">post image</a> (WordPresss 2.9+ feature).</li>
25
  <li>If no image is found, it grabs an image attached to your post.</li>
26
  <li>If no image is attached, it can extract an image from your post content (off by default).</li>
 
27
  <li>If no image is found at this point, it will default to an image you set (not set by default).</li>
28
  </ol>
29
 
@@ -36,25 +37,24 @@
36
  <li>Activate <em>Get The Image</em>.</li>
37
  </ol>
38
 
39
- <p class="alert">If you are upgrading from a version prior to 0.3 just overwrite your old files. You'll need to change the calls to the plugin in your template files because how the plugin works has changed. Follow the instructions below to see how the image script should be called.</p>
40
-
41
  <h2>How to use the plugin</h2>
42
 
43
  <p>To call the image script, you'll need to use what's called <a href="http://codex.wordpress.org/Template_Tags/How_to_Pass_Tag_Parameters#Tags_with_PHP_function-style_parameters" title="PHP function-style parameters">function-style parameters</a>.</p>
44
 
45
  <p><strong>Example with function-style parameters</strong></p>
46
 
47
- <pre><code>&lt;?php get_the_image( array( 'custom_key' => array( 'Thumbnail', 'thumbnail' ), 'size' => 'thumbnail' ) ); ?></code></pre>
48
 
49
  <h2>The image script parameters</h2>
50
 
51
  <p>By simply making a function call to <code>&lt;?php get_the_image(); ?></code> within a template file, the script will default to this:</p>
52
 
53
  <pre><code>$defaults = array(
54
- 'custom_key' => array( 'Thumbnail', 'thumbnail' ),
 
55
  'attachment' => true,
56
- 'size' => 'thumbnail',
57
  'the_post_thumbnail' => true,
 
58
  'default_image' => false,
59
  'order_of_image' => 1,
60
  'link_to_post' => true,
@@ -62,24 +62,30 @@
62
  'image_scan' => false,
63
  'width' => false,
64
  'height' => false,
 
 
 
 
65
  'echo' => true
66
  );</code></pre>
67
 
68
  <dl>
69
- <dt>custom_key</dt>
70
- <dd>This parameter refers to a custom field key (or keys) that you use. Remember, custom field keys are case-sensitive (defaults are <code>Thumbnail</code> and <code>thumbnail</code>).</dd>
 
 
71
  <dt>attachment</dt>
72
  <dd>The script will look for images attached to the post (set to <code>true</code> by default).</dd>
73
- <dt>size</dt>
74
- <dd>This refers to the size of an attached image. You can choose between <code>thumbnail</code>, <code>medium</code>, <code>large</code>, <code>full</code>, or any custom image size you have available (the default is <code>thumbnail</code>).</dd>
75
  <dt>the_post_thumbnail</dt>
76
  <dd>This refers to the WordPress 2.9's new <code>the_post_thumbnail()</code> feature. By having this set to <code>true</code>, you may select an image from the post image meta box while in the post editor.</dd>
 
 
77
  <dt>default_image</dt>
78
  <dd>Will take the input of an image URL and use it if no other images are found (no default set).</dd>
79
  <dt>order_of_image</dt>
80
  <dd>You can choose for the script to grab something other than the first attached image. This only refers to image attachments.</dd>
81
  <dt>link_to_post</dt>
82
- <dd>Whether the attachment image should be linked to the post (set to <code>true</code> by default).</dd>
83
  <dt>image_class</dt>
84
  <dd>You can give an additional class to the image for use in your CSS.</dd>
85
  <dt>image_scan</dt>
@@ -88,6 +94,14 @@
88
  <dd>Set the width of the image on output.</dd>
89
  <dt>height</dt>
90
  <dd>Set the height of the image on output.</dd>
 
 
 
 
 
 
 
 
91
  <dt>echo</dt>
92
  <dd>If set to <code>true</code>, the image is shown on the page. If set to <code>false</code>, the image will be returned to use in your own function. (Set to <code>true</code> by default.)</dd>
93
  </dl>
@@ -102,7 +116,7 @@
102
 
103
  <p><strong>Example 2:</strong> Let's suppose you want a full-sized image and maybe you want to grab it by a custom field key of <code>Feature</code>. Depending on your theme, this will need to go within the Loop in whatever file is calling the featured article.</p>
104
 
105
- <pre><code>&lt;?php get_the_image( array( 'custom_key' => array( 'Feature' ), 'size' => 'full' ) ); ?></code></pre>
106
 
107
  <p>If no feature image exists by custom field, it will look for images attached to your post.</p>
108
 
@@ -126,7 +140,7 @@
126
 
127
  &lt;div id="post-&lt;?php the_ID(); ?>" &lt;?php post_class(); ?>>
128
 
129
- &lt;?php get_the_image( array( 'custom_key' => array( 'feature_img' ), 'size' => 'medium', 'width' => '200', 'height' => '200', 'image_class' => 'feature' ) ); ?>
130
 
131
  &lt;h2>&lt;a href="&lt;?php the_permalink(); ?>" title="&lt;?php the_title_attribute(); ?>" rel="bookmark">&lt;?php the_title(); ?>&lt;/a>&lt;/h2>
132
 
24
  <li>If no image is added by custom field, check for a <a href="http://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature" title="WordPress 2.9's post image feature">post image</a> (WordPresss 2.9+ feature).</li>
25
  <li>If no image is found, it grabs an image attached to your post.</li>
26
  <li>If no image is attached, it can extract an image from your post content (off by default).</li>
27
+ <li>If no image is found, checks for a custom callback function that developers may optionally set.</li>
28
  <li>If no image is found at this point, it will default to an image you set (not set by default).</li>
29
  </ol>
30
 
37
  <li>Activate <em>Get The Image</em>.</li>
38
  </ol>
39
 
 
 
40
  <h2>How to use the plugin</h2>
41
 
42
  <p>To call the image script, you'll need to use what's called <a href="http://codex.wordpress.org/Template_Tags/How_to_Pass_Tag_Parameters#Tags_with_PHP_function-style_parameters" title="PHP function-style parameters">function-style parameters</a>.</p>
43
 
44
  <p><strong>Example with function-style parameters</strong></p>
45
 
46
+ <pre><code>&lt;?php get_the_image( array( 'meta_key' => array( 'Thumbnail', 'thumbnail' ), 'size' => 'thumbnail' ) ); ?></code></pre>
47
 
48
  <h2>The image script parameters</h2>
49
 
50
  <p>By simply making a function call to <code>&lt;?php get_the_image(); ?></code> within a template file, the script will default to this:</p>
51
 
52
  <pre><code>$defaults = array(
53
+ 'meta_key' => array( 'Thumbnail', 'thumbnail' ),
54
+ 'post_id' => $post->ID,
55
  'attachment' => true,
 
56
  'the_post_thumbnail' => true,
57
+ 'size' => 'thumbnail',
58
  'default_image' => false,
59
  'order_of_image' => 1,
60
  'link_to_post' => true,
62
  'image_scan' => false,
63
  'width' => false,
64
  'height' => false,
65
+ 'format' => 'img',
66
+ 'meta_key_save' => false,
67
+ 'callback' => null,
68
+ 'cache' => true,
69
  'echo' => true
70
  );</code></pre>
71
 
72
  <dl>
73
+ <dt>meta_key</dt>
74
+ <dd>This parameter refers to post meta keys (custom fields) that you use. Remember, meta keys are case-sensitive (defaults are <code>Thumbnail</code> and <code>thumbnail</code>).</dd>
75
+ <dt>post_id</dt>
76
+ <dd>The ID of the post to get the image for. This defaults to the current post in the loop.</dd>
77
  <dt>attachment</dt>
78
  <dd>The script will look for images attached to the post (set to <code>true</code> by default).</dd>
 
 
79
  <dt>the_post_thumbnail</dt>
80
  <dd>This refers to the WordPress 2.9's new <code>the_post_thumbnail()</code> feature. By having this set to <code>true</code>, you may select an image from the post image meta box while in the post editor.</dd>
81
+ <dt>size</dt>
82
+ <dd>This refers to the size of an attached image. You can choose between <code>thumbnail</code>, <code>medium</code>, <code>large</code>, <code>full</code>, or any custom image size you have available (the default is <code>thumbnail</code>).</dd>
83
  <dt>default_image</dt>
84
  <dd>Will take the input of an image URL and use it if no other images are found (no default set).</dd>
85
  <dt>order_of_image</dt>
86
  <dd>You can choose for the script to grab something other than the first attached image. This only refers to image attachments.</dd>
87
  <dt>link_to_post</dt>
88
+ <dd>Whether the image shown should be linked to the post (set to <code>true</code> by default).</dd>
89
  <dt>image_class</dt>
90
  <dd>You can give an additional class to the image for use in your CSS.</dd>
91
  <dt>image_scan</dt>
94
  <dd>Set the width of the image on output.</dd>
95
  <dt>height</dt>
96
  <dd>Set the height of the image on output.</dd>
97
+ <dt>format</dt>
98
+ <dd>What format to return the image in. If set to <code>array</code> the return value of the function will be an array of <code>&lt;img></code> attributes. All other values will return the <code>&lt;img></code> element.</dd>
99
+ <dt>meta_key_save</dt>
100
+ <dd>A meta key to save the image <acronym title="Uniform Resource Locator">URL</acronym> as. This is useful if you're not using custom fields but want to cut back on database queries by having the script automatically set the custom field for you. By default, this is set to <code>false</code>.</dd>
101
+ <dt>callback</dt>
102
+ <dd>A custom callback function that will be called if set. It's only called if no images are found by any other options of the plugin. However, it will be run before the <code>default_image</code> is set. The <code>$args</code> array is passed to the callback function as the only parameter.</dd>
103
+ <dt>cache</dt>
104
+ <dd>Whether to use the WordPress Cache <acronym title="Application Programming Interface">API</acronym> (integrates with caching plugins) to serve the post images. By default, this is set to <code>true</code>.</dd>
105
  <dt>echo</dt>
106
  <dd>If set to <code>true</code>, the image is shown on the page. If set to <code>false</code>, the image will be returned to use in your own function. (Set to <code>true</code> by default.)</dd>
107
  </dl>
116
 
117
  <p><strong>Example 2:</strong> Let's suppose you want a full-sized image and maybe you want to grab it by a custom field key of <code>Feature</code>. Depending on your theme, this will need to go within the Loop in whatever file is calling the featured article.</p>
118
 
119
+ <pre><code>&lt;?php get_the_image( array( 'meta_key' => array( 'Feature' ), 'size' => 'full' ) ); ?></code></pre>
120
 
121
  <p>If no feature image exists by custom field, it will look for images attached to your post.</p>
122
 
140
 
141
  &lt;div id="post-&lt;?php the_ID(); ?>" &lt;?php post_class(); ?>>
142
 
143
+ &lt;?php get_the_image( array( 'meta_key' => array( 'feature_img' ), 'size' => 'medium', 'width' => '200', 'height' => '200', 'image_class' => 'feature' ) ); ?>
144
 
145
  &lt;h2>&lt;a href="&lt;?php the_permalink(); ?>" title="&lt;?php the_title_attribute(); ?>" rel="bookmark">&lt;?php the_title(); ?>&lt;/a>&lt;/h2>
146
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: image, images, thumbnail
5
  Requires at least: 2.9
6
  Tested up to: 3.0
7
- Stable tag: 0.5
8
 
9
  An easy-to-use image script for adding things such as thumbnails and feature images.
10
 
@@ -56,7 +56,12 @@ You can view this plugin in action on my <a href="http://justintadlock.com" titl
56
 
57
  == Changelog ==
58
 
59
- Earlier versions were not documented well.
 
 
 
 
 
60
 
61
  **Version 0.5**
62
 
4
  Tags: image, images, thumbnail
5
  Requires at least: 2.9
6
  Tested up to: 3.0
7
+ Stable tag: 0.6
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**
60
+
61
+ * Deprecated `custom_key` in favor of `meta_key`.
62
+ * Added the `meta_key_save` argument to allow users to save the image as a meta key/value pair.
63
+ * Added a `callback` argument to allow developers to create a custom callback function.
64
+ * Added a `cache` argument, which allows users to turn off caching.
65
 
66
  **Version 0.5**
67