Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 421 lines (344 sloc) 16.347 kB
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
1 <?php
2 /**
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.
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
6 * Version: 0.6.1
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
7 * Author: Justin Tadlock
8 * Author URI: http://justintadlock.com
9 *
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
10 * Get the Image - An advanced post image script for WordPress.
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
11 *
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
12 * Get the Image was created to be a highly-intuitive image script that displays post-specific images (an
13 * image-based representation of a post). The script handles old-style post images via custom fields for
14 * backwards compatibility. It also supports WordPress' built-in featured image functionality. On top of
15 * those things, it can automatically set attachment images as the post image or scan the post content for
16 * the first image element used. It can also fall back to a given default image.
17 *
18 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
19 * General Public License version 2, as published by the Free Software Foundation. You may NOT assume
20 * that you can use any other version of the GPL.
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
21 *
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
22 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
23 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
24 *
25 * @package GetTheImage
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
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
30 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
31 */
32
33 /* Adds theme support for post images. */
34 add_theme_support( 'post-thumbnails' );
35
ca5ff9c Bringing code up to version 0.5.
greenshady authored
36 /* Delete the cache when a post or post metadata is updated. */
37 add_action( 'save_post', 'get_the_image_delete_cache' );
38 add_action( 'deleted_post_meta', 'get_the_image_delete_cache' );
39 add_action( 'updated_post_meta', 'get_the_image_delete_cache' );
40 add_action( 'added_post_meta', 'get_the_image_delete_cache' );
41
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
42 /**
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
43 * The main image function for displaying an image. It supports several arguments that allow developers to
44 * customize how the script outputs the image.
45 *
46 * The image check order is important to note here. If an image is found by any specific check, the script
47 * will no longer look for images. The check order is 'meta_key', 'the_post_thumbnail', 'attachment',
48 * 'image_scan', 'callback', and 'default_image'.
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
49 *
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
50 * @since 0.1.0
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
51 * @global $post The current post's DB object.
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
52 * @param array $args Arguments for how to load and display the image.
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
53 * @return string|array The HTML for the image. | Image attributes in an array.
54 */
55 function get_the_image( $args = array() ) {
56 global $post;
57
58 /* Set the default arguments. */
59 $defaults = array(
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
60 'meta_key' => array( 'Thumbnail', 'thumbnail' ),
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
61 'post_id' => $post->ID,
62 'attachment' => true,
63 'the_post_thumbnail' => true, // WP 2.9+ image function
ca5ff9c Bringing code up to version 0.5.
greenshady authored
64 'size' => 'thumbnail',
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
65 'default_image' => false,
66 'order_of_image' => 1,
67 'link_to_post' => true,
68 'image_class' => false,
69 'image_scan' => false,
70 'width' => false,
71 'height' => false,
72 'format' => 'img',
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
73 'meta_key_save' => false,
74 'callback' => null,
75 'cache' => true,
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
76 'echo' => true,
77 'custom_key' => null, // @deprecated 0.6. Use 'meta_key'.
78 'default_size' => null, // @deprecated 0.5. Use 'size'.
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
79 );
80
81 /* Allow plugins/themes to filter the arguments. */
82 $args = apply_filters( 'get_the_image_args', $args );
83
84 /* Merge the input arguments and the defaults. */
85 $args = wp_parse_args( $args, $defaults );
86
ca5ff9c Bringing code up to version 0.5.
greenshady authored
87 /* If $default_size is given, overwrite $size. */
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
88 if ( !is_null( $args['default_size'] ) )
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
89 $args['size'] = $args['default_size']; // Deprecated 0.5 in favor of $size
90
91 /* If $custom_key is set, overwrite $meta_key. */
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
92 if ( !is_null( $args['custom_key'] ) )
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
93 $args['meta_key'] = $args['custom_key']; // Deprecated 0.6 in favor of $meta_key
ca5ff9c Bringing code up to version 0.5.
greenshady authored
94
95 /* If $format is set to 'array', don't link to the post. */
96 if ( 'array' == $args['format'] )
97 $args['link_to_post'] = false;
98
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
99 /* Extract the array to allow easy use of variables. */
100 extract( $args );
101
ca5ff9c Bringing code up to version 0.5.
greenshady authored
102 /* Check for a cached image. */
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
103 $image_cache = wp_cache_get( 'get_the_image' );
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
104
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
105 if ( !is_array( $image_cache ) )
106 $image_cache = array();
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
107
ca5ff9c Bringing code up to version 0.5.
greenshady authored
108 /* If there is no cached image, let's see if one exists. */
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
109 if ( !isset( $image_cache[$post_id][$size] ) || empty( $cache ) ) {
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
110
ca5ff9c Bringing code up to version 0.5.
greenshady authored
111 /* If a custom field key (array) is defined, check for images by custom field. */
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
112 if ( !empty( $meta_key ) )
ca5ff9c Bringing code up to version 0.5.
greenshady authored
113 $image = image_by_custom_field( $args );
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
114
ca5ff9c Bringing code up to version 0.5.
greenshady authored
115 /* If no image found and $the_post_thumbnail is set to true, check for a post image (WP feature). */
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
116 if ( empty( $image ) && !empty( $the_post_thumbnail ) )
ca5ff9c Bringing code up to version 0.5.
greenshady authored
117 $image = image_by_the_post_thumbnail( $args );
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
118
ca5ff9c Bringing code up to version 0.5.
greenshady authored
119 /* If no image found and $attachment is set to true, check for an image by attachment. */
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
120 if ( empty( $image ) && !empty( $attachment ) )
ca5ff9c Bringing code up to version 0.5.
greenshady authored
121 $image = image_by_attachment( $args );
122
123 /* If no image found and $image_scan is set to true, scan the post for images. */
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
124 if ( empty( $image ) && !empty( $image_scan ) )
ca5ff9c Bringing code up to version 0.5.
greenshady authored
125 $image = image_by_scan( $args );
126
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
127 /* If no image found and a callback function was given. */
128 if ( empty( $image ) && !is_null( $callback ) && function_exists( $callback ) )
129 $image = call_user_func( $callback, $args );
130
ca5ff9c Bringing code up to version 0.5.
greenshady authored
131 /* If no image found and a $default_image is set, get the default image. */
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
132 if ( empty( $image ) && !empty( $default_image ) )
ca5ff9c Bringing code up to version 0.5.
greenshady authored
133 $image = image_by_default( $args );
134
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
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
ca5ff9c Bringing code up to version 0.5.
greenshady authored
139 /* If an image is returned, run it through the display function. */
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
140 if ( !empty( $image ) )
ca5ff9c Bringing code up to version 0.5.
greenshady authored
141 $image = display_the_image( $args, $image );
142
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
143 $image_cache[$post_id][$size] = $image;
144 wp_cache_set( 'get_the_image', $image_cache );
ca5ff9c Bringing code up to version 0.5.
greenshady authored
145 }
146 else {
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
147 $image = $image_cache[$post_id][$size];
ca5ff9c Bringing code up to version 0.5.
greenshady authored
148 }
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
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. */
ca5ff9c Bringing code up to version 0.5.
greenshady authored
154 if ( 'array' == $format ) {
155 $atts = wp_kses_hair( $image, array( 'http' ) );
156
157 foreach ( $atts as $att )
158 $out[$att['name']] = $att['value'];
159
160 $out['url'] = $out['src']; // @deprecated 0.5 Use 'src' instead of 'url'.
161 return $out;
162 }
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
163 elseif ( !empty( $echo ) )
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
164 echo $image;
165 else
166 return $image;
167 }
168
169 /* Internal Functions */
170
171 /**
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
172 * Calls images by custom field key. Script loops through multiple custom field keys. If that particular key
173 * is found, $image is set and the loop breaks. If an image is found, it is returned.
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
174 *
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
175 * @since 0.3.0
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
176 * @param array $args
177 * @return array|bool
178 */
179 function image_by_custom_field( $args = array() ) {
180
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
181 /* If $meta_key is not an array. */
182 if ( !is_array( $args['meta_key'] ) ) {
183
184 /* Get the image URL by the single meta key. */
185 $image = get_post_meta( $args['post_id'], $args['meta_key'], true );
186 }
187
188 /* If $meta_key is an array. */
189 elseif ( is_array( $args['meta_key'] ) ) {
190
191 /* Loop through each of the given meta keys. */
192 foreach ( $args['meta_key'] as $meta_key ) {
193
194 /* Get the image URL by the current meta key in the loop. */
195 $image = get_post_meta( $args['post_id'], $meta_key, true );
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
196
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
197 /* If an image was found, break out of the loop. */
198 if ( !empty( $image ) )
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
199 break;
200 }
201 }
202
203 /* If a custom key value has been given for one of the keys, return the image URL. */
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
204 if ( !empty( $image ) )
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
205 return array( 'url' => $image );
206
207 return false;
208 }
209
210 /**
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
211 * Checks for images using a custom version of the WordPress 2.9+ get_the_post_thumbnail() function.
212 * If an image is found, return it and the $post_thumbnail_id. The WordPress function's other filters are
213 * later added in the display_the_image() function.
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
214 *
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
215 * @since 0.4.0
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
216 * @param array $args
217 * @return array|bool
218 */
219 function image_by_the_post_thumbnail( $args = array() ) {
220
221 /* Check for a post image ID (set by WP as a custom field). */
222 $post_thumbnail_id = get_post_thumbnail_id( $args['post_id'] );
223
224 /* If no post image ID is found, return false. */
225 if ( empty( $post_thumbnail_id ) )
226 return false;
227
228 /* Apply filters on post_thumbnail_size because this is a default WP filter used with its image feature. */
ca5ff9c Bringing code up to version 0.5.
greenshady authored
229 $size = apply_filters( 'post_thumbnail_size', $args['size'] );
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
230
231 /* Get the attachment image source. This should return an array. */
232 $image = wp_get_attachment_image_src( $post_thumbnail_id, $size );
233
ca5ff9c Bringing code up to version 0.5.
greenshady authored
234 /* Get the attachment excerpt to use as alt text. */
235 $alt = trim( strip_tags( get_post_field( 'post_excerpt', $post_thumbnail_id ) ) );
236
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
237 /* Return both the image URL and the post thumbnail ID. */
ca5ff9c Bringing code up to version 0.5.
greenshady authored
238 return array( 'url' => $image[0], 'post_thumbnail_id' => $post_thumbnail_id, 'alt' => $alt );
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
239 }
240
241 /**
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
242 * Check for attachment images. Uses get_children() to check if the post has images attached. If image
243 * attachments are found, loop through each. The loop only breaks once $order_of_image is reached.
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
244 *
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
245 * @since 0.3.0
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
246 * @param array $args
247 * @return array|bool
248 */
249 function image_by_attachment( $args = array() ) {
250
251 /* Get attachments for the inputted $post_id. */
252 $attachments = get_children( array( 'post_parent' => $args['post_id'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) );
253
ca5ff9c Bringing code up to version 0.5.
greenshady authored
254 /* If no attachments are found, check if the post itself is an attachment and grab its image. */
255 if ( empty( $attachments ) && $args['size'] ) {
256 if ( 'attachment' == get_post_type( $args['post_id'] ) ) {
257 $image = wp_get_attachment_image_src( $args['post_id'], $args['size'] );
258 $alt = trim( strip_tags( get_post_field( 'post_excerpt', $args['post_id'] ) ) );
259 }
260 }
261
262 /* If no attachments or image is found, return false. */
263 if ( empty( $attachments ) && empty( $image ) )
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
264 return false;
265
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
266 /* Set the default iterator to 0. */
267 $i = 0;
268
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
269 /* Loop through each attachment. Once the $order_of_image (default is '1') is reached, break the loop. */
270 foreach ( $attachments as $id => $attachment ) {
271 if ( ++$i == $args['order_of_image'] ) {
ca5ff9c Bringing code up to version 0.5.
greenshady authored
272 $image = wp_get_attachment_image_src( $id, $args['size'] );
273 $alt = trim( strip_tags( get_post_field( 'post_excerpt', $id ) ) );
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
274 break;
275 }
276 }
277
278 /* Return the image URL. */
ca5ff9c Bringing code up to version 0.5.
greenshady authored
279 return array( 'url' => $image[0], 'alt' => $alt );
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
280 }
281
282 /**
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
283 * Scans the post for images within the content. Not called by default with get_the_image(). Shouldn't use
284 * if using large images within posts, better to use the other options.
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
285 *
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
286 * @since 0.3.0
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
287 * @global $post The current post's DB object.
288 * @param array $args
289 * @return array|bool
290 */
291 function image_by_scan( $args = array() ) {
292
293 /* Search the post's content for the <img /> tag and get its URL. */
294 preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i', get_post_field( 'post_content', $args['post_id'] ), $matches );
295
296 /* If there is a match for the image, return its URL. */
297 if ( isset( $matches ) && $matches[1][0] )
298 return array( 'url' => $matches[1][0] );
299
300 return false;
301 }
302
303 /**
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
304 * Used for setting a default image. The function simply returns the image URL it was given in an array.
305 * Not used with get_the_image() by default.
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
306 *
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
307 * @since 0.3.0
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
308 * @param array $args
309 * @return array
310 */
311 function image_by_default( $args = array() ) {
312 return array( 'url' => $args['default_image'] );
313 }
314
315 /**
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
316 * Formats an image with appropriate alt text and class. Adds a link to the post if argument is set. Should
317 * only be called if there is an image to display, but will handle it if not.
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
318 *
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
319 * @since 0.1.0
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
320 * @param array $args
321 * @param array $image Array of image info ($image, $classes, $alt, $caption).
322 * @return string $image Formatted image (w/link to post if the option is set).
323 */
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. */
331 extract( $args );
332
ca5ff9c Bringing code up to version 0.5.
greenshady authored
333 /* If there is alt text, set it. Otherwise, default to the post title. */
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
334 $image_alt = ( ( !empty( $image['alt'] ) ) ? $image['alt'] : apply_filters( 'the_title', get_post_field( 'post_title', $post_id ) ) );
ca5ff9c Bringing code up to version 0.5.
greenshady authored
335
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
336 /* If there is a width or height, set them as HMTL-ready attributes. */
ca5ff9c Bringing code up to version 0.5.
greenshady authored
337 $width = ( ( $width ) ? ' width="' . esc_attr( $width ) . '"' : '' );
338 $height = ( ( $height ) ? ' height="' . esc_attr( $height ) . '"' : '' );
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
339
340 /* Loop through the custom field keys and add them as classes. */
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
341 if ( is_array( $meta_key ) ) {
342 foreach ( $meta_key as $key )
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
343 $classes[] = str_replace( ' ', '-', strtolower( $key ) );
344 }
345
ca5ff9c Bringing code up to version 0.5.
greenshady authored
346 /* Add the $size and any user-added $image_class to the class. */
347 $classes[] = $size;
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
348 $classes[] = $image_class;
349
ca5ff9c Bringing code up to version 0.5.
greenshady authored
350 /* Join all the classes into a single string and make sure there are no duplicates. */
351 $class = join( ' ', array_unique( $classes ) );
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
352
353 /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
354 if ( !empty( $image['post_thumbnail_id'] ) )
ca5ff9c Bringing code up to version 0.5.
greenshady authored
355 do_action( 'begin_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $size );
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
356
357 /* Add the image attributes to the <img /> element. */
ca5ff9c Bringing code up to version 0.5.
greenshady authored
358 $html = '<img src="' . $image['url'] . '" alt="' . esc_attr( strip_tags( $image_alt ) ) . '" class="' . esc_attr( $class ) . '"' . $width . $height . ' />';
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
359
360 /* If $link_to_post is set to true, link the image to its post. */
361 if ( $link_to_post )
ca5ff9c Bringing code up to version 0.5.
greenshady authored
362 $html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( apply_filters( 'the_title', get_post_field( 'post_title', $post_id ) ) ) . '">' . $html . '</a>';
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
363
364 /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
365 if ( !empty( $image['post_thumbnail_id'] ) )
ca5ff9c Bringing code up to version 0.5.
greenshady authored
366 do_action( 'end_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $size );
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
367
368 /* If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail(). */
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
369 if ( !empty( $image['post_thumbnail_id'] ) )
ca5ff9c Bringing code up to version 0.5.
greenshady authored
370 $html = apply_filters( 'post_thumbnail_html', $html, $post_id, $image['post_thumbnail_id'], $size, '' );
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
371
372 return $html;
373 }
374
375 /**
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
376 * Saves the image URL as the value of the meta key provided. This allows users to set a custom meta key
377 * for their image. By doing this, users can trim off database queries when grabbing attachments or get rid
378 * of expensive scans of the content when using the image scan feature.
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
379 *
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
380 * @since 0.6.0
ecc26c2 Deprecated custom_key in favor of meta_key.
greenshady authored
381 * @param array $args Parameters for what image to get.
382 * @param array $image Array of image info ($image, $classes, $alt, $caption).
383 */
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. */
391 $meta = get_post_meta( $args['post_id'], $args['meta_key_save'], true );
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 /**
ca5ff9c Bringing code up to version 0.5.
greenshady authored
403 * Deletes the image cache for users that are using a persistent-caching plugin.
404 *
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
405 * @since 0.5.0
ca5ff9c Bringing code up to version 0.5.
greenshady authored
406 */
407 function get_the_image_delete_cache() {
408 wp_cache_delete( 'get_the_image' );
409 }
410
411 /**
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
412 * Get the image with a link to the post. Use get_the_image() instead.
413 *
7d49016 Bringing this up to 0.6.1 standards.
greenshady authored
414 * @since 0.1.0
415 * @deprecated 0.3.0
4c2ae75 Importing the files and folders for the Get the Image plugin.
greenshady authored
416 */
417 function get_the_image_link( $deprecated = '', $deprecated_2 = '', $deprecated_3 = '' ) {
418 get_the_image();
419 }
420
421 ?>
Something went wrong with that request. Please try again.