Version Description
Download this release
Release Info
Developer | greenshady |
Plugin | Get the Image |
Version | 0.8.1 |
Comparing to | |
See all releases |
Code changes from version 0.8 to 0.8.1
- get-the-image.php +47 -47
- readme.html +22 -22
- readme.txt +13 -4
get-the-image.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Get The Image
|
4 |
* Plugin URI: http://themehybrid.com/plugins/get-the-image
|
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.8
|
7 |
* Author: Justin Tadlock
|
8 |
* Author URI: http://justintadlock.com
|
9 |
*
|
@@ -16,18 +16,18 @@
|
|
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
|
20 |
-
*
|
21 |
*
|
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.
|
24 |
*
|
25 |
-
* @package
|
26 |
-
* @version
|
27 |
-
* @author
|
28 |
* @copyright Copyright (c) 2008 - 2012, Justin Tadlock
|
29 |
-
* @link
|
30 |
-
* @license
|
31 |
*/
|
32 |
|
33 |
/* Adds theme support for WordPress 'featured images'. */
|
@@ -57,28 +57,28 @@ function get_the_image( $args = array() ) {
|
|
57 |
|
58 |
/* Set the default arguments. */
|
59 |
$defaults = array(
|
60 |
-
'meta_key'
|
61 |
-
'post_id'
|
62 |
-
'attachment'
|
63 |
-
'the_post_thumbnail' =>
|
64 |
-
'size'
|
65 |
-
'default_image'
|
66 |
-
'order_of_image'
|
67 |
-
'link_to_post'
|
68 |
-
'image_class'
|
69 |
-
'image_scan'
|
70 |
-
'width'
|
71 |
-
'height'
|
72 |
-
'format'
|
73 |
-
'meta_key_save'
|
74 |
-
'thumbnail_id_save'
|
75 |
-
'callback'
|
76 |
-
'cache'
|
77 |
-
'before'
|
78 |
-
'after'
|
79 |
-
'echo'
|
80 |
-
'custom_key'
|
81 |
-
'default_size'
|
82 |
);
|
83 |
|
84 |
/* Allow plugins/themes to filter the arguments. */
|
@@ -115,7 +115,7 @@ function get_the_image( $args = array() ) {
|
|
115 |
$image_html = '';
|
116 |
|
117 |
/* If there is no cached image, let's see if one exists. */
|
118 |
-
if ( !isset( $image_cache[$key] ) || empty( $cache ) ) {
|
119 |
|
120 |
/* If a custom field key (array) is defined, check for images by custom field. */
|
121 |
if ( !empty( $meta_key ) )
|
@@ -146,13 +146,13 @@ function get_the_image( $args = array() ) {
|
|
146 |
|
147 |
/* If $meta_key_save was set, save the image to a custom field. */
|
148 |
if ( !empty( $meta_key_save ) )
|
149 |
-
get_the_image_meta_key_save( $args, $image
|
150 |
|
151 |
/* Format the image HTML. */
|
152 |
$image_html = get_the_image_format( $args, $image );
|
153 |
|
154 |
/* Set the image cache for the specific post. */
|
155 |
-
$image_cache[$key] = $image_html;
|
156 |
wp_cache_set( $post_id, $image_cache, 'get_the_image' );
|
157 |
}
|
158 |
}
|
@@ -176,7 +176,7 @@ function get_the_image( $args = array() ) {
|
|
176 |
|
177 |
/* Loop through the image attributes and add them in key/value pairs for the return array. */
|
178 |
foreach ( $atts as $att )
|
179 |
-
$out[$att['name']] = $att['value'];
|
180 |
|
181 |
$out['url'] = $out['src']; // @deprecated 0.5 Use 'src' instead of 'url'.
|
182 |
|
@@ -186,7 +186,7 @@ function get_the_image( $args = array() ) {
|
|
186 |
|
187 |
/* Or, if $echo is set to false, return the formatted image. */
|
188 |
elseif ( false === $echo ) {
|
189 |
-
return $args['before'] . $image_html . $args['after'];
|
190 |
}
|
191 |
|
192 |
/* If there is a $post_thumbnail_id, do the actions associated with get_the_post_thumbnail(). */
|
@@ -194,7 +194,7 @@ function get_the_image( $args = array() ) {
|
|
194 |
do_action( 'begin_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $size );
|
195 |
|
196 |
/* Display the image if we get to this point. */
|
197 |
-
echo $args['before'] . $image_html . $args['after'];
|
198 |
|
199 |
/* If there is a $post_thumbnail_id, do the actions associated with get_the_post_thumbnail(). */
|
200 |
if ( isset( $image['post_thumbnail_id'] ) )
|
@@ -204,8 +204,8 @@ function get_the_image( $args = array() ) {
|
|
204 |
/* Internal Functions */
|
205 |
|
206 |
/**
|
207 |
-
* Calls images by custom field key. Script loops through multiple custom field keys. If that particular
|
208 |
-
* is found, $image is set and the loop breaks. If an image is found, it is returned.
|
209 |
*
|
210 |
* @since 0.7.0
|
211 |
* @access private
|
@@ -293,12 +293,12 @@ function get_the_image_by_attachment( $args = array() ) {
|
|
293 |
/* Get attachments for the inputted $post_id. */
|
294 |
$attachments = get_children(
|
295 |
array(
|
296 |
-
'post_parent'
|
297 |
-
'post_status'
|
298 |
-
'post_type'
|
299 |
-
'post_mime_type'
|
300 |
-
'order'
|
301 |
-
'orderby'
|
302 |
'suppress_filters' => true
|
303 |
)
|
304 |
);
|
@@ -326,14 +326,14 @@ function get_the_image_by_attachment( $args = array() ) {
|
|
326 |
if ( !empty( $attachment_id ) ) {
|
327 |
|
328 |
/* Get the attachment image. */
|
329 |
-
$image = wp_get_attachment_image_src( $
|
330 |
|
331 |
/* Get the attachment excerpt. */
|
332 |
-
$alt = trim( strip_tags( get_post_field( 'post_excerpt', $
|
333 |
|
334 |
/* Save the attachment as the 'featured image'. */
|
335 |
if ( true === $args['thumbnail_id_save'] )
|
336 |
-
set_post_thumbnail( $args['post_id'], $
|
337 |
|
338 |
/* Return the image URL. */
|
339 |
return array( 'src' => $image[0], 'alt' => $alt );
|
3 |
* Plugin Name: Get The Image
|
4 |
* Plugin URI: http://themehybrid.com/plugins/get-the-image
|
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.8.1
|
7 |
* Author: Justin Tadlock
|
8 |
* Author URI: http://justintadlock.com
|
9 |
*
|
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 as published by the Free Software Foundation; either version 2 of the License,
|
20 |
+
* or (at your option) any later version.
|
21 |
*
|
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.
|
24 |
*
|
25 |
+
* @package GetTheImage
|
26 |
+
* @version 0.8.1
|
27 |
+
* @author Justin Tadlock <justin@justintadlock.com>
|
28 |
* @copyright Copyright (c) 2008 - 2012, 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
|
31 |
*/
|
32 |
|
33 |
/* Adds theme support for WordPress 'featured images'. */
|
57 |
|
58 |
/* Set the default arguments. */
|
59 |
$defaults = array(
|
60 |
+
'meta_key' => array( 'Thumbnail', 'thumbnail' ), // array|string
|
61 |
+
'post_id' => get_the_ID(),
|
62 |
+
'attachment' => true,
|
63 |
+
'the_post_thumbnail' => true, // WP 2.9+ image function
|
64 |
+
'size' => 'thumbnail',
|
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',
|
73 |
+
'meta_key_save' => false,
|
74 |
+
'thumbnail_id_save' => false, // Set 'featured image'.
|
75 |
+
'callback' => null,
|
76 |
+
'cache' => true,
|
77 |
+
'before' => '',
|
78 |
+
'after' => '',
|
79 |
+
'echo' => true,
|
80 |
+
'custom_key' => null, // @deprecated 0.6. Use 'meta_key'.
|
81 |
+
'default_size' => null, // @deprecated 0.5. Use 'size'.
|
82 |
);
|
83 |
|
84 |
/* Allow plugins/themes to filter the arguments. */
|
115 |
$image_html = '';
|
116 |
|
117 |
/* If there is no cached image, let's see if one exists. */
|
118 |
+
if ( !isset( $image_cache[ $key ] ) || empty( $cache ) ) {
|
119 |
|
120 |
/* If a custom field key (array) is defined, check for images by custom field. */
|
121 |
if ( !empty( $meta_key ) )
|
146 |
|
147 |
/* If $meta_key_save was set, save the image to a custom field. */
|
148 |
if ( !empty( $meta_key_save ) )
|
149 |
+
get_the_image_meta_key_save( $args, $image );
|
150 |
|
151 |
/* Format the image HTML. */
|
152 |
$image_html = get_the_image_format( $args, $image );
|
153 |
|
154 |
/* Set the image cache for the specific post. */
|
155 |
+
$image_cache[ $key ] = $image_html;
|
156 |
wp_cache_set( $post_id, $image_cache, 'get_the_image' );
|
157 |
}
|
158 |
}
|
176 |
|
177 |
/* Loop through the image attributes and add them in key/value pairs for the return array. */
|
178 |
foreach ( $atts as $att )
|
179 |
+
$out[ $att['name'] ] = $att['value'];
|
180 |
|
181 |
$out['url'] = $out['src']; // @deprecated 0.5 Use 'src' instead of 'url'.
|
182 |
|
186 |
|
187 |
/* Or, if $echo is set to false, return the formatted image. */
|
188 |
elseif ( false === $echo ) {
|
189 |
+
return !empty( $image_html ) ? $args['before'] . $image_html . $args['after'] : $image_html;
|
190 |
}
|
191 |
|
192 |
/* If there is a $post_thumbnail_id, do the actions associated with get_the_post_thumbnail(). */
|
194 |
do_action( 'begin_fetch_post_thumbnail_html', $post_id, $image['post_thumbnail_id'], $size );
|
195 |
|
196 |
/* Display the image if we get to this point. */
|
197 |
+
echo !empty( $image_html ) ? $args['before'] . $image_html . $args['after'] : $image_html;
|
198 |
|
199 |
/* If there is a $post_thumbnail_id, do the actions associated with get_the_post_thumbnail(). */
|
200 |
if ( isset( $image['post_thumbnail_id'] ) )
|
204 |
/* Internal Functions */
|
205 |
|
206 |
/**
|
207 |
+
* Calls images by custom field key. Script loops through multiple custom field keys. If that particular
|
208 |
+
* key is found, $image is set and the loop breaks. If an image is found, it is returned.
|
209 |
*
|
210 |
* @since 0.7.0
|
211 |
* @access private
|
293 |
/* Get attachments for the inputted $post_id. */
|
294 |
$attachments = get_children(
|
295 |
array(
|
296 |
+
'post_parent' => $args['post_id'],
|
297 |
+
'post_status' => 'inherit',
|
298 |
+
'post_type' => 'attachment',
|
299 |
+
'post_mime_type' => 'image',
|
300 |
+
'order' => 'ASC',
|
301 |
+
'orderby' => 'menu_order ID',
|
302 |
'suppress_filters' => true
|
303 |
)
|
304 |
);
|
326 |
if ( !empty( $attachment_id ) ) {
|
327 |
|
328 |
/* Get the attachment image. */
|
329 |
+
$image = wp_get_attachment_image_src( $attachment_id, $args['size'] );
|
330 |
|
331 |
/* Get the attachment excerpt. */
|
332 |
+
$alt = trim( strip_tags( get_post_field( 'post_excerpt', $attachment_id ) ) );
|
333 |
|
334 |
/* Save the attachment as the 'featured image'. */
|
335 |
if ( true === $args['thumbnail_id_save'] )
|
336 |
+
set_post_thumbnail( $args['post_id'], $attachment_id );
|
337 |
|
338 |
/* Return the image URL. */
|
339 |
return array( 'src' => $image[0], 'alt' => $alt );
|
readme.html
CHANGED
@@ -50,28 +50,28 @@
|
|
50 |
<p>By simply making a function call to <code><?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'
|
54 |
-
'post_id'
|
55 |
-
'attachment'
|
56 |
'the_post_thumbnail' => true, // WP 2.9+ image function
|
57 |
-
'size'
|
58 |
-
'default_image'
|
59 |
-
'order_of_image'
|
60 |
-
'link_to_post'
|
61 |
-
'image_class'
|
62 |
-
'image_scan'
|
63 |
-
'width'
|
64 |
-
'height'
|
65 |
-
'format'
|
66 |
-
'meta_key_save'
|
67 |
-
'thumbnail_id_save'
|
68 |
-
'callback'
|
69 |
-
'cache'
|
70 |
-
'before'
|
71 |
-
'after'
|
72 |
-
'echo'
|
73 |
-
'custom_key'
|
74 |
-
'default_size'
|
75 |
);</code></pre>
|
76 |
|
77 |
<dl>
|
@@ -214,7 +214,7 @@ img.thumbnail { }</code></pre>
|
|
214 |
|
215 |
<p>This plugin is copyrighted to <a href="http://justintadlock.com" title="Justin Tadlock">Justin Tadlock</a>.</p>
|
216 |
|
217 |
-
<p>2008 – 2012 © Justin Tadlock
|
218 |
|
219 |
</body>
|
220 |
</html>
|
50 |
<p>By simply making a function call to <code><?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' ), // array|string
|
54 |
+
'post_id' => get_the_ID(),
|
55 |
+
'attachment' => true,
|
56 |
'the_post_thumbnail' => true, // WP 2.9+ image function
|
57 |
+
'size' => 'thumbnail',
|
58 |
+
'default_image' => false,
|
59 |
+
'order_of_image' => 1,
|
60 |
+
'link_to_post' => true,
|
61 |
+
'image_class' => false,
|
62 |
+
'image_scan' => false,
|
63 |
+
'width' => false,
|
64 |
+
'height' => false,
|
65 |
+
'format' => 'img',
|
66 |
+
'meta_key_save' => false,
|
67 |
+
'thumbnail_id_save' => false, // Set 'featured image'.
|
68 |
+
'callback' => null,
|
69 |
+
'cache' => true,
|
70 |
+
'before' => '',
|
71 |
+
'after' => '',
|
72 |
+
'echo' => true,
|
73 |
+
'custom_key' => null, // @deprecated 0.6. Use 'meta_key'.
|
74 |
+
'default_size' => null, // @deprecated 0.5. Use 'size'.
|
75 |
);</code></pre>
|
76 |
|
77 |
<dl>
|
214 |
|
215 |
<p>This plugin is copyrighted to <a href="http://justintadlock.com" title="Justin Tadlock">Justin Tadlock</a>.</p>
|
216 |
|
217 |
+
<p>2008 – 2012 © Justin Tadlock..</p>
|
218 |
|
219 |
</body>
|
220 |
</html>
|
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
=== Get the Image ===
|
2 |
Contributors: greenshady
|
3 |
-
Donate link:
|
4 |
Tags: image, images, thumbnail
|
5 |
Requires at least: 3.2
|
6 |
-
Tested up to: 3.
|
7 |
-
Stable tag: 0.8
|
8 |
|
9 |
An easy-to-use image script for adding things such as thumbnails and feature images.
|
10 |
|
@@ -14,6 +14,8 @@ An easy-to-use image script for adding things such as thumbnails and feature ima
|
|
14 |
|
15 |
This is a highly intuitive script that can grab an image by custom field input, WP's post image feature, post attachment, or extracting it from the post's content.
|
16 |
|
|
|
|
|
17 |
== Installation ==
|
18 |
|
19 |
1. Upload `get-the-image` to the `/wp-content/plugins/` directory.
|
@@ -35,7 +37,7 @@ This plugin was created to be a lightweight solution to handle a very powerful n
|
|
35 |
= How does it pull images? =
|
36 |
|
37 |
1. Looks for an image by custom field (one of your choosing).
|
38 |
-
1. If no image is added by custom field, check for an image using `the_post_thumbnail()` (
|
39 |
1. If no image is found, it grabs an image attached to your post.
|
40 |
1. If no image is attached, it can extract an image from your post content (off by default).
|
41 |
1. If no image is found at this point, it will default to an image you set (not set by default).
|
@@ -56,6 +58,13 @@ You can view this plugin in action on my <a href="http://justintadlock.com" titl
|
|
56 |
|
57 |
== Changelog ==
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
**Version 0.8**
|
60 |
|
61 |
* Inline docs updates.
|
1 |
=== Get the Image ===
|
2 |
Contributors: greenshady
|
3 |
+
Donate link: http://themehybrid.com/donate
|
4 |
Tags: image, images, thumbnail
|
5 |
Requires at least: 3.2
|
6 |
+
Tested up to: 3.5
|
7 |
+
Stable tag: 0.8.1
|
8 |
|
9 |
An easy-to-use image script for adding things such as thumbnails and feature images.
|
10 |
|
14 |
|
15 |
This is a highly intuitive script that can grab an image by custom field input, WP's post image feature, post attachment, or extracting it from the post's content.
|
16 |
|
17 |
+
Support for this plugin is handled on the Theme Hybrid <a href="http://themehybrid.com/support">support forums</a>.
|
18 |
+
|
19 |
== Installation ==
|
20 |
|
21 |
1. Upload `get-the-image` to the `/wp-content/plugins/` directory.
|
37 |
= How does it pull images? =
|
38 |
|
39 |
1. Looks for an image by custom field (one of your choosing).
|
40 |
+
1. If no image is added by custom field, check for an image using `the_post_thumbnail()` (WordPress featured image).
|
41 |
1. If no image is found, it grabs an image attached to your post.
|
42 |
1. If no image is attached, it can extract an image from your post content (off by default).
|
43 |
1. If no image is found at this point, it will default to an image you set (not set by default).
|
58 |
|
59 |
== Changelog ==
|
60 |
|
61 |
+
**Version 0.8.1**
|
62 |
+
|
63 |
+
* Use correct `$attachment_id` variable instead of `$id`.
|
64 |
+
* Pass full `$image` array to the `get_the_image_meta_key_save()` function so that it saves correctly.
|
65 |
+
* Only use `before` and `after` arguments if an image is found.
|
66 |
+
* General code formatting updated.
|
67 |
+
|
68 |
**Version 0.8**
|
69 |
|
70 |
* Inline docs updates.
|