Version Description
Download this release
Release Info
Developer | greenshady |
Plugin | Get the Image |
Version | 1.1.0 |
Comparing to | |
See all releases |
Code changes from version 1.0.1 to 1.1.0
- changelog.md +206 -0
- contributing.md +31 -0
- get-the-image.php +339 -176
- license.txt → license.md +0 -0
- readme.md +146 -233
- readme.txt +27 -144
changelog.md
ADDED
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Change Log
|
2 |
+
|
3 |
+
## [1.1.0] - 2017-09-22
|
4 |
+
|
5 |
+
### Added
|
6 |
+
|
7 |
+
* New `srcset_sizes` argument for adding an array of `'image-size' => 'descriptor'` key/value pairs, which handles responsive images.
|
8 |
+
* New `link` argument that can be set to `post` (links to post), `file` (links to image file), `attachment` (links to attachment page if image is attachment), or `false` to link to nothing.
|
9 |
+
* New `link_class` argument to add a custom HTML class to the wrapping link element.
|
10 |
+
* Image classes based on the content width vs. the image width (`cw-equal`, `cw-lesser`, `cw-greater`).
|
11 |
+
* `min_width` argument to only show image if it meets the minimum width provided.
|
12 |
+
* `min_height` argument to only show image if it meets the minimum height provided.
|
13 |
+
* Introduces the `image_attr` argument, which allows developers to pass in an array of attributes that they want applied to `<img>` tag.
|
14 |
+
|
15 |
+
### Changed
|
16 |
+
|
17 |
+
* New `get_image_attr()` and `get_image_class()` methods were added to split off and clean up the code for getting the image attributes and classes.
|
18 |
+
|
19 |
+
### Deprecated
|
20 |
+
|
21 |
+
* Deprecated the `link_to_post` argument in favor of the new `link` argument.
|
22 |
+
|
23 |
+
## [1.0.1]
|
24 |
+
|
25 |
+
### Fixed
|
26 |
+
|
27 |
+
* Changed priority of `split_content` filter to make sure images are split from the content.
|
28 |
+
|
29 |
+
## [1.0.0]
|
30 |
+
|
31 |
+
### Added
|
32 |
+
|
33 |
+
* Re-coded how the image script works by encapsulating the functionality into a single class rather than multiple functions. This makes it much easier to reuse code and paves the way for more improvements in the future.
|
34 |
+
* New `scan_raw` argument for pulling an image (straight HTML) directly from the post content.
|
35 |
+
* New `split_content` argument for removing an image from the post content if one is found. Used only in conjunction with the `scan_raw` argument.
|
36 |
+
* New `order` argument for changing the order in which the script looks for images.
|
37 |
+
* Better support and handling for sub-attachments (e.g., featured images for audio/video attachments).
|
38 |
+
* Support for Schema.org microdata. `itemprop="image"` attribute added to image outputs where possible.
|
39 |
+
* New image orientation class if the width and height are available. Class can be `landscape` or `portrait`.
|
40 |
+
* Default image size is `post-thumbnail` if the theme has set this size. Otherwise, `thumbnail` is the default size.
|
41 |
+
* Supports the ability to get embedded images via WordPress' image embeds (Instagram, Flickr, etc.) via the `scan*` methods.
|
42 |
+
* New filter hook: `get_the_image_post_content`. Used when checking the post content.
|
43 |
+
* Added `min_width` and `min_height` arguments (doesn't work with `scan*` methods).
|
44 |
+
|
45 |
+
### Changed
|
46 |
+
|
47 |
+
* `the_post_thumbnail` argument deprecated in favor of `featured`.
|
48 |
+
* `image_scan` argument deprecated in favor of `scan` or `scan_raw`.
|
49 |
+
* `default_image` argument deprecated in favor of `default`.
|
50 |
+
* `order_of_image` argument removed with no replacement.
|
51 |
+
|
52 |
+
## [0.9.0]
|
53 |
+
|
54 |
+
### Added
|
55 |
+
|
56 |
+
* Caption support. FTW!
|
57 |
+
* Multiple image classes now allowed via the `image_class` argument.
|
58 |
+
* Use current theme's `post-thumbnail` as default image size if set via `set_post_thumbnail_size()`.
|
59 |
+
|
60 |
+
### Fixed
|
61 |
+
|
62 |
+
* Use the WordPress-saved attachment alt text for the image.
|
63 |
+
* Only add `$out['src']` if `$out['url']` is set when returning as an array.
|
64 |
+
* Allow `https` when returning as an array.
|
65 |
+
* Use the correct variable (`$attachment_id`) when getting an image via attachment.
|
66 |
+
|
67 |
+
## [0.8.1]
|
68 |
+
|
69 |
+
### Changed
|
70 |
+
|
71 |
+
* General code formatting updated.
|
72 |
+
|
73 |
+
### Fixed
|
74 |
+
|
75 |
+
* Use correct `$attachment_id` variable instead of `$id`.
|
76 |
+
* Pass full `$image` array to the `get_the_image_meta_key_save()` function so that it saves correctly.
|
77 |
+
* Only use `before` and `after` arguments if an image is found.
|
78 |
+
|
79 |
+
## [0.8.0]
|
80 |
+
|
81 |
+
### Added
|
82 |
+
|
83 |
+
* Added the `before` argument to output HTML before the image.
|
84 |
+
* Added the `after` argument to output HTML after the image.
|
85 |
+
* Added the `thumbnail_id_save` argument to allow the attached image to be saved as the thumbnail/featured image.
|
86 |
+
|
87 |
+
### Changed
|
88 |
+
|
89 |
+
* Inline docs updates.
|
90 |
+
* Get the post ID via `get_the_ID()` rather than the global `$post` object.
|
91 |
+
* Simplified the `meta_key` logic.
|
92 |
+
* Completely rewrote the `attachment` logic.
|
93 |
+
* Sanitize classes with `sanitize_html_class()`.
|
94 |
+
|
95 |
+
### Fixed
|
96 |
+
|
97 |
+
* Fixed debug notice with `$image_html`.
|
98 |
+
* Moved the `*_fetch_post_thumbnail_html` hooks into the main function and only fire them if displaying to the screen.
|
99 |
+
|
100 |
+
## [0.7.0]
|
101 |
+
|
102 |
+
### Added
|
103 |
+
|
104 |
+
* New cache delete functions that delete when a post or post meta is updated.
|
105 |
+
|
106 |
+
### Fixed
|
107 |
+
|
108 |
+
* Fixed notice when `image_scan` was used.
|
109 |
+
|
110 |
+
### Deprecated
|
111 |
+
|
112 |
+
* Deprecated and replaced functions that lacked the `get_the_image_` prefix.
|
113 |
+
|
114 |
+
## [0.6.2]
|
115 |
+
|
116 |
+
### Changed
|
117 |
+
|
118 |
+
* Minor code adjustments.
|
119 |
+
|
120 |
+
### Fixed
|
121 |
+
|
122 |
+
* Updated the cache to save by post ID instead of a single object.
|
123 |
+
|
124 |
+
## [0.6.1]
|
125 |
+
|
126 |
+
### Changed
|
127 |
+
|
128 |
+
* Updated inline documentation of the code.
|
129 |
+
* Smarter `meta_key` logic, which allows a single meta key or an array of keys to be used.
|
130 |
+
* Set `custom_key` and `default_size` to `null` by default since they're deprecated.
|
131 |
+
|
132 |
+
## [0.6.0]
|
133 |
+
|
134 |
+
### Added
|
135 |
+
|
136 |
+
* Added the `meta_key_save` argument to allow users to save the image as a meta key/value pair.
|
137 |
+
* Added a `callback` argument to allow developers to create a custom callback function.
|
138 |
+
* Added a `cache` argument, which allows users to turn off caching.
|
139 |
+
|
140 |
+
### Deprecated
|
141 |
+
|
142 |
+
* Deprecated `custom_key` in favor of `meta_key`.
|
143 |
+
|
144 |
+
## [0.5.0]
|
145 |
+
|
146 |
+
### Added
|
147 |
+
|
148 |
+
* Added support for persistent-caching plugins.
|
149 |
+
|
150 |
+
### Changed
|
151 |
+
|
152 |
+
* Switched the `default_size` argument to `size` to be more in line with the WordPress post thumbnail arguments, but `default_size` will still work.
|
153 |
+
* Now using `wp_kses_hair()` to extract image attributes when using the `array` value for `format`.
|
154 |
+
* Image `alt` text will now use the attachment description if one has been given rather than the post title.
|
155 |
+
* Updated the `readme.html` instructions for using the plugin.
|
156 |
+
|
157 |
+
## [0.4.0]
|
158 |
+
|
159 |
+
### Added
|
160 |
+
|
161 |
+
* Added support for `the_post_thumbnail()`, which is WordPress 2.9's new image functionality.
|
162 |
+
* New function: `image_by_the_post_thumbnail()`.
|
163 |
+
* Documented more of the code, so the inline PHP doc is updated.
|
164 |
+
|
165 |
+
### Changed
|
166 |
+
|
167 |
+
* Dropped support for older versions of WordPress. Now only compatible with 2.9+.
|
168 |
+
* Cleaned up some of the old legacy code that's no longer needed.
|
169 |
+
|
170 |
+
## [0.3.3]
|
171 |
+
|
172 |
+
### Added
|
173 |
+
|
174 |
+
* Added the `get_the_image` filter hook.
|
175 |
+
|
176 |
+
### Changed
|
177 |
+
|
178 |
+
* General code cleanup
|
179 |
+
|
180 |
+
## [0.3.2]
|
181 |
+
|
182 |
+
### Added
|
183 |
+
|
184 |
+
* Beefed up the inline documentation so developers can better understand the code.
|
185 |
+
* Added a GPL license.txt file.
|
186 |
+
|
187 |
+
### Changed
|
188 |
+
|
189 |
+
* General code cleanup.
|
190 |
+
* More efficient and logical code.
|
191 |
+
|
192 |
+
## [0.3.1]
|
193 |
+
|
194 |
+
### Fixed
|
195 |
+
|
196 |
+
* Fixed the default image and image scan features.
|
197 |
+
|
198 |
+
## [0.3.0]
|
199 |
+
|
200 |
+
### Added
|
201 |
+
|
202 |
+
* Added more parameters.
|
203 |
+
|
204 |
+
### Changed
|
205 |
+
|
206 |
+
* Changed methods of calling the image script.
|
contributing.md
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Contributing
|
2 |
+
|
3 |
+
The code for the project is handled via its [GitHub Repository](https://github.com/justintadlock/get-the-image). You can open tickets, create patches, and send pull requests there.
|
4 |
+
|
5 |
+
## Pull requests
|
6 |
+
|
7 |
+
Problem first. Solution second.
|
8 |
+
|
9 |
+
Pull requests should have a ticket open for discussion first. I rarely accept pull requests that aren't for a specific issue for various reasons. It's far better to post an issue and let me or the community provide feedback prior to creating a pull request.
|
10 |
+
|
11 |
+
Please don't make pull requests against the `master` branch. This is the latest, stable code. You can make a pull request against one of the point branches or the `dev` (future release) branch.
|
12 |
+
|
13 |
+
## Coding standards
|
14 |
+
|
15 |
+
In general, the project follows all WordPress [coding standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards). There are instances where it doesn't, opting for personal choices of my own, but in terms of contributing, following the WordPress standards is best practice.
|
16 |
+
|
17 |
+
## Script and style files
|
18 |
+
|
19 |
+
When making patches or pull requests with changes to script or style files, only do so to the primary file. Don't create patches for the minified (`.min`) versions of the files. Those will be minified after a patch is merged into the code base.
|
20 |
+
|
21 |
+
## Language
|
22 |
+
|
23 |
+
All text strings follow U.S. English by default. While such guides are generally unneeded, in cases where style considerations are necessary, these will typically follow conventions laid out in *Elements of Style* or the *AP Stylebook*.
|
24 |
+
|
25 |
+
## Licensing
|
26 |
+
|
27 |
+
Any code contributed to the project via patches, pull requests, or other means will be licensed under the [GPL version 2](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) or later. By contributing code to the project, you provide consent to use such code under this license. The exception to this rule is when bringing in third-party code with an alternate open source license.
|
28 |
+
|
29 |
+
## Versioning
|
30 |
+
|
31 |
+
The project uses [semantic versioning](http://semver.org). Version numbers will look like `3.2.1` where `3` is the "major" release, `2` is the minor release, and `1` is the patch release.
|
get-the-image.php
CHANGED
@@ -1,48 +1,48 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin Name: Get The Image
|
4 |
-
* Plugin URI:
|
5 |
* Description: This is a highly intuitive script that can grab an image by custom field, featured image, post attachment, or extracting it from the post's content.
|
6 |
-
* Version: 1.0
|
7 |
* Author: Justin Tadlock
|
8 |
-
* Author URI:
|
9 |
*/
|
10 |
|
11 |
/**
|
12 |
* Get the Image - An advanced post image script for WordPress.
|
13 |
*
|
14 |
-
* Get the Image was created to be a highly-intuitive image script that displays post-specific images (an
|
15 |
-
* image-based representation of a post). The script handles old-style post images via custom fields for
|
16 |
-
* backwards compatibility. It also supports WordPress' built-in featured image functionality. On top of
|
17 |
-
* those things, it can automatically set attachment images as the post image or scan the post content for
|
18 |
* the first image element used. It can also fall back to a given default image.
|
19 |
*
|
20 |
-
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
|
21 |
-
* General Public License as published by the Free Software Foundation; either version 2 of the License,
|
22 |
* or (at your option) any later version.
|
23 |
*
|
24 |
-
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
25 |
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
26 |
*
|
27 |
* @package GetTheImage
|
28 |
-
* @version 1.0
|
29 |
* @author Justin Tadlock <justin@justintadlock.com>
|
30 |
-
* @copyright Copyright (c) 2008 -
|
31 |
-
* @link
|
32 |
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
33 |
*/
|
34 |
|
35 |
-
|
36 |
add_theme_support( 'post-thumbnails' );
|
37 |
|
38 |
-
|
39 |
add_action( 'save_post', 'get_the_image_delete_cache_by_post' );
|
40 |
add_action( 'deleted_post_meta', 'get_the_image_delete_cache_by_meta', 10, 2 );
|
41 |
add_action( 'updated_post_meta', 'get_the_image_delete_cache_by_meta', 10, 2 );
|
42 |
add_action( 'added_post_meta', 'get_the_image_delete_cache_by_meta', 10, 2 );
|
43 |
|
44 |
/**
|
45 |
-
* The main image function for displaying an image. This is a wrapper for the Get_The_Image class. Use this
|
46 |
* function in themes rather than the class.
|
47 |
*
|
48 |
* @since 0.1.0
|
@@ -62,8 +62,8 @@ function get_the_image( $args = array() ) {
|
|
62 |
|
63 |
|
64 |
/**
|
65 |
-
* Class for getting images related to a post. Only use this class in your projects if you absolutely know
|
66 |
-
* what you're doing and expect your code to break in future versions. Use the the `get_the_image()`
|
67 |
* wrapper function instead. That's the reason it exists.
|
68 |
*
|
69 |
* @since 1.0.0
|
@@ -81,8 +81,8 @@ final class Get_The_Image {
|
|
81 |
public $args = array();
|
82 |
|
83 |
/**
|
84 |
-
* Image arguments array filled by the class. This is used to store data about the image (src,
|
85 |
-
* width, height, etc.). In some scenarios, it may not be set, particularly when getting the
|
86 |
* raw image HTML.
|
87 |
*
|
88 |
* @since 1.0.0
|
@@ -101,7 +101,7 @@ final class Get_The_Image {
|
|
101 |
public $image = '';
|
102 |
|
103 |
/**
|
104 |
-
* Original image HTML. This is set when splitting an image from the content. By default, this
|
105 |
* is only used when 'scan_raw' is set.
|
106 |
*
|
107 |
* @since 1.0.0
|
@@ -110,6 +110,15 @@ final class Get_The_Image {
|
|
110 |
*/
|
111 |
public $original_image = '';
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
/**
|
114 |
* Constructor method. This sets up and runs the show.
|
115 |
*
|
@@ -121,20 +130,20 @@ final class Get_The_Image {
|
|
121 |
public function __construct( $args = array() ) {
|
122 |
global $wp_embed;
|
123 |
|
124 |
-
|
125 |
add_filter( 'get_the_image_post_content', array( $wp_embed, 'run_shortcode' ) );
|
126 |
add_filter( 'get_the_image_post_content', array( $wp_embed, 'autoembed' ) );
|
127 |
|
128 |
-
|
129 |
$defaults = array(
|
130 |
|
131 |
-
|
132 |
'post_id' => get_the_ID(),
|
133 |
|
134 |
-
|
135 |
'order' => array( 'meta_key', 'featured', 'attachment', 'scan', 'scan_raw', 'callback', 'default' ),
|
136 |
|
137 |
-
|
138 |
'meta_key' => array( 'Thumbnail', 'thumbnail' ), // array|string
|
139 |
'featured' => true,
|
140 |
'attachment' => true,
|
@@ -143,87 +152,97 @@ final class Get_The_Image {
|
|
143 |
'callback' => null,
|
144 |
'default' => false,
|
145 |
|
146 |
-
|
147 |
'split_content' => false,
|
148 |
|
149 |
-
|
150 |
'size' => has_image_size( 'post-thumbnail' ) ? 'post-thumbnail' : 'thumbnail',
|
151 |
|
152 |
-
|
153 |
-
'
|
|
|
|
|
|
|
|
|
154 |
'image_class' => false,
|
|
|
155 |
'width' => false,
|
156 |
'height' => false,
|
157 |
'before' => '',
|
158 |
'after' => '',
|
159 |
|
160 |
-
|
161 |
'min_width' => 0,
|
162 |
'min_height' => 0,
|
163 |
|
164 |
-
|
165 |
'caption' => false, // Default WP [caption] requires a width.
|
166 |
|
167 |
-
|
168 |
'meta_key_save' => false, // Save as metadata (string).
|
169 |
'thumbnail_id_save' => false, // Set 'featured image'.
|
170 |
'cache' => true, // Cache the image.
|
171 |
|
172 |
-
|
173 |
'format' => 'img',
|
174 |
'echo' => true,
|
175 |
|
176 |
-
|
177 |
'custom_key' => null, // @deprecated 0.6.0 Use 'meta_key'.
|
178 |
'default_size' => null, // @deprecated 0.5.0 Use 'size'.
|
179 |
'the_post_thumbnail' => null, // @deprecated 1.0.0 Use 'featured'.
|
180 |
'image_scan' => null, // @deprecated 1.0.0 Use 'scan' or 'scan_raw'.
|
181 |
'default_image' => null, // @deprecated 1.0.0 Use 'default'.
|
182 |
'order_of_image' => null, // @deprecated 1.0.0 No replacement.
|
|
|
183 |
);
|
184 |
|
185 |
-
|
186 |
$this->args = apply_filters(
|
187 |
'get_the_image_args',
|
188 |
wp_parse_args( $args, $defaults )
|
189 |
);
|
190 |
|
191 |
-
|
192 |
if ( empty( $this->args['post_id'] ) )
|
193 |
return false;
|
194 |
|
195 |
/* === Handle deprecated arguments. === */
|
196 |
|
197 |
-
|
198 |
if ( !is_null( $this->args['default_size'] ) )
|
199 |
$this->args['size'] = $this->args['default_size'];
|
200 |
|
201 |
-
|
202 |
if ( !is_null( $this->args['custom_key'] ) )
|
203 |
$this->args['meta_key'] = $this->args['custom_key'];
|
204 |
|
205 |
-
|
206 |
if ( !is_null( $this->args['the_post_thumbnail'] ) )
|
207 |
$this->args['featured'] = $this->args['the_post_thumbnail'];
|
208 |
|
209 |
-
|
210 |
if ( !is_null( $this->args['image_scan'] ) )
|
211 |
$this->args['scan'] = $this->args['image_scan'];
|
212 |
|
213 |
-
|
214 |
if ( !is_null( $this->args['default_image'] ) )
|
215 |
$this->args['default'] = $this->args['default_image'];
|
216 |
|
|
|
|
|
|
|
|
|
217 |
/* === End deprecated arguments. === */
|
218 |
|
219 |
-
|
220 |
if ( 'array' == $this->args['format'] )
|
221 |
-
$this->args['
|
222 |
|
223 |
-
|
224 |
$this->find();
|
225 |
|
226 |
-
|
227 |
if ( true === $this->args['split_content'] && !empty( $this->original_image ) )
|
228 |
add_filter( 'the_content', array( $this, 'split_content' ), 9 );
|
229 |
}
|
@@ -237,39 +256,39 @@ final class Get_The_Image {
|
|
237 |
*/
|
238 |
public function get_image() {
|
239 |
|
240 |
-
|
241 |
$image_html = apply_filters( 'get_the_image', $this->image );
|
242 |
|
243 |
-
|
244 |
if ( 'array' === $this->args['format'] ) {
|
245 |
|
246 |
-
|
247 |
$out = array();
|
248 |
|
249 |
-
|
250 |
$atts = wp_kses_hair( $image_html, array( 'http', 'https' ) );
|
251 |
|
252 |
-
|
253 |
foreach ( $atts as $att )
|
254 |
$out[ $att['name'] ] = $att['value'];
|
255 |
|
256 |
-
|
257 |
return $out;
|
258 |
}
|
259 |
|
260 |
-
|
261 |
elseif ( false === $this->args['echo'] ) {
|
262 |
return !empty( $image_html ) ? $this->args['before'] . $image_html . $this->args['after'] : $image_html;
|
263 |
}
|
264 |
|
265 |
-
|
266 |
if ( isset( $this->image_args['post_thumbnail_id'] ) )
|
267 |
do_action( 'begin_fetch_post_thumbnail_html', $this->args['post_id'], $this->image_args['post_thumbnail_id'], $this->args['size'] );
|
268 |
|
269 |
-
|
270 |
echo !empty( $image_html ) ? $this->args['before'] . $image_html . $this->args['after'] : $image_html;
|
271 |
|
272 |
-
|
273 |
if ( isset( $this->image_args['post_thumbnail_id'] ) )
|
274 |
do_action( 'end_fetch_post_thumbnail_html', $this->args['post_id'], $this->image_args['post_thumbnail_id'], $this->args['size'] );
|
275 |
}
|
@@ -284,16 +303,16 @@ final class Get_The_Image {
|
|
284 |
*/
|
285 |
public function find() {
|
286 |
|
287 |
-
|
288 |
$key = md5( serialize( compact( array_keys( $this->args ) ) ) );
|
289 |
|
290 |
-
|
291 |
$image_cache = wp_cache_get( $this->args['post_id'], 'get_the_image' );
|
292 |
|
293 |
if ( !is_array( $image_cache ) )
|
294 |
$image_cache = array();
|
295 |
|
296 |
-
|
297 |
if ( !isset( $image_cache[ $key ] ) || empty( $cache ) ) {
|
298 |
|
299 |
foreach ( $this->args['order'] as $method ) {
|
@@ -323,24 +342,24 @@ final class Get_The_Image {
|
|
323 |
$this->get_default_image();
|
324 |
}
|
325 |
|
326 |
-
|
327 |
if ( empty( $this->image ) && !empty( $this->image_args ) )
|
328 |
$this->format_image();
|
329 |
|
330 |
-
|
331 |
if ( !empty( $this->image ) ) {
|
332 |
|
333 |
-
|
334 |
if ( !empty( $this->args['meta_key_save'] ) )
|
335 |
$this->meta_key_save();
|
336 |
|
337 |
-
|
338 |
$image_cache[ $key ] = $this->image;
|
339 |
wp_cache_set( $this->args['post_id'], $image_cache, 'get_the_image' );
|
340 |
}
|
341 |
}
|
342 |
|
343 |
-
|
344 |
else {
|
345 |
$this->image = $image_cache[ $key ];
|
346 |
}
|
@@ -355,26 +374,26 @@ final class Get_The_Image {
|
|
355 |
*/
|
356 |
public function get_meta_key_image() {
|
357 |
|
358 |
-
|
359 |
if ( !is_array( $this->args['meta_key'] ) )
|
360 |
$this->args['meta_key'] = array( $this->args['meta_key'] );
|
361 |
|
362 |
-
|
363 |
foreach ( $this->args['meta_key'] as $meta_key ) {
|
364 |
|
365 |
-
|
366 |
$image = get_post_meta( $this->args['post_id'], $meta_key, true );
|
367 |
|
368 |
-
|
369 |
if ( !empty( $image ) )
|
370 |
break;
|
371 |
}
|
372 |
|
373 |
-
|
374 |
if ( !empty( $image ) && is_numeric( $image ) )
|
375 |
$this->_get_image_attachment( absint( $image ) );
|
376 |
|
377 |
-
|
378 |
elseif ( !empty( $image ) )
|
379 |
$this->image_args = array( 'src' => $image );
|
380 |
}
|
@@ -388,26 +407,27 @@ final class Get_The_Image {
|
|
388 |
*/
|
389 |
public function get_featured_image() {
|
390 |
|
391 |
-
|
392 |
$post_thumbnail_id = get_post_thumbnail_id( $this->args['post_id'] );
|
393 |
|
394 |
-
|
395 |
if ( empty( $post_thumbnail_id ) )
|
396 |
return;
|
397 |
|
398 |
-
|
399 |
$this->args['size'] = apply_filters( 'post_thumbnail_size', $this->args['size'] );
|
400 |
|
401 |
-
|
402 |
$this->_get_image_attachment( $post_thumbnail_id );
|
403 |
|
404 |
-
|
405 |
-
$this->image_args
|
|
|
406 |
}
|
407 |
|
408 |
/**
|
409 |
-
* Gets the first image attached to the post. If the post itself is an attachment image, that will
|
410 |
-
* be the image used. This method also works with sub-attachments (images for audio/video attachments
|
411 |
* are a good example).
|
412 |
*
|
413 |
* @since 1.0.0
|
@@ -416,15 +436,15 @@ final class Get_The_Image {
|
|
416 |
*/
|
417 |
public function get_attachment_image() {
|
418 |
|
419 |
-
|
420 |
if ( wp_attachment_is_image( $this->args['post_id'] ) ) {
|
421 |
$attachment_id = $this->args['post_id'];
|
422 |
}
|
423 |
|
424 |
-
|
425 |
else {
|
426 |
|
427 |
-
|
428 |
$attachments = get_children(
|
429 |
array(
|
430 |
'numberposts' => 1,
|
@@ -438,7 +458,7 @@ final class Get_The_Image {
|
|
438 |
)
|
439 |
);
|
440 |
|
441 |
-
|
442 |
if ( !empty( $attachments ) )
|
443 |
$attachment_id = array_shift( $attachments );
|
444 |
}
|
@@ -448,8 +468,8 @@ final class Get_The_Image {
|
|
448 |
}
|
449 |
|
450 |
/**
|
451 |
-
* Scans the post content for an image. It first scans and checks for an image with the
|
452 |
-
* "wp-image-xxx" ID. If that exists, it'll grab the actual image attachment. If not, it looks
|
453 |
* for the image source.
|
454 |
*
|
455 |
* @since 1.0.0
|
@@ -458,16 +478,16 @@ final class Get_The_Image {
|
|
458 |
*/
|
459 |
public function get_scan_image() {
|
460 |
|
461 |
-
|
462 |
$post_content = get_post_field( 'post_content', $this->args['post_id'] );
|
463 |
|
464 |
-
|
465 |
$post_content = apply_filters( 'get_the_image_post_content', $post_content );
|
466 |
|
467 |
-
|
468 |
preg_match( '/id=[\'"]wp-image-([\d]*)[\'"]/i', $post_content, $image_ids );
|
469 |
|
470 |
-
|
471 |
if ( is_array( $image_ids ) ) {
|
472 |
|
473 |
foreach ( $image_ids as $image_id ) {
|
@@ -478,26 +498,26 @@ final class Get_The_Image {
|
|
478 |
}
|
479 |
}
|
480 |
|
481 |
-
|
482 |
preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i', $post_content, $matches );
|
483 |
|
484 |
-
|
485 |
if ( isset( $matches ) && !empty( $matches[1][0] ) )
|
486 |
$this->image_args = array( 'src' => $matches[1][0] );
|
487 |
}
|
488 |
|
489 |
/**
|
490 |
-
* Scans the post content for a complete image. This method will attempt to grab the complete
|
491 |
-
* HTML for an image. If an image is found, pretty much all arguments passed in may be ignored
|
492 |
-
* in favor of getting the actual image used in the post content. It works with both captions
|
493 |
-
* and linked images. However, it can't account for all possible HTML wrappers for images used
|
494 |
* in all setups.
|
495 |
*
|
496 |
-
* This method was created for use with the WordPress "image" post format where theme authors
|
497 |
-
* might want to pull the whole image from the content as the user added it. It's also meant
|
498 |
* to be used (not required) with the `split_content` option.
|
499 |
*
|
500 |
-
* Note: This option should not be used if returning the image as an array. If that's desired,
|
501 |
* use the `scan` option instead.
|
502 |
*
|
503 |
* @since 1.0.0
|
@@ -506,13 +526,13 @@ final class Get_The_Image {
|
|
506 |
*/
|
507 |
public function get_scan_raw_image() {
|
508 |
|
509 |
-
|
510 |
$post_content = get_post_field( 'post_content', $this->args['post_id'] );
|
511 |
|
512 |
-
|
513 |
$post_content = apply_filters( 'get_the_image_post_content', $post_content );
|
514 |
|
515 |
-
|
516 |
preg_match_all( '/' . get_shortcode_regex() . '/s', $post_content, $matches, PREG_SET_ORDER );
|
517 |
|
518 |
if ( !empty( $matches ) ) {
|
@@ -531,7 +551,7 @@ final class Get_The_Image {
|
|
531 |
|
532 |
if ( !empty( $image_src ) ) {
|
533 |
|
534 |
-
|
535 |
if ( preg_match( '#.*?[\s]caption=[\'"](.+?)[\'"]#i', $shortcode[0], $caption_matches ) )
|
536 |
$image_caption = trim( $caption_matches[1] );
|
537 |
|
@@ -543,21 +563,21 @@ final class Get_The_Image {
|
|
543 |
if ( !empty( $image_caption ) )
|
544 |
$caption_args['caption'] = $image_caption;
|
545 |
|
546 |
-
|
547 |
$patterns = array(
|
548 |
'/(src=[\'"]).+?([\'"])/i',
|
549 |
'/(width=[\'"]).+?([\'"])/i',
|
550 |
'/(height=[\'"]).+?([\'"])/i',
|
551 |
);
|
552 |
|
553 |
-
|
554 |
$replacements = array(
|
555 |
'${1}' . $image_src[0] . '${2}',
|
556 |
'${1}' . $image_src[1] . '${2}',
|
557 |
'${1}' . $image_src[2] . '${2}',
|
558 |
);
|
559 |
|
560 |
-
|
561 |
$shortcode_content = preg_replace( $patterns, $replacements, $shortcode[5] );
|
562 |
|
563 |
$this->image = img_caption_shortcode( $caption_args, $shortcode_content );
|
@@ -574,14 +594,14 @@ final class Get_The_Image {
|
|
574 |
}
|
575 |
}
|
576 |
|
577 |
-
|
578 |
if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)#is', $post_content, $matches ) )
|
579 |
$this->image = $this->original_image = $matches[0];
|
580 |
}
|
581 |
|
582 |
/**
|
583 |
-
* Allows developers to create a custom callback function. If the `callback` argument is set, theme
|
584 |
-
* developers are expected to **always** return an array. Even if nothing is found, return an empty
|
585 |
* array.
|
586 |
*
|
587 |
* @since 1.0.0
|
@@ -604,7 +624,7 @@ final class Get_The_Image {
|
|
604 |
}
|
605 |
|
606 |
/**
|
607 |
-
* Handles an image attachment. Other methods rely on this method for getting the image data since
|
608 |
* most images are actually attachments.
|
609 |
*
|
610 |
* @since 1.0.0
|
@@ -614,31 +634,65 @@ final class Get_The_Image {
|
|
614 |
*/
|
615 |
public function _get_image_attachment( $attachment_id ) {
|
616 |
|
617 |
-
|
618 |
$image = wp_get_attachment_image_src( $attachment_id, $this->args['size'] );
|
619 |
|
620 |
-
|
621 |
$alt = trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) );
|
622 |
|
623 |
-
|
624 |
$caption = get_post_field( 'post_excerpt', $attachment_id );
|
625 |
|
626 |
-
|
|
|
|
|
|
|
|
|
627 |
if ( true === $this->args['thumbnail_id_save'] )
|
628 |
$this->thumbnail_id_save( $attachment_id );
|
629 |
|
630 |
-
|
631 |
$this->image_args = array(
|
632 |
-
'
|
|
|
633 |
'width' => $image[1],
|
634 |
'height' => $image[2],
|
635 |
-
'alt' => $alt,
|
636 |
-
'caption' => $caption
|
637 |
);
|
|
|
|
|
|
|
638 |
}
|
639 |
|
640 |
/**
|
641 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
642 |
* the `$image_args` property to set up the image.
|
643 |
*
|
644 |
* @since 1.0.0
|
@@ -647,86 +701,173 @@ final class Get_The_Image {
|
|
647 |
*/
|
648 |
public function format_image() {
|
649 |
|
650 |
-
|
651 |
if ( empty( $this->image_args['src'] ) )
|
652 |
return;
|
653 |
|
654 |
-
|
655 |
-
if (
|
656 |
-
return;
|
657 |
|
658 |
-
|
659 |
-
|
660 |
-
return;
|
661 |
|
662 |
-
|
663 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
664 |
|
665 |
-
|
666 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
667 |
|
668 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
669 |
if ( isset( $this->image_args['width'] ) && isset( $this->image_args['height'] ) ) {
|
670 |
|
671 |
-
|
672 |
-
|
673 |
|
674 |
-
/* If an explicit width/height is not set, use the info from the image. */
|
675 |
-
if ( empty( $this->args['width'] ) && empty( $this->args['height'] ) ) {
|
676 |
$this->args['width'] = $this->image_args['width'];
|
677 |
$this->args['height'] = $this->image_args['height'];
|
678 |
}
|
679 |
}
|
680 |
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
|
685 |
-
|
686 |
-
|
687 |
-
$classes = array_merge( $classes, (array)$this->args['meta_key'] );
|
688 |
|
689 |
-
|
690 |
-
$
|
691 |
|
692 |
-
|
693 |
-
|
694 |
|
695 |
-
|
696 |
-
|
697 |
|
698 |
-
|
699 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
700 |
|
701 |
-
|
702 |
-
$classes = $this->sanitize_class( $classes );
|
703 |
|
704 |
-
|
705 |
-
$
|
|
|
706 |
|
707 |
-
|
708 |
-
|
709 |
|
710 |
-
|
711 |
-
|
712 |
-
$html = '<a href="' . get_permalink( $this->args['post_id'] ) . '" title="' . esc_attr( get_post_field( 'post_title', $this->args['post_id'] ) ) . '">' . $html . '</a>';
|
713 |
|
714 |
-
|
715 |
-
|
716 |
-
$html = apply_filters( 'post_thumbnail_html', $html, $this->args['post_id'], $this->image_args['post_thumbnail_id'], $this->args['size'], '' );
|
717 |
|
718 |
-
|
719 |
-
|
720 |
-
$html = img_caption_shortcode( array( 'caption' => $this->image_args['caption'], 'width' => $this->args['width'] ), $html );
|
721 |
|
722 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
723 |
}
|
724 |
|
725 |
/**
|
726 |
-
* Saves the image source as metadata. Saving the image as meta is actually quite a bit quicker
|
727 |
-
* if the user doesn't have a persistent caching plugin available. However, it doesn't play as
|
728 |
-
* nicely with custom image sizes used across multiple themes where one might want to resize images.
|
729 |
-
* This option should be reserved for advanced users only. Don't use in publicly-distributed
|
730 |
* themes.
|
731 |
*
|
732 |
* @since 1.0.0
|
@@ -735,26 +876,26 @@ final class Get_The_Image {
|
|
735 |
*/
|
736 |
public function meta_key_save() {
|
737 |
|
738 |
-
|
739 |
if ( empty( $this->args['meta_key_save'] ) || empty( $this->image_args['src'] ) )
|
740 |
return;
|
741 |
|
742 |
-
|
743 |
$meta = get_post_meta( $this->args['post_id'], $this->args['meta_key_save'], true );
|
744 |
|
745 |
-
|
746 |
if ( empty( $meta ) )
|
747 |
add_post_meta( $this->args['post_id'], $this->args['meta_key_save'], $this->image_args['src'] );
|
748 |
|
749 |
-
|
750 |
elseif ( $meta !== $this->image_args['src'] )
|
751 |
update_post_meta( $this->args['post_id'], $this->args['meta_key_save'], $this->image_args['src'], $meta );
|
752 |
}
|
753 |
|
754 |
/**
|
755 |
-
* Saves the image attachment as the WordPress featured image. This is useful for setting the
|
756 |
-
* featured image for the post in the case that the user forgot to (win for client work!). It
|
757 |
-
* should not be used in publicly-distributed themes where you don't know how the user will be
|
758 |
* setting up their site.
|
759 |
*
|
760 |
* @since 1.0.0
|
@@ -763,7 +904,7 @@ final class Get_The_Image {
|
|
763 |
*/
|
764 |
public function thumbnail_id_save( $attachment_id ) {
|
765 |
|
766 |
-
|
767 |
if ( true === $this->args['thumbnail_id_save'] )
|
768 |
set_post_thumbnail( $this->args['post_id'], $attachment_id );
|
769 |
}
|
@@ -798,6 +939,28 @@ final class Get_The_Image {
|
|
798 |
|
799 |
return str_replace( $this->original_image, '', $content );
|
800 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
801 |
}
|
802 |
|
803 |
/**
|
@@ -813,7 +976,7 @@ function get_the_image_delete_cache_by_post( $post_id ) {
|
|
813 |
}
|
814 |
|
815 |
/**
|
816 |
-
* Deletes the image cache for a specific post when the 'added_post_meta', 'deleted_post_meta',
|
817 |
* or 'updated_post_meta' hooks are called.
|
818 |
*
|
819 |
* @since 0.7.0
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin Name: Get The Image
|
4 |
+
* Plugin URI: https://themehybrid.com/plugins/get-the-image
|
5 |
* Description: This is a highly intuitive script that can grab an image by custom field, featured image, post attachment, or extracting it from the post's content.
|
6 |
+
* Version: 1.1.0
|
7 |
* Author: Justin Tadlock
|
8 |
+
* Author URI: https://themehybrid.com
|
9 |
*/
|
10 |
|
11 |
/**
|
12 |
* Get the Image - An advanced post image script for WordPress.
|
13 |
*
|
14 |
+
* Get the Image was created to be a highly-intuitive image script that displays post-specific images (an
|
15 |
+
* image-based representation of a post). The script handles old-style post images via custom fields for
|
16 |
+
* backwards compatibility. It also supports WordPress' built-in featured image functionality. On top of
|
17 |
+
* those things, it can automatically set attachment images as the post image or scan the post content for
|
18 |
* the first image element used. It can also fall back to a given default image.
|
19 |
*
|
20 |
+
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
|
21 |
+
* General Public License as published by the Free Software Foundation; either version 2 of the License,
|
22 |
* or (at your option) any later version.
|
23 |
*
|
24 |
+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
25 |
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
26 |
*
|
27 |
* @package GetTheImage
|
28 |
+
* @version 1.1.0
|
29 |
* @author Justin Tadlock <justin@justintadlock.com>
|
30 |
+
* @copyright Copyright (c) 2008 - 2017, Justin Tadlock
|
31 |
+
* @link https://themehybrid.com/plugins/get-the-image
|
32 |
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
33 |
*/
|
34 |
|
35 |
+
# Adds theme support for WordPress 'featured images'.
|
36 |
add_theme_support( 'post-thumbnails' );
|
37 |
|
38 |
+
# Delete the cache when a post or post metadata is updated.
|
39 |
add_action( 'save_post', 'get_the_image_delete_cache_by_post' );
|
40 |
add_action( 'deleted_post_meta', 'get_the_image_delete_cache_by_meta', 10, 2 );
|
41 |
add_action( 'updated_post_meta', 'get_the_image_delete_cache_by_meta', 10, 2 );
|
42 |
add_action( 'added_post_meta', 'get_the_image_delete_cache_by_meta', 10, 2 );
|
43 |
|
44 |
/**
|
45 |
+
* The main image function for displaying an image. This is a wrapper for the Get_The_Image class. Use this
|
46 |
* function in themes rather than the class.
|
47 |
*
|
48 |
* @since 0.1.0
|
62 |
|
63 |
|
64 |
/**
|
65 |
+
* Class for getting images related to a post. Only use this class in your projects if you absolutely know
|
66 |
+
* what you're doing and expect your code to break in future versions. Use the the `get_the_image()`
|
67 |
* wrapper function instead. That's the reason it exists.
|
68 |
*
|
69 |
* @since 1.0.0
|
81 |
public $args = array();
|
82 |
|
83 |
/**
|
84 |
+
* Image arguments array filled by the class. This is used to store data about the image (src,
|
85 |
+
* width, height, etc.). In some scenarios, it may not be set, particularly when getting the
|
86 |
* raw image HTML.
|
87 |
*
|
88 |
* @since 1.0.0
|
101 |
public $image = '';
|
102 |
|
103 |
/**
|
104 |
+
* Original image HTML. This is set when splitting an image from the content. By default, this
|
105 |
* is only used when 'scan_raw' is set.
|
106 |
*
|
107 |
* @since 1.0.0
|
110 |
*/
|
111 |
public $original_image = '';
|
112 |
|
113 |
+
/**
|
114 |
+
* Holds an array of srcset sources and descriptors.
|
115 |
+
*
|
116 |
+
* @since 1.1.0
|
117 |
+
* @access public
|
118 |
+
* @var array
|
119 |
+
*/
|
120 |
+
public $srcsets = array();
|
121 |
+
|
122 |
/**
|
123 |
* Constructor method. This sets up and runs the show.
|
124 |
*
|
130 |
public function __construct( $args = array() ) {
|
131 |
global $wp_embed;
|
132 |
|
133 |
+
// Use WP's embed functionality to handle the [embed] shortcode and autoembeds. */
|
134 |
add_filter( 'get_the_image_post_content', array( $wp_embed, 'run_shortcode' ) );
|
135 |
add_filter( 'get_the_image_post_content', array( $wp_embed, 'autoembed' ) );
|
136 |
|
137 |
+
// Set the default arguments.
|
138 |
$defaults = array(
|
139 |
|
140 |
+
// Post the image is associated with.
|
141 |
'post_id' => get_the_ID(),
|
142 |
|
143 |
+
// Method order (see methods below).
|
144 |
'order' => array( 'meta_key', 'featured', 'attachment', 'scan', 'scan_raw', 'callback', 'default' ),
|
145 |
|
146 |
+
// Methods of getting an image (in order).
|
147 |
'meta_key' => array( 'Thumbnail', 'thumbnail' ), // array|string
|
148 |
'featured' => true,
|
149 |
'attachment' => true,
|
152 |
'callback' => null,
|
153 |
'default' => false,
|
154 |
|
155 |
+
// Split image from post content (by default, only used with the 'scan_raw' option).
|
156 |
'split_content' => false,
|
157 |
|
158 |
+
// Attachment-specific arguments.
|
159 |
'size' => has_image_size( 'post-thumbnail' ) ? 'post-thumbnail' : 'thumbnail',
|
160 |
|
161 |
+
// Key (image size) / Value ( width or px-density descriptor) pairs (e.g., 'large' => '2x' )
|
162 |
+
'srcset_sizes' => array(),
|
163 |
+
|
164 |
+
// Format/display of image.
|
165 |
+
'link' => 'post', // string|bool - 'post' (true), 'file', 'attachment', false
|
166 |
+
'link_class' => '',
|
167 |
'image_class' => false,
|
168 |
+
'image_attr' => array(),
|
169 |
'width' => false,
|
170 |
'height' => false,
|
171 |
'before' => '',
|
172 |
'after' => '',
|
173 |
|
174 |
+
// Minimum allowed sizes.
|
175 |
'min_width' => 0,
|
176 |
'min_height' => 0,
|
177 |
|
178 |
+
// Captions.
|
179 |
'caption' => false, // Default WP [caption] requires a width.
|
180 |
|
181 |
+
// Saving the image.
|
182 |
'meta_key_save' => false, // Save as metadata (string).
|
183 |
'thumbnail_id_save' => false, // Set 'featured image'.
|
184 |
'cache' => true, // Cache the image.
|
185 |
|
186 |
+
// Return/echo image.
|
187 |
'format' => 'img',
|
188 |
'echo' => true,
|
189 |
|
190 |
+
// Deprecated arguments.
|
191 |
'custom_key' => null, // @deprecated 0.6.0 Use 'meta_key'.
|
192 |
'default_size' => null, // @deprecated 0.5.0 Use 'size'.
|
193 |
'the_post_thumbnail' => null, // @deprecated 1.0.0 Use 'featured'.
|
194 |
'image_scan' => null, // @deprecated 1.0.0 Use 'scan' or 'scan_raw'.
|
195 |
'default_image' => null, // @deprecated 1.0.0 Use 'default'.
|
196 |
'order_of_image' => null, // @deprecated 1.0.0 No replacement.
|
197 |
+
'link_to_post' => null, // @deprecated 1.1.0 Use 'link'.
|
198 |
);
|
199 |
|
200 |
+
// Allow plugins/themes to filter the arguments.
|
201 |
$this->args = apply_filters(
|
202 |
'get_the_image_args',
|
203 |
wp_parse_args( $args, $defaults )
|
204 |
);
|
205 |
|
206 |
+
// If no post ID, return.
|
207 |
if ( empty( $this->args['post_id'] ) )
|
208 |
return false;
|
209 |
|
210 |
/* === Handle deprecated arguments. === */
|
211 |
|
212 |
+
// If $default_size is given, overwrite $size.
|
213 |
if ( !is_null( $this->args['default_size'] ) )
|
214 |
$this->args['size'] = $this->args['default_size'];
|
215 |
|
216 |
+
// If $custom_key is set, overwrite $meta_key.
|
217 |
if ( !is_null( $this->args['custom_key'] ) )
|
218 |
$this->args['meta_key'] = $this->args['custom_key'];
|
219 |
|
220 |
+
// If 'the_post_thumbnail' is set, overwrite 'featured'.
|
221 |
if ( !is_null( $this->args['the_post_thumbnail'] ) )
|
222 |
$this->args['featured'] = $this->args['the_post_thumbnail'];
|
223 |
|
224 |
+
// If 'image_scan' is set, overwrite 'scan'.
|
225 |
if ( !is_null( $this->args['image_scan'] ) )
|
226 |
$this->args['scan'] = $this->args['image_scan'];
|
227 |
|
228 |
+
// If 'default_image' is set, overwrite 'default'.
|
229 |
if ( !is_null( $this->args['default_image'] ) )
|
230 |
$this->args['default'] = $this->args['default_image'];
|
231 |
|
232 |
+
// If 'link_to_post' is set, overwrite 'link'.
|
233 |
+
if ( !is_null( $this->args['link_to_post'] ) )
|
234 |
+
$this->args['link'] = true === $this->args['link_to_post'] ? 'post' : false;
|
235 |
+
|
236 |
/* === End deprecated arguments. === */
|
237 |
|
238 |
+
// If $format is set to 'array', don't link to the post.
|
239 |
if ( 'array' == $this->args['format'] )
|
240 |
+
$this->args['link'] = false;
|
241 |
|
242 |
+
// Find images.
|
243 |
$this->find();
|
244 |
|
245 |
+
// Only used if $original_image is set.
|
246 |
if ( true === $this->args['split_content'] && !empty( $this->original_image ) )
|
247 |
add_filter( 'the_content', array( $this, 'split_content' ), 9 );
|
248 |
}
|
256 |
*/
|
257 |
public function get_image() {
|
258 |
|
259 |
+
// Allow plugins/theme to override the final output.
|
260 |
$image_html = apply_filters( 'get_the_image', $this->image );
|
261 |
|
262 |
+
// If $format is set to 'array', return an array of image attributes.
|
263 |
if ( 'array' === $this->args['format'] ) {
|
264 |
|
265 |
+
// Set up a default empty array.
|
266 |
$out = array();
|
267 |
|
268 |
+
// Get the image attributes.
|
269 |
$atts = wp_kses_hair( $image_html, array( 'http', 'https' ) );
|
270 |
|
271 |
+
// Loop through the image attributes and add them in key/value pairs for the return array.
|
272 |
foreach ( $atts as $att )
|
273 |
$out[ $att['name'] ] = $att['value'];
|
274 |
|
275 |
+
// Return the array of attributes.
|
276 |
return $out;
|
277 |
}
|
278 |
|
279 |
+
// Or, if $echo is set to false, return the formatted image.
|
280 |
elseif ( false === $this->args['echo'] ) {
|
281 |
return !empty( $image_html ) ? $this->args['before'] . $image_html . $this->args['after'] : $image_html;
|
282 |
}
|
283 |
|
284 |
+
// If there is a $post_thumbnail_id, do the actions associated with get_the_post_thumbnail().
|
285 |
if ( isset( $this->image_args['post_thumbnail_id'] ) )
|
286 |
do_action( 'begin_fetch_post_thumbnail_html', $this->args['post_id'], $this->image_args['post_thumbnail_id'], $this->args['size'] );
|
287 |
|
288 |
+
// Display the image if we get to this point.
|
289 |
echo !empty( $image_html ) ? $this->args['before'] . $image_html . $this->args['after'] : $image_html;
|
290 |
|
291 |
+
// If there is a $post_thumbnail_id, do the actions associated with get_the_post_thumbnail().
|
292 |
if ( isset( $this->image_args['post_thumbnail_id'] ) )
|
293 |
do_action( 'end_fetch_post_thumbnail_html', $this->args['post_id'], $this->image_args['post_thumbnail_id'], $this->args['size'] );
|
294 |
}
|
303 |
*/
|
304 |
public function find() {
|
305 |
|
306 |
+
// Get cache key based on $this->args.
|
307 |
$key = md5( serialize( compact( array_keys( $this->args ) ) ) );
|
308 |
|
309 |
+
// Check for a cached image.
|
310 |
$image_cache = wp_cache_get( $this->args['post_id'], 'get_the_image' );
|
311 |
|
312 |
if ( !is_array( $image_cache ) )
|
313 |
$image_cache = array();
|
314 |
|
315 |
+
// If there is no cached image, let's see if one exists.
|
316 |
if ( !isset( $image_cache[ $key ] ) || empty( $cache ) ) {
|
317 |
|
318 |
foreach ( $this->args['order'] as $method ) {
|
342 |
$this->get_default_image();
|
343 |
}
|
344 |
|
345 |
+
// Format the image HTML.
|
346 |
if ( empty( $this->image ) && !empty( $this->image_args ) )
|
347 |
$this->format_image();
|
348 |
|
349 |
+
// If we have image HTML.
|
350 |
if ( !empty( $this->image ) ) {
|
351 |
|
352 |
+
// Save the image as metadata.
|
353 |
if ( !empty( $this->args['meta_key_save'] ) )
|
354 |
$this->meta_key_save();
|
355 |
|
356 |
+
// Set the image cache for the specific post.
|
357 |
$image_cache[ $key ] = $this->image;
|
358 |
wp_cache_set( $this->args['post_id'], $image_cache, 'get_the_image' );
|
359 |
}
|
360 |
}
|
361 |
|
362 |
+
// If an image was already cached for the post and arguments, use it.
|
363 |
else {
|
364 |
$this->image = $image_cache[ $key ];
|
365 |
}
|
374 |
*/
|
375 |
public function get_meta_key_image() {
|
376 |
|
377 |
+
// If $meta_key is not an array.
|
378 |
if ( !is_array( $this->args['meta_key'] ) )
|
379 |
$this->args['meta_key'] = array( $this->args['meta_key'] );
|
380 |
|
381 |
+
// Loop through each of the given meta keys.
|
382 |
foreach ( $this->args['meta_key'] as $meta_key ) {
|
383 |
|
384 |
+
// Get the image URL by the current meta key in the loop.
|
385 |
$image = get_post_meta( $this->args['post_id'], $meta_key, true );
|
386 |
|
387 |
+
// If an image was found, break out of the loop.
|
388 |
if ( !empty( $image ) )
|
389 |
break;
|
390 |
}
|
391 |
|
392 |
+
// If there's an image and it is numeric, assume it is an attachment ID.
|
393 |
if ( !empty( $image ) && is_numeric( $image ) )
|
394 |
$this->_get_image_attachment( absint( $image ) );
|
395 |
|
396 |
+
// Else, assume the image is a file URL.
|
397 |
elseif ( !empty( $image ) )
|
398 |
$this->image_args = array( 'src' => $image );
|
399 |
}
|
407 |
*/
|
408 |
public function get_featured_image() {
|
409 |
|
410 |
+
// Check for a post image ID (set by WP as a custom field).
|
411 |
$post_thumbnail_id = get_post_thumbnail_id( $this->args['post_id'] );
|
412 |
|
413 |
+
// If no post image ID is found, return.
|
414 |
if ( empty( $post_thumbnail_id ) )
|
415 |
return;
|
416 |
|
417 |
+
// Apply filters on post_thumbnail_size because this is a default WP filter used with its image feature.
|
418 |
$this->args['size'] = apply_filters( 'post_thumbnail_size', $this->args['size'] );
|
419 |
|
420 |
+
// Set the image args.
|
421 |
$this->_get_image_attachment( $post_thumbnail_id );
|
422 |
|
423 |
+
// Add the post thumbnail ID.
|
424 |
+
if ( $this->image_args )
|
425 |
+
$this->image_args['post_thumbnail_id'] = $post_thumbnail_id;
|
426 |
}
|
427 |
|
428 |
/**
|
429 |
+
* Gets the first image attached to the post. If the post itself is an attachment image, that will
|
430 |
+
* be the image used. This method also works with sub-attachments (images for audio/video attachments
|
431 |
* are a good example).
|
432 |
*
|
433 |
* @since 1.0.0
|
436 |
*/
|
437 |
public function get_attachment_image() {
|
438 |
|
439 |
+
// Check if the post itself is an image attachment.
|
440 |
if ( wp_attachment_is_image( $this->args['post_id'] ) ) {
|
441 |
$attachment_id = $this->args['post_id'];
|
442 |
}
|
443 |
|
444 |
+
// If the post is not an image attachment, check if it has any image attachments.
|
445 |
else {
|
446 |
|
447 |
+
// Get attachments for the inputted $post_id.
|
448 |
$attachments = get_children(
|
449 |
array(
|
450 |
'numberposts' => 1,
|
458 |
)
|
459 |
);
|
460 |
|
461 |
+
// Check if any attachments were found.
|
462 |
if ( !empty( $attachments ) )
|
463 |
$attachment_id = array_shift( $attachments );
|
464 |
}
|
468 |
}
|
469 |
|
470 |
/**
|
471 |
+
* Scans the post content for an image. It first scans and checks for an image with the
|
472 |
+
* "wp-image-xxx" ID. If that exists, it'll grab the actual image attachment. If not, it looks
|
473 |
* for the image source.
|
474 |
*
|
475 |
* @since 1.0.0
|
478 |
*/
|
479 |
public function get_scan_image() {
|
480 |
|
481 |
+
// Get the post content.
|
482 |
$post_content = get_post_field( 'post_content', $this->args['post_id'] );
|
483 |
|
484 |
+
// Apply filters to content.
|
485 |
$post_content = apply_filters( 'get_the_image_post_content', $post_content );
|
486 |
|
487 |
+
// Check the content for `id="wp-image-%d"`.
|
488 |
preg_match( '/id=[\'"]wp-image-([\d]*)[\'"]/i', $post_content, $image_ids );
|
489 |
|
490 |
+
// Loop through any found image IDs.
|
491 |
if ( is_array( $image_ids ) ) {
|
492 |
|
493 |
foreach ( $image_ids as $image_id ) {
|
498 |
}
|
499 |
}
|
500 |
|
501 |
+
// Search the post's content for the <img /> tag and get its URL.
|
502 |
preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i', $post_content, $matches );
|
503 |
|
504 |
+
// If there is a match for the image, set the image args.
|
505 |
if ( isset( $matches ) && !empty( $matches[1][0] ) )
|
506 |
$this->image_args = array( 'src' => $matches[1][0] );
|
507 |
}
|
508 |
|
509 |
/**
|
510 |
+
* Scans the post content for a complete image. This method will attempt to grab the complete
|
511 |
+
* HTML for an image. If an image is found, pretty much all arguments passed in may be ignored
|
512 |
+
* in favor of getting the actual image used in the post content. It works with both captions
|
513 |
+
* and linked images. However, it can't account for all possible HTML wrappers for images used
|
514 |
* in all setups.
|
515 |
*
|
516 |
+
* This method was created for use with the WordPress "image" post format where theme authors
|
517 |
+
* might want to pull the whole image from the content as the user added it. It's also meant
|
518 |
* to be used (not required) with the `split_content` option.
|
519 |
*
|
520 |
+
* Note: This option should not be used if returning the image as an array. If that's desired,
|
521 |
* use the `scan` option instead.
|
522 |
*
|
523 |
* @since 1.0.0
|
526 |
*/
|
527 |
public function get_scan_raw_image() {
|
528 |
|
529 |
+
// Get the post content.
|
530 |
$post_content = get_post_field( 'post_content', $this->args['post_id'] );
|
531 |
|
532 |
+
// Apply filters to content.
|
533 |
$post_content = apply_filters( 'get_the_image_post_content', $post_content );
|
534 |
|
535 |
+
// Finds matches for shortcodes in the content.
|
536 |
preg_match_all( '/' . get_shortcode_regex() . '/s', $post_content, $matches, PREG_SET_ORDER );
|
537 |
|
538 |
if ( !empty( $matches ) ) {
|
551 |
|
552 |
if ( !empty( $image_src ) ) {
|
553 |
|
554 |
+
// Old-style captions.
|
555 |
if ( preg_match( '#.*?[\s]caption=[\'"](.+?)[\'"]#i', $shortcode[0], $caption_matches ) )
|
556 |
$image_caption = trim( $caption_matches[1] );
|
557 |
|
563 |
if ( !empty( $image_caption ) )
|
564 |
$caption_args['caption'] = $image_caption;
|
565 |
|
566 |
+
// Set up the patterns for the 'src', 'width', and 'height' attributes.
|
567 |
$patterns = array(
|
568 |
'/(src=[\'"]).+?([\'"])/i',
|
569 |
'/(width=[\'"]).+?([\'"])/i',
|
570 |
'/(height=[\'"]).+?([\'"])/i',
|
571 |
);
|
572 |
|
573 |
+
// Set up the replacements for the 'src', 'width', and 'height' attributes.
|
574 |
$replacements = array(
|
575 |
'${1}' . $image_src[0] . '${2}',
|
576 |
'${1}' . $image_src[1] . '${2}',
|
577 |
'${1}' . $image_src[2] . '${2}',
|
578 |
);
|
579 |
|
580 |
+
// Filter the image attributes.
|
581 |
$shortcode_content = preg_replace( $patterns, $replacements, $shortcode[5] );
|
582 |
|
583 |
$this->image = img_caption_shortcode( $caption_args, $shortcode_content );
|
594 |
}
|
595 |
}
|
596 |
|
597 |
+
// Pull a raw HTML image + link if it exists.
|
598 |
if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)#is', $post_content, $matches ) )
|
599 |
$this->image = $this->original_image = $matches[0];
|
600 |
}
|
601 |
|
602 |
/**
|
603 |
+
* Allows developers to create a custom callback function. If the `callback` argument is set, theme
|
604 |
+
* developers are expected to **always** return an array. Even if nothing is found, return an empty
|
605 |
* array.
|
606 |
*
|
607 |
* @since 1.0.0
|
624 |
}
|
625 |
|
626 |
/**
|
627 |
+
* Handles an image attachment. Other methods rely on this method for getting the image data since
|
628 |
* most images are actually attachments.
|
629 |
*
|
630 |
* @since 1.0.0
|
634 |
*/
|
635 |
public function _get_image_attachment( $attachment_id ) {
|
636 |
|
637 |
+
// Get the attachment image.
|
638 |
$image = wp_get_attachment_image_src( $attachment_id, $this->args['size'] );
|
639 |
|
640 |
+
// Get the attachment alt text.
|
641 |
$alt = trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) );
|
642 |
|
643 |
+
// Get the attachment caption.
|
644 |
$caption = get_post_field( 'post_excerpt', $attachment_id );
|
645 |
|
646 |
+
// Only use the image if we have an image and it meets the size requirements.
|
647 |
+
if ( ! $image || ! $this->have_required_dimensions( $image[1], $image[2] ) )
|
648 |
+
return;
|
649 |
+
|
650 |
+
// Save the attachment as the 'featured image'.
|
651 |
if ( true === $this->args['thumbnail_id_save'] )
|
652 |
$this->thumbnail_id_save( $attachment_id );
|
653 |
|
654 |
+
// Set the image args.
|
655 |
$this->image_args = array(
|
656 |
+
'id' => $attachment_id,
|
657 |
+
'src' => $image[0],
|
658 |
'width' => $image[1],
|
659 |
'height' => $image[2],
|
660 |
+
'alt' => $alt,
|
661 |
+
'caption' => $caption
|
662 |
);
|
663 |
+
|
664 |
+
// Get the image srcset sizes.
|
665 |
+
$this->get_srcset( $attachment_id );
|
666 |
}
|
667 |
|
668 |
/**
|
669 |
+
* Adds array of srcset image sources and descriptors based on the `srcset_sizes` argument
|
670 |
+
* provided by the developer.
|
671 |
+
*
|
672 |
+
* @since 1.1.0
|
673 |
+
* @access public
|
674 |
+
* @param int $attachment_id
|
675 |
+
* @return void
|
676 |
+
*/
|
677 |
+
public function get_srcset( $attachment_id ) {
|
678 |
+
|
679 |
+
// Bail if no sizes set.
|
680 |
+
if ( empty( $this->args['srcset_sizes'] ) )
|
681 |
+
return;
|
682 |
+
|
683 |
+
foreach ( $this->args['srcset_sizes'] as $size => $descriptor ) {
|
684 |
+
|
685 |
+
$image = wp_get_attachment_image_src( $attachment_id, $size );
|
686 |
+
|
687 |
+
// Make sure image doesn't match the image used for the `src` attribute.
|
688 |
+
// This will happen often if the particular image size doesn't exist.
|
689 |
+
if ( $this->image_args['src'] !== $image[0] )
|
690 |
+
$this->srcsets[] = sprintf( "%s %s", esc_url( $image[0] ), esc_attr( $descriptor ) );
|
691 |
+
}
|
692 |
+
}
|
693 |
+
|
694 |
+
/**
|
695 |
+
* Formats the image HTML. This method is only called if the `$image` property isn't set. It uses
|
696 |
* the `$image_args` property to set up the image.
|
697 |
*
|
698 |
* @since 1.0.0
|
701 |
*/
|
702 |
public function format_image() {
|
703 |
|
704 |
+
// If there is no image URL, return false.
|
705 |
if ( empty( $this->image_args['src'] ) )
|
706 |
return;
|
707 |
|
708 |
+
// Check against min. width and height. If the image is too small return.
|
709 |
+
if ( isset( $this->image_args['width'] ) || isset( $this->image_args['height'] ) ) {
|
|
|
710 |
|
711 |
+
$_w = isset( $this->image_args['width'] ) ? $this->image_args['width'] : false;
|
712 |
+
$_h = isset( $this->image_args['height'] ) ? $this->image_args['height'] : false;
|
|
|
713 |
|
714 |
+
if ( ! $this->have_required_dimensions( $_w, $_h ) )
|
715 |
+
return;
|
716 |
+
}
|
717 |
+
|
718 |
+
// Set up a variable for the image attributes.
|
719 |
+
$img_attr = '';
|
720 |
+
|
721 |
+
// Loop through the image attributes and format them for display.
|
722 |
+
foreach ( $this->get_image_attr() as $name => $value )
|
723 |
+
$img_attr .= false !== $value ? sprintf( ' %s="%s"', esc_html( $name ), esc_attr( $value ) ) : esc_html( " {$name}" );
|
724 |
+
|
725 |
+
// Add the image attributes to the <img /> element.
|
726 |
+
$html = sprintf( '<img %s />', $img_attr );
|
727 |
+
|
728 |
+
// If $link is set to true, link the image to its post.
|
729 |
+
if ( false !== $this->args['link'] ) {
|
730 |
+
|
731 |
+
if ( 'post' === $this->args['link'] || true === $this->args['link'] )
|
732 |
+
$url = get_permalink( $this->args['post_id'] );
|
733 |
+
|
734 |
+
elseif ( 'file' === $this->args['link'] )
|
735 |
+
$url = $this->image_args['src'];
|
736 |
+
|
737 |
+
elseif ( 'attachment' === $this->args['link'] && isset( $this->image_args['id'] ) )
|
738 |
+
$url = get_permalink( $this->image_args['id'] );
|
739 |
+
|
740 |
+
if ( ! empty( $url ) ) {
|
741 |
+
|
742 |
+
$link_class = $this->args['link_class'] ? sprintf( ' class="%s"', esc_attr( $this->args['link_class'] ) ) : '';
|
743 |
|
744 |
+
$html = sprintf( '<a href="%s"%s>%s</a>', esc_url( $url ), $link_class, $html );
|
745 |
+
}
|
746 |
+
}
|
747 |
+
|
748 |
+
// If there is a $post_thumbnail_id, apply the WP filters normally associated with get_the_post_thumbnail().
|
749 |
+
if ( ! empty( $this->image_args['post_thumbnail_id'] ) )
|
750 |
+
$html = apply_filters( 'post_thumbnail_html', $html, $this->args['post_id'], $this->image_args['post_thumbnail_id'], $this->args['size'], '' );
|
751 |
+
|
752 |
+
// If we're showing a caption.
|
753 |
+
if ( true === $this->args['caption'] && ! empty( $this->image_args['caption'] ) )
|
754 |
+
$html = img_caption_shortcode( array( 'caption' => $this->image_args['caption'], 'width' => $this->args['width'] ), $html );
|
755 |
|
756 |
+
$this->image = $html;
|
757 |
+
}
|
758 |
+
|
759 |
+
/**
|
760 |
+
* Sets up and returns an array of attributes for the final `<img>` element.
|
761 |
+
*
|
762 |
+
* @since 1.1.0
|
763 |
+
* @access public
|
764 |
+
* @return array
|
765 |
+
*/
|
766 |
+
public function get_image_attr() {
|
767 |
+
|
768 |
+
$attr = array();
|
769 |
+
|
770 |
+
// Add the image class.
|
771 |
+
$attr['class'] = join( ' ', $this->get_image_class() );
|
772 |
+
|
773 |
+
// If there's a width/height for the image.
|
774 |
if ( isset( $this->image_args['width'] ) && isset( $this->image_args['height'] ) ) {
|
775 |
|
776 |
+
// If an explicit width/height is not set, use the info from the image.
|
777 |
+
if ( ! $this->args['width'] && ! $this->args['height'] ) {
|
778 |
|
|
|
|
|
779 |
$this->args['width'] = $this->image_args['width'];
|
780 |
$this->args['height'] = $this->image_args['height'];
|
781 |
}
|
782 |
}
|
783 |
|
784 |
+
// If there is a width or height, set them.
|
785 |
+
if ( $this->args['width'] )
|
786 |
+
$attr['width'] = $this->args['width'];
|
787 |
|
788 |
+
if ( $this->args['height'] )
|
789 |
+
$attr['height'] = $this->args['height'];
|
|
|
790 |
|
791 |
+
// If there is alt text, set it. Otherwise, default to the post title.
|
792 |
+
$attr['alt'] = ! empty( $this->image_args['alt'] ) ? $this->image_args['alt'] : get_post_field( 'post_title', $this->args['post_id'] );
|
793 |
|
794 |
+
// Add the itemprop attribute.
|
795 |
+
$attr['itemprop'] = 'image';
|
796 |
|
797 |
+
// Parse the args with the user inputted args.
|
798 |
+
$attr = wp_parse_args( $this->args['image_attr'], $attr );
|
799 |
|
800 |
+
// Allow devs to filter the image attributes.
|
801 |
+
$attr = apply_filters( 'get_the_image_attr', $attr, $this );
|
802 |
+
|
803 |
+
// Add the image source after the filter so that it can't be overwritten.
|
804 |
+
$attr['src'] = $this->image_args['src'];
|
805 |
+
|
806 |
+
// Return attributes.
|
807 |
+
return $attr;
|
808 |
+
}
|
809 |
+
|
810 |
+
/**
|
811 |
+
* Sets up and returns an array of classes for the `<img>` element.
|
812 |
+
*
|
813 |
+
* @since 1.1.0
|
814 |
+
* @access public
|
815 |
+
* @global int $content_width
|
816 |
+
* @return array
|
817 |
+
*/
|
818 |
+
public function get_image_class() {
|
819 |
+
global $content_width;
|
820 |
|
821 |
+
$classes = array();
|
|
|
822 |
|
823 |
+
// Get true image height and width.
|
824 |
+
$width = isset( $this->image_args['width'] ) ? $this->image_args['width'] : false;
|
825 |
+
$height = isset( $this->image_args['height'] ) ? $this->image_args['height'] : false;
|
826 |
|
827 |
+
// If there's a width/height for the image.
|
828 |
+
if ( $width && $height ) {
|
829 |
|
830 |
+
// Set a class based on the orientation.
|
831 |
+
$classes[] = $height > $width ? 'portrait' : 'landscape';
|
|
|
832 |
|
833 |
+
// Set class based on the content width (defined by theme).
|
834 |
+
if ( 0 < $content_width ) {
|
|
|
835 |
|
836 |
+
if ( $content_width == $width )
|
837 |
+
$classes[] = 'cw-equal';
|
|
|
838 |
|
839 |
+
elseif ( $content_width <= $width )
|
840 |
+
$classes[] = 'cw-lesser';
|
841 |
+
|
842 |
+
elseif ( $content_width >= $width )
|
843 |
+
$classes[] = 'cw-greater';
|
844 |
+
}
|
845 |
+
}
|
846 |
+
|
847 |
+
// Add the meta key(s) to the classes array.
|
848 |
+
if ( ! empty( $this->args['meta_key'] ) )
|
849 |
+
$classes = array_merge( $classes, (array)$this->args['meta_key'] );
|
850 |
+
|
851 |
+
// Add the $size to the class.
|
852 |
+
$classes[] = $this->args['size'];
|
853 |
+
|
854 |
+
// Get the custom image class.
|
855 |
+
if ( ! empty( $this->args['image_class'] ) ) {
|
856 |
+
|
857 |
+
if ( ! is_array( $this->args['image_class'] ) )
|
858 |
+
$this->args['image_class'] = preg_split( '#\s+#', $this->args['image_class'] );
|
859 |
+
|
860 |
+
$classes = array_merge( $classes, $this->args['image_class'] );
|
861 |
+
}
|
862 |
+
|
863 |
+
return apply_filters( 'get_the_image_class', $this->sanitize_class( $classes ), $this );
|
864 |
}
|
865 |
|
866 |
/**
|
867 |
+
* Saves the image source as metadata. Saving the image as meta is actually quite a bit quicker
|
868 |
+
* if the user doesn't have a persistent caching plugin available. However, it doesn't play as
|
869 |
+
* nicely with custom image sizes used across multiple themes where one might want to resize images.
|
870 |
+
* This option should be reserved for advanced users only. Don't use in publicly-distributed
|
871 |
* themes.
|
872 |
*
|
873 |
* @since 1.0.0
|
876 |
*/
|
877 |
public function meta_key_save() {
|
878 |
|
879 |
+
// If the $meta_key_save argument is empty or there is no image $url given, return.
|
880 |
if ( empty( $this->args['meta_key_save'] ) || empty( $this->image_args['src'] ) )
|
881 |
return;
|
882 |
|
883 |
+
// Get the current value of the meta key.
|
884 |
$meta = get_post_meta( $this->args['post_id'], $this->args['meta_key_save'], true );
|
885 |
|
886 |
+
// If there is no value for the meta key, set a new value with the image $url.
|
887 |
if ( empty( $meta ) )
|
888 |
add_post_meta( $this->args['post_id'], $this->args['meta_key_save'], $this->image_args['src'] );
|
889 |
|
890 |
+
// If the current value doesn't match the image $url, update it.
|
891 |
elseif ( $meta !== $this->image_args['src'] )
|
892 |
update_post_meta( $this->args['post_id'], $this->args['meta_key_save'], $this->image_args['src'], $meta );
|
893 |
}
|
894 |
|
895 |
/**
|
896 |
+
* Saves the image attachment as the WordPress featured image. This is useful for setting the
|
897 |
+
* featured image for the post in the case that the user forgot to (win for client work!). It
|
898 |
+
* should not be used in publicly-distributed themes where you don't know how the user will be
|
899 |
* setting up their site.
|
900 |
*
|
901 |
* @since 1.0.0
|
904 |
*/
|
905 |
public function thumbnail_id_save( $attachment_id ) {
|
906 |
|
907 |
+
// Save the attachment as the 'featured image'.
|
908 |
if ( true === $this->args['thumbnail_id_save'] )
|
909 |
set_post_thumbnail( $this->args['post_id'], $attachment_id );
|
910 |
}
|
939 |
|
940 |
return str_replace( $this->original_image, '', $content );
|
941 |
}
|
942 |
+
|
943 |
+
/**
|
944 |
+
* Checks if the image meets the minimum size requirements.
|
945 |
+
*
|
946 |
+
* @since 1.1.0
|
947 |
+
* @access public
|
948 |
+
* @param int|bool $width
|
949 |
+
* @param int|bool $height
|
950 |
+
* @return bool
|
951 |
+
*/
|
952 |
+
public function have_required_dimensions( $width = false, $height = false ) {
|
953 |
+
|
954 |
+
// Check against min. width. If the image width is too small return.
|
955 |
+
if ( 0 < $this->args['min_width'] && $width && $width < $this->args['min_width'] )
|
956 |
+
return false;
|
957 |
+
|
958 |
+
// Check against min. height. If the image height is too small return.
|
959 |
+
if ( 0 < $this->args['min_height'] && $height && $height < $this->args['min_height'] )
|
960 |
+
return false;
|
961 |
+
|
962 |
+
return true;
|
963 |
+
}
|
964 |
}
|
965 |
|
966 |
/**
|
976 |
}
|
977 |
|
978 |
/**
|
979 |
+
* Deletes the image cache for a specific post when the 'added_post_meta', 'deleted_post_meta',
|
980 |
* or 'updated_post_meta' hooks are called.
|
981 |
*
|
982 |
* @since 0.7.0
|
license.txt → license.md
RENAMED
File without changes
|
readme.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
-
# Get the Image
|
2 |
|
3 |
Get the Image is a plugin that grabs images for you. It was designed to make the process of things such as adding thumbnails, feature images, and/or other images to your blog much easier, but it's so much more than that. It is an image-based representation of your WordPress posts.
|
4 |
|
5 |
-
## What the plugin does
|
6 |
|
7 |
This plugin was made to easily get an image related to a post. This is the default method order in which the plugin attempts to grab an image.
|
8 |
|
@@ -12,77 +12,89 @@ This plugin was made to easily get an image related to a post. This is the defa
|
|
12 |
* Image embedded in the post content.
|
13 |
* Default/fallback image.
|
14 |
|
15 |
-
## Usage
|
16 |
|
17 |
The basic function call for the plugin is like so:
|
18 |
|
19 |
-
|
|
|
|
|
20 |
|
21 |
This is the only function you should use from the plugin. It expects to be called within the WordPress posts loop unless you pass it a post ID directly (`post_id` argument).
|
22 |
|
23 |
To do more with the image script, you'll need to use what's called [function-style parameters](http://codex.wordpress.org/Template_Tags/How_to_Pass_Tag_Parameters#Tags_with_PHP_function-style_parameters). The following is a basic example of using function-style parameters.
|
24 |
|
25 |
-
|
|
|
|
|
26 |
|
27 |
-
### Parameters
|
28 |
|
29 |
The `get_the_image()` function accepts a single parameter of `$args`, which is an array of parameters for deciding how to load an image. The following is the list of all the default arguments.
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
* `post_id` - The ID of the post to get the image for. This defaults to the current post in the loop.
|
88 |
* `order` - Order of methods used to grab images. Defaults to `array( 'meta_key', 'featured', 'attachment', 'scan', 'scan_raw', 'callback', 'default' )`.
|
@@ -95,7 +107,9 @@ The `get_the_image()` function accepts a single parameter of `$args`, which is a
|
|
95 |
* `default` - Will take the input of an image URL and use it if no other images are found (no default set).
|
96 |
* `split_content` - Whether to split the raw HTML of the found image from the post content. Default is `false`. This method is only used with the `scan_raw` method.
|
97 |
* `size` - This refers to the size of an attached image. You can choose between `thumbnail`, `medium`, `large`, `full`, or any custom image size you have available (the default is `thumbnail` or `post-thumbnail` if theme has set a thumbnail size).
|
98 |
-
* `
|
|
|
|
|
99 |
* `image_class` - You can give an additional class to the image for use in your CSS.
|
100 |
* `width` - Set the width of the image on output.
|
101 |
* `height` - Set the height of the image on output.
|
@@ -110,232 +124,131 @@ The `get_the_image()` function accepts a single parameter of `$args`, which is a
|
|
110 |
* `format` - What format to return the image in. If set to `array` the return value of the function will be an array of `<img>` attributes. All other values will return the `<img>` element.
|
111 |
* `echo` - If set to `true`, the image is shown on the page. If set to `false`, the image will be returned to use in your own function. (Set to `true` by default.)
|
112 |
|
113 |
-
### Some usage examples
|
114 |
|
115 |
-
#### Example 1
|
116 |
|
117 |
Let's suppose that you want to add thumbnails to your category archive pages. What you'll need to do is open your `category.php` file and add this code within the Loop:
|
118 |
|
119 |
-
|
|
|
|
|
120 |
|
121 |
By default, that will look for an image with the custom field **key** `Thumbnail` and `thumbnail`. If that image doesn't exist, it will check if a post image has been set. If that image doesn't exist, it will search for any images attached to your post.
|
122 |
|
123 |
-
#### Example 2
|
124 |
|
125 |
-
Let's suppose you want a full-sized image and maybe you want to grab it by a custom field key of `
|
126 |
|
127 |
-
|
|
|
|
|
128 |
|
129 |
If no feature image exists by custom field, it will look for images attached to your post.
|
130 |
|
131 |
-
#### Example 3
|
132 |
|
133 |
If you want to have a sort of fallback image, then you can set an image for the script to default to if no other images are found.
|
134 |
|
135 |
-
|
|
|
|
|
136 |
|
137 |
-
#### Example 4
|
138 |
|
139 |
You can even make the script scan for images that have been added to your post with this:
|
140 |
|
141 |
-
|
|
|
|
|
142 |
|
143 |
-
#### Example 5
|
144 |
|
145 |
-
Saving an image to the `
|
146 |
|
147 |
-
|
|
|
|
|
148 |
|
149 |
-
### A real-world example
|
150 |
|
151 |
-
This is an example Loop, which may differ slightly from your theme, but the concept is the same. The call to get the image can go anywhere between the opening and closing lines.
|
152 |
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
</div>
|
166 |
-
|
167 |
-
<?php endwhile; endif; ?>
|
168 |
|
169 |
-
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
Sometimes, we stop using plugins, but we forget to remove the function calls to the plugin in our theme files. When deactivated, this causes errors. To protect yourself from these errors, you can call the image script like this:
|
172 |
|
173 |
-
|
174 |
-
|
175 |
-
|
|
|
|
|
176 |
|
177 |
Basically, this just checks to see if the plugin is activated and has loaded the appropriate function.
|
178 |
|
179 |
-
## Styling your images
|
180 |
|
181 |
The plugin will help you style your images by giving you some CSS classes to work with. It will turn your custom field keys and default size into CSS classes. You can also choose to input your own class.
|
182 |
|
183 |
By default, you can add this to your CSS:
|
184 |
|
185 |
-
|
|
|
|
|
186 |
|
187 |
Let's suppose you've used this code:
|
188 |
|
189 |
-
|
|
|
|
|
190 |
|
191 |
This will give you these CSS classes to work with:
|
192 |
|
193 |
-
|
194 |
-
|
195 |
-
|
|
|
|
|
196 |
|
197 |
You can also input a custom CSS class like so:
|
198 |
|
199 |
-
|
|
|
|
|
200 |
|
201 |
You will still have the `size` and `meta_key` classes plus your additional class:
|
202 |
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
### Version 1.0.1 ###
|
209 |
-
|
210 |
-
* Changed priority of `split_content` filter to make sure images are split from the content.
|
211 |
-
|
212 |
-
### Version 1.0.0 ###
|
213 |
-
|
214 |
-
#### General Changes: ####
|
215 |
-
|
216 |
-
* `the_post_thumbnail` argument deprecated in favor of `featured`.
|
217 |
-
* `image_scan` argument deprecated in favor of `scan` or `scan_raw`.
|
218 |
-
* `default_image` argument deprecated in favor of `default`.
|
219 |
-
* `order_of_image` argument removed with no replacement.
|
220 |
-
|
221 |
-
#### Enhancements: ####
|
222 |
-
|
223 |
-
* Re-coded how the image script works by encapsulating the functionality into a single class rather than multiple functions. This makes it much easier to reuse code and paves the way for more improvements in the future.
|
224 |
-
* New `scan_raw` argument for pulling an image (straight HTML) directly from the post content.
|
225 |
-
* New `split_content` argument for removing an image from the post content if one is found. Used only in conjunction with the `scan_raw` argument.
|
226 |
-
* New `order` argument for changing the order in which the script looks for images.
|
227 |
-
* Better support and handling for sub-attachments (e.g., featured images for audio/video attachments).
|
228 |
-
* Support for Schema.org microdata. `itemprop="image"` attribute added to image outputs where possible.
|
229 |
-
* New image orientation class if the width and height are available. Class can be `landscape` or `portrait`.
|
230 |
-
* Default image size is `post-thumbnail` if the theme has set this size. Otherwise, `thumbnail` is the default size.
|
231 |
-
* Supports the ability to get embedded images via WordPress' image embeds (Instagram, Flickr, etc.) via the `scan*` methods.
|
232 |
-
* New filter hook: `get_the_image_post_content`. Used when checking the post content.
|
233 |
-
* Added `min_width` and `min_height` arguments (doesn't work with `scan*` methods).
|
234 |
-
|
235 |
-
### Version 0.9.0 ###
|
236 |
-
|
237 |
-
#### Enhancements: ####
|
238 |
-
|
239 |
-
* Caption support. FTW!
|
240 |
-
* Multiple image classes now allowed via the `image_class` argument.
|
241 |
-
* Use current theme's `post-thumbnail` as default image size if set via `set_post_thumbnail_size()`.
|
242 |
-
|
243 |
-
#### Bug fixes: ####
|
244 |
-
|
245 |
-
* Use the WordPress-saved attachment alt text for the image.
|
246 |
-
* Only add `$out['src']` if `$out['url']` is set when returning as an array.
|
247 |
-
* Allow `https` when returning as an array.
|
248 |
-
* Use the correct variable (`$attachment_id`) when getting an image via attachment.
|
249 |
-
|
250 |
-
### Version 0.8.1 ###
|
251 |
-
|
252 |
-
* Use correct `$attachment_id` variable instead of `$id`.
|
253 |
-
* Pass full `$image` array to the `get_the_image_meta_key_save()` function so that it saves correctly.
|
254 |
-
* Only use `before` and `after` arguments if an image is found.
|
255 |
-
* General code formatting updated.
|
256 |
-
|
257 |
-
### Version 0.8 ###
|
258 |
-
|
259 |
-
* Inline docs updates.
|
260 |
-
* Added the `before` argument to output HTML before the image.
|
261 |
-
* Added the `after` argument to output HTML after the image.
|
262 |
-
* Added the `thumbnail_id_save` argument to allow the attached image to be saved as the thumbnail/featured image.
|
263 |
-
* Get the post ID via `get_the_ID()` rather than the global `$post` object.
|
264 |
-
* Fixed debug notice with `$image_html`.
|
265 |
-
* Moved the `*_fetch_post_thumbnail_html` hooks into the main function and only fire them if displaying to the screen.
|
266 |
-
* Simplified the `meta_key` logic.
|
267 |
-
* Completely rewrote the `attachment` logic.
|
268 |
-
* Sanitize classes with `sanitize_html_class()`.
|
269 |
-
|
270 |
-
### Version 0.7 ###
|
271 |
-
|
272 |
-
* Deprecated and replaced functions that lacked the `get_the_image_` prefix.
|
273 |
-
* New cache delete functions that delete when a post or post meta is updated.
|
274 |
-
* Fixed notice when `image_scan` was used.
|
275 |
-
|
276 |
-
### Version 0.6.2 ###
|
277 |
-
|
278 |
-
* Updated the cache to save by post ID instead of a single object.
|
279 |
-
* Minor code adjustments.
|
280 |
-
|
281 |
-
### Version 0.6.1 ###
|
282 |
-
|
283 |
-
* Updated inline documentation of the code.
|
284 |
-
* Smarter `meta_key` logic, which allows a single meta key or an array of keys to be used.
|
285 |
-
* Set `custom_key` and `default_size` to `null` by default since they're deprecated.
|
286 |
-
|
287 |
-
### Version 0.6 ###
|
288 |
-
|
289 |
-
* Deprecated `custom_key` in favor of `meta_key`.
|
290 |
-
* Added the `meta_key_save` argument to allow users to save the image as a meta key/value pair.
|
291 |
-
* Added a `callback` argument to allow developers to create a custom callback function.
|
292 |
-
* Added a `cache` argument, which allows users to turn off caching.
|
293 |
-
|
294 |
-
### Version 0.5 ###
|
295 |
-
|
296 |
-
* Added support for persistent-caching plugins.
|
297 |
-
* Switched the `default_size` argument to `size` to be more in line with the WordPress post thumbnail arguments, but `default_size` will still work.
|
298 |
-
* Now using `wp_kses_hair()` to extract image attributes when using the `array` value for `format`.
|
299 |
-
* Image `alt` text will now use the attachment description if one has been given rather than the post title.
|
300 |
-
* Updated the `readme.html` instructions for using the plugin.
|
301 |
-
|
302 |
-
### Version 0.4 ###
|
303 |
-
|
304 |
-
* Dropped support for older versions of WordPress. Now only compatible with 2.9+.
|
305 |
-
* Added support for `the_post_thumbnail()`, which is WordPress 2.9's new image functionality.
|
306 |
-
* New function: `image_by_the_post_thumbnail()`.
|
307 |
-
* Documented more of the code, so the inline PHP doc is updated.
|
308 |
-
* Cleaned up some of the old legacy code that's no longer needed.
|
309 |
-
|
310 |
-
### Version 0.3.3 ###
|
311 |
-
|
312 |
-
* General code cleanup
|
313 |
-
* Added the `get_the_image` filter hook.
|
314 |
-
|
315 |
-
### Version 0.3.2 ###
|
316 |
-
|
317 |
-
* General code cleanup.
|
318 |
-
* More efficient and logical code.
|
319 |
-
* Beefed up the inline documentation so developers can better understand the code.
|
320 |
-
* Added a GPL license.txt file.
|
321 |
-
|
322 |
-
### Version 0.3.1 ###
|
323 |
-
|
324 |
-
* Fixed the default image and image scan features.
|
325 |
-
|
326 |
-
### Version 0.3 ###
|
327 |
-
|
328 |
-
* Changed methods of calling the image script.
|
329 |
-
* Added more parameters.
|
330 |
|
331 |
-
## Support
|
332 |
|
333 |
-
I run a WordPress community called [Theme Hybrid](
|
334 |
|
335 |
I know. I know. You might not want to pay for support, but just consider it a donation to the project. To continue making cool, GPL-licensed plugins and having the time to support them, I must pay the bills.
|
336 |
|
337 |
-
## Copyright and License
|
338 |
|
339 |
Get the Image is licensed under the [GNU GPL](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html), version 2 or later.
|
340 |
|
341 |
-
2008 – 
|
1 |
+
# Get the Image
|
2 |
|
3 |
Get the Image is a plugin that grabs images for you. It was designed to make the process of things such as adding thumbnails, feature images, and/or other images to your blog much easier, but it's so much more than that. It is an image-based representation of your WordPress posts.
|
4 |
|
5 |
+
## What the plugin does
|
6 |
|
7 |
This plugin was made to easily get an image related to a post. This is the default method order in which the plugin attempts to grab an image.
|
8 |
|
12 |
* Image embedded in the post content.
|
13 |
* Default/fallback image.
|
14 |
|
15 |
+
## Usage
|
16 |
|
17 |
The basic function call for the plugin is like so:
|
18 |
|
19 |
+
```
|
20 |
+
<?php get_the_image(); ?>
|
21 |
+
```
|
22 |
|
23 |
This is the only function you should use from the plugin. It expects to be called within the WordPress posts loop unless you pass it a post ID directly (`post_id` argument).
|
24 |
|
25 |
To do more with the image script, you'll need to use what's called [function-style parameters](http://codex.wordpress.org/Template_Tags/How_to_Pass_Tag_Parameters#Tags_with_PHP_function-style_parameters). The following is a basic example of using function-style parameters.
|
26 |
|
27 |
+
```
|
28 |
+
<?php get_the_image( array( 'meta_key' => 'thumbnail', 'size' => 'thumbnail' ) ); ?>
|
29 |
+
```
|
30 |
|
31 |
+
### Parameters
|
32 |
|
33 |
The `get_the_image()` function accepts a single parameter of `$args`, which is an array of parameters for deciding how to load an image. The following is the list of all the default arguments.
|
34 |
|
35 |
+
```
|
36 |
+
$defaults = array(
|
37 |
+
|
38 |
+
// Post the image is associated with.
|
39 |
+
'post_id' => get_the_ID(),
|
40 |
+
|
41 |
+
// Method order (see methods below).
|
42 |
+
'order' => array( 'meta_key', 'featured', 'attachment', 'scan', 'scan_raw', 'callback', 'default' ),
|
43 |
+
|
44 |
+
// Methods of getting an image (in order).
|
45 |
+
'meta_key' => array( 'Thumbnail', 'thumbnail' ), // array|string
|
46 |
+
'featured' => true,
|
47 |
+
'attachment' => true,
|
48 |
+
'scan' => false,
|
49 |
+
'scan_raw' => false, // Note: don't use the array format option with this.
|
50 |
+
'callback' => null,
|
51 |
+
'default' => false,
|
52 |
+
|
53 |
+
// Split image from post content (by default, only used with the 'scan_raw' option).
|
54 |
+
'split_content' => false,
|
55 |
+
|
56 |
+
// Attachment-specific arguments.
|
57 |
+
'size' => has_image_size( 'post-thumbnail' ) ? 'post-thumbnail' : 'thumbnail',
|
58 |
+
|
59 |
+
// Key (image size) / Value ( width or px-density descriptor) pairs (e.g., 'large' => '2x' )
|
60 |
+
'srcset_sizes' => array(),
|
61 |
+
|
62 |
+
// Format/display of image.
|
63 |
+
'link' => 'post', // string|bool - 'post' (true), 'file', 'attachment', false
|
64 |
+
'link_class' => '',
|
65 |
+
'image_class' => false,
|
66 |
+
'image_attr' => array(),
|
67 |
+
'width' => false,
|
68 |
+
'height' => false,
|
69 |
+
'before' => '',
|
70 |
+
'after' => '',
|
71 |
+
|
72 |
+
// Minimum allowed sizes.
|
73 |
+
'min_width' => 0,
|
74 |
+
'min_height' => 0,
|
75 |
+
|
76 |
+
// Captions.
|
77 |
+
'caption' => false, // Default WP [caption] requires a width.
|
78 |
+
|
79 |
+
// Saving the image.
|
80 |
+
'meta_key_save' => false, // Save as metadata (string).
|
81 |
+
'thumbnail_id_save' => false, // Set 'featured image'.
|
82 |
+
'cache' => true, // Cache the image.
|
83 |
+
|
84 |
+
// Return/echo image.
|
85 |
+
'format' => 'img',
|
86 |
+
'echo' => true,
|
87 |
+
|
88 |
+
// Deprecated arguments.
|
89 |
+
'custom_key' => null, // @deprecated 0.6.0 Use 'meta_key'.
|
90 |
+
'default_size' => null, // @deprecated 0.5.0 Use 'size'.
|
91 |
+
'the_post_thumbnail' => null, // @deprecated 1.0.0 Use 'featured'.
|
92 |
+
'image_scan' => null, // @deprecated 1.0.0 Use 'scan' or 'scan_raw'.
|
93 |
+
'default_image' => null, // @deprecated 1.0.0 Use 'default'.
|
94 |
+
'order_of_image' => null, // @deprecated 1.0.0 No replacement.
|
95 |
+
'link_to_post' => null, // @deprecated 1.1.0 Use 'link'.
|
96 |
+
);
|
97 |
+
```
|
98 |
|
99 |
* `post_id` - The ID of the post to get the image for. This defaults to the current post in the loop.
|
100 |
* `order` - Order of methods used to grab images. Defaults to `array( 'meta_key', 'featured', 'attachment', 'scan', 'scan_raw', 'callback', 'default' )`.
|
107 |
* `default` - Will take the input of an image URL and use it if no other images are found (no default set).
|
108 |
* `split_content` - Whether to split the raw HTML of the found image from the post content. Default is `false`. This method is only used with the `scan_raw` method.
|
109 |
* `size` - This refers to the size of an attached image. You can choose between `thumbnail`, `medium`, `large`, `full`, or any custom image size you have available (the default is `thumbnail` or `post-thumbnail` if theme has set a thumbnail size).
|
110 |
+
* `link` - What to link the image to. `'post'` (links to the post), `'file'` (links to the image file), `'attachment'` (links to the attachment page if image is attachment), or `false` (link to nothing).
|
111 |
+
* `link_class` - Add a custom HTML class to the link.
|
112 |
+
* `image_attr` - Array of image attributes (key is the attribute name, value is the attribute value).
|
113 |
* `image_class` - You can give an additional class to the image for use in your CSS.
|
114 |
* `width` - Set the width of the image on output.
|
115 |
* `height` - Set the height of the image on output.
|
124 |
* `format` - What format to return the image in. If set to `array` the return value of the function will be an array of `<img>` attributes. All other values will return the `<img>` element.
|
125 |
* `echo` - If set to `true`, the image is shown on the page. If set to `false`, the image will be returned to use in your own function. (Set to `true` by default.)
|
126 |
|
127 |
+
### Some usage examples
|
128 |
|
129 |
+
#### Example 1
|
130 |
|
131 |
Let's suppose that you want to add thumbnails to your category archive pages. What you'll need to do is open your `category.php` file and add this code within the Loop:
|
132 |
|
133 |
+
```
|
134 |
+
<?php get_the_image(); ?>
|
135 |
+
```
|
136 |
|
137 |
By default, that will look for an image with the custom field **key** `Thumbnail` and `thumbnail`. If that image doesn't exist, it will check if a post image has been set. If that image doesn't exist, it will search for any images attached to your post.
|
138 |
|
139 |
+
#### Example 2
|
140 |
|
141 |
+
Let's suppose you want a full-sized image and maybe you want to grab it by a custom field key of `feature`. Depending on your theme, this will need to go within the Loop in whatever file is calling the featured article.
|
142 |
|
143 |
+
```
|
144 |
+
<?php get_the_image( array( 'meta_key' => 'feature', 'size' => 'full' ) ); ?>
|
145 |
+
```
|
146 |
|
147 |
If no feature image exists by custom field, it will look for images attached to your post.
|
148 |
|
149 |
+
#### Example 3
|
150 |
|
151 |
If you want to have a sort of fallback image, then you can set an image for the script to default to if no other images are found.
|
152 |
|
153 |
+
```
|
154 |
+
<?php get_the_image( array( 'default' => 'http://mysite.com/wp-content/uploads/example.jpg' ) ); ?>
|
155 |
+
```
|
156 |
|
157 |
+
#### Example 4
|
158 |
|
159 |
You can even make the script scan for images that have been added to your post with this:
|
160 |
|
161 |
+
```
|
162 |
+
<?php get_the_image( array( 'scan' => true ) ); ?>
|
163 |
+
```
|
164 |
|
165 |
+
#### Example 5
|
166 |
|
167 |
+
Saving an image to the `thumbnail` custom field automatically.
|
168 |
|
169 |
+
```
|
170 |
+
<?php get_the_image( array( 'meta_key_save' => 'thumbnail' ) ); ?>
|
171 |
+
```
|
172 |
|
173 |
+
### A real-world example
|
174 |
|
175 |
+
This is an example Loop, which may differ slightly from your theme, but the concept is the same. The call to get the image can go anywhere between the opening and closing lines. In the following example, the image will appear before the post title.
|
176 |
|
177 |
+
```
|
178 |
+
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
|
179 |
+
|
180 |
+
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
|
181 |
+
|
182 |
+
<?php get_the_image( array( size' => 'medium', 'image_class' => 'feature' ) ); ?>
|
183 |
+
|
184 |
+
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
|
185 |
+
|
186 |
+
<div class="entry-summary">
|
187 |
+
<?the_excerpt(); ?>
|
|
|
188 |
</div>
|
|
|
|
|
189 |
|
190 |
+
</div>
|
191 |
+
|
192 |
+
<?php endwhile; endif; ?>
|
193 |
+
```
|
194 |
+
|
195 |
+
### Protect yourself from errors in the future
|
196 |
|
197 |
Sometimes, we stop using plugins, but we forget to remove the function calls to the plugin in our theme files. When deactivated, this causes errors. To protect yourself from these errors, you can call the image script like this:
|
198 |
|
199 |
+
```
|
200 |
+
<?php if ( function_exists( 'get_the_image' ) ) {
|
201 |
+
get_the_image();
|
202 |
+
} ?>
|
203 |
+
```
|
204 |
|
205 |
Basically, this just checks to see if the plugin is activated and has loaded the appropriate function.
|
206 |
|
207 |
+
## Styling your images
|
208 |
|
209 |
The plugin will help you style your images by giving you some CSS classes to work with. It will turn your custom field keys and default size into CSS classes. You can also choose to input your own class.
|
210 |
|
211 |
By default, you can add this to your CSS:
|
212 |
|
213 |
+
```
|
214 |
+
img.thumbnail {}
|
215 |
+
```
|
216 |
|
217 |
Let's suppose you've used this code:
|
218 |
|
219 |
+
```
|
220 |
+
<?php get_the_image( array( 'meta_key' => array( 'Donkey Kong', 'mario' ), 'size' => 'full' ) ); ?>
|
221 |
+
```
|
222 |
|
223 |
This will give you these CSS classes to work with:
|
224 |
|
225 |
+
```
|
226 |
+
img.full {}
|
227 |
+
img.donkey-kong {}
|
228 |
+
img.mario {}
|
229 |
+
```
|
230 |
|
231 |
You can also input a custom CSS class like so:
|
232 |
|
233 |
+
```
|
234 |
+
<?php get_the_image( array( 'image_class' => 'custom-image' ) ); ?>
|
235 |
+
```
|
236 |
|
237 |
You will still have the `size` and `meta_key` classes plus your additional class:
|
238 |
|
239 |
+
```
|
240 |
+
img.custom-image {}
|
241 |
+
img.thumbnail {}
|
242 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
|
244 |
+
## Support
|
245 |
|
246 |
+
I run a WordPress community called [Theme Hybrid](https://themehybrid.com), which is where I fully support all of my WordPress projects, including plugins. You can sign up for an account to get plugin support for a small yearly fee.
|
247 |
|
248 |
I know. I know. You might not want to pay for support, but just consider it a donation to the project. To continue making cool, GPL-licensed plugins and having the time to support them, I must pay the bills.
|
249 |
|
250 |
+
## Copyright and License
|
251 |
|
252 |
Get the Image is licensed under the [GNU GPL](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html), version 2 or later.
|
253 |
|
254 |
+
2008 – 2017 © [Justin Tadlock](http://justintadlock.com).
|
readme.txt
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
=== Get the Image ===
|
2 |
|
3 |
Contributors: greenshady
|
4 |
-
Donate link:
|
5 |
Tags: image, images, thumbnail
|
6 |
Requires at least: 3.9
|
7 |
-
|
|
|
|
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -12,7 +14,7 @@ An easy-to-use image script for adding things such as thumbnail, slider, gallery
|
|
12 |
|
13 |
== Description ==
|
14 |
|
15 |
-
Get the Image is one of the most advanced thumbnail/image scripts ever created for WordPress.
|
16 |
|
17 |
It is used everywhere from small blogs to large, enterprise-level solutions like [WordPress.com VIP](http://vip.wordpress.com/). Get the Image offers something for everybody. Much of the reason for its success is because it uses standard WordPress code and methods for doing what it needs to do, which is to simply grab images.
|
18 |
|
@@ -20,7 +22,11 @@ The plugin was designed to make the process of adding thumbnail, featured, slide
|
|
20 |
|
21 |
This is a highly intuitive script that can grab an image by custom field input, WordPress' featured image, post attachment, or extracting it from the post's content. Plus, a lot more!
|
22 |
|
23 |
-
###
|
|
|
|
|
|
|
|
|
24 |
|
25 |
The original plugin was in launched 2008, which means it has several years of solid testing and development behind it. It was created at a time when WordPress had very little native media support. At the time, it was mostly used as a "thumbnail" script for magazine-/news-style sites. But, it has grown into a much more flexible script over the years.
|
26 |
|
@@ -30,47 +36,45 @@ The plugin has been downloaded 100,000s of times and is used on millions of site
|
|
30 |
|
31 |
Other image plugins have come and gone, but Get the Image has stood the test of time with several years of successful installs and happy users.
|
32 |
|
33 |
-
### Professional support
|
34 |
-
|
35 |
-
If you need professional plugin support from me, the plugin author, you can access the support forums at [Theme Hybrid](http://themehybrid.com/support), which is a professional WordPress help/support site where I handle support for all my plugins and themes for a community of 40,000+ users (and growing).
|
36 |
|
37 |
-
|
38 |
|
39 |
-
|
40 |
|
41 |
-
|
42 |
|
43 |
-
|
44 |
|
45 |
-
|
46 |
|
47 |
-
|
48 |
-
2. Activate the plugin through the 'Plugins' menu in WordPress.
|
49 |
-
3. Add the appropriate code to your template files as outlined in the `readme.md` file.
|
50 |
|
51 |
== Frequently Asked Questions ==
|
52 |
|
53 |
-
### Why was this plugin created?
|
54 |
|
55 |
It was originally created to work with magazine/news themes. These types of themes typically required a lot of work when inputting images to make them look good. This plugin was developed to make that process much easier for the end user. But, at the same time, it needed to be flexible enough to handle anything.
|
56 |
|
57 |
However, over the years, it has grown to be one of the most robust image scripts for WordPress.
|
58 |
|
59 |
-
### How does it grab images?
|
60 |
|
61 |
-
1.
|
62 |
-
2. If no image is added by custom field, check for
|
63 |
3. If no image is found, it grabs an image attached to your post.
|
64 |
4. If no image is attached, it can extract an image from your post content (off by default).
|
65 |
5. If no image is found at this point, it will fall back to a default image (not set by default).
|
66 |
|
67 |
-
### How do I add it to my theme?
|
68 |
|
69 |
There are several methods, but in general, you would use this call within The Loop.
|
70 |
|
71 |
-
|
|
|
|
|
72 |
|
73 |
-
To see all methods and options, refer to the `readme.md` file included with the plugin download or view
|
74 |
|
75 |
== Screenshots ==
|
76 |
|
@@ -80,125 +84,4 @@ To see all methods and options, refer to the `readme.md` file included with the
|
|
80 |
|
81 |
== Changelog ==
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
* Changed priority of `split_content` filter to make sure images are split from the content.
|
86 |
-
|
87 |
-
### Version 1.0.0 ###
|
88 |
-
|
89 |
-
#### General Changes: ####
|
90 |
-
|
91 |
-
* `the_post_thumbnail` argument deprecated in favor of `featured`.
|
92 |
-
* `image_scan` argument deprecated in favor of `scan` or `scan_raw`.
|
93 |
-
* `default_image` argument deprecated in favor of `default`.
|
94 |
-
* `order_of_image` argument removed with no replacement.
|
95 |
-
|
96 |
-
#### Enhancements: ####
|
97 |
-
|
98 |
-
* Re-coded how the image script works by encapsulating the functionality into a single class rather than multiple functions. This makes it much easier to reuse code and paves the way for more improvements in the future.
|
99 |
-
* New `scan_raw` argument for pulling an image (straight HTML) directly from the post content.
|
100 |
-
* New `split_content` argument for removing an image from the post content if one is found. Used only in conjunction with the `scan_raw` argument.
|
101 |
-
* New `order` argument for changing the order in which the script looks for images.
|
102 |
-
* Better support and handling for sub-attachments (e.g., featured images for audio/video attachments).
|
103 |
-
* Support for Schema.org microdata. `itemprop="image"` attribute added to image outputs where possible.
|
104 |
-
* New image orientation class if the width and height are available. Class can be `landscape` or `portrait`.
|
105 |
-
* Default image size is `post-thumbnail` if the theme has set this size. Otherwise, `thumbnail` is the default size.
|
106 |
-
* Supports the ability to get embedded images via WordPress' image embeds (Instagram, Flickr, etc.) via the `scan*` methods.
|
107 |
-
* New filter hook: `get_the_image_post_content`. Used when checking the post content.
|
108 |
-
* Added `min_width` and `min_height` arguments (doesn't work with `scan*` methods).
|
109 |
-
|
110 |
-
### Version 0.9.0 ###
|
111 |
-
|
112 |
-
#### Enhancements: ####
|
113 |
-
|
114 |
-
* Caption support. FTW!
|
115 |
-
* Multiple image classes now allowed via the `image_class` argument.
|
116 |
-
* Use current theme's `post-thumbnail` as default image size if set via `set_post_thumbnail_size()`.
|
117 |
-
|
118 |
-
#### Bug fixes: ####
|
119 |
-
|
120 |
-
* Use the WordPress-saved attachment alt text for the image.
|
121 |
-
* Only add `$out['src']` if `$out['url']` is set when returning as an array.
|
122 |
-
* Allow `https` when returning as an array.
|
123 |
-
* Use the correct variable (`$attachment_id`) when getting an image via attachment.
|
124 |
-
|
125 |
-
### Version 0.8.1 ###
|
126 |
-
|
127 |
-
* Use correct `$attachment_id` variable instead of `$id`.
|
128 |
-
* Pass full `$image` array to the `get_the_image_meta_key_save()` function so that it saves correctly.
|
129 |
-
* Only use `before` and `after` arguments if an image is found.
|
130 |
-
* General code formatting updated.
|
131 |
-
|
132 |
-
### Version 0.8 ###
|
133 |
-
|
134 |
-
* Inline docs updates.
|
135 |
-
* Added the `before` argument to output HTML before the image.
|
136 |
-
* Added the `after` argument to output HTML after the image.
|
137 |
-
* Added the `thumbnail_id_save` argument to allow the attached image to be saved as the thumbnail/featured image.
|
138 |
-
* Get the post ID via `get_the_ID()` rather than the global `$post` object.
|
139 |
-
* Fixed debug notice with `$image_html`.
|
140 |
-
* Moved the `*_fetch_post_thumbnail_html` hooks into the main function and only fire them if displaying to the screen.
|
141 |
-
* Simplified the `meta_key` logic.
|
142 |
-
* Completely rewrote the `attachment` logic.
|
143 |
-
* Sanitize classes with `sanitize_html_class()`.
|
144 |
-
|
145 |
-
### Version 0.7 ###
|
146 |
-
|
147 |
-
* Deprecated and replaced functions that lacked the `get_the_image_` prefix.
|
148 |
-
* New cache delete functions that delete when a post or post meta is updated.
|
149 |
-
* Fixed notice when `image_scan` was used.
|
150 |
-
|
151 |
-
### Version 0.6.2 ###
|
152 |
-
|
153 |
-
* Updated the cache to save by post ID instead of a single object.
|
154 |
-
* Minor code adjustments.
|
155 |
-
|
156 |
-
### Version 0.6.1 ###
|
157 |
-
|
158 |
-
* Updated inline documentation of the code.
|
159 |
-
* Smarter `meta_key` logic, which allows a single meta key or an array of keys to be used.
|
160 |
-
* Set `custom_key` and `default_size` to `null` by default since they're deprecated.
|
161 |
-
|
162 |
-
### Version 0.6 ###
|
163 |
-
|
164 |
-
* Deprecated `custom_key` in favor of `meta_key`.
|
165 |
-
* Added the `meta_key_save` argument to allow users to save the image as a meta key/value pair.
|
166 |
-
* Added a `callback` argument to allow developers to create a custom callback function.
|
167 |
-
* Added a `cache` argument, which allows users to turn off caching.
|
168 |
-
|
169 |
-
### Version 0.5 ###
|
170 |
-
|
171 |
-
* Added support for persistent-caching plugins.
|
172 |
-
* Switched the `default_size` argument to `size` to be more in line with the WordPress post thumbnail arguments, but `default_size` will still work.
|
173 |
-
* Now using `wp_kses_hair()` to extract image attributes when using the `array` value for `format`.
|
174 |
-
* Image `alt` text will now use the attachment description if one has been given rather than the post title.
|
175 |
-
* Updated the `readme.html` instructions for using the plugin.
|
176 |
-
|
177 |
-
### Version 0.4 ###
|
178 |
-
|
179 |
-
* Dropped support for older versions of WordPress. Now only compatible with 2.9+.
|
180 |
-
* Added support for `the_post_thumbnail()`, which is WordPress 2.9's new image functionality.
|
181 |
-
* New function: `image_by_the_post_thumbnail()`.
|
182 |
-
* Documented more of the code, so the inline PHP doc is updated.
|
183 |
-
* Cleaned up some of the old legacy code that's no longer needed.
|
184 |
-
|
185 |
-
### Version 0.3.3 ###
|
186 |
-
|
187 |
-
* General code cleanup
|
188 |
-
* Added the `get_the_image` filter hook.
|
189 |
-
|
190 |
-
### Version 0.3.2 ###
|
191 |
-
|
192 |
-
* General code cleanup.
|
193 |
-
* More efficient and logical code.
|
194 |
-
* Beefed up the inline documentation so developers can better understand the code.
|
195 |
-
* Added a GPL license.txt file.
|
196 |
-
|
197 |
-
### Version 0.3.1 ###
|
198 |
-
|
199 |
-
* Fixed the default image and image scan features.
|
200 |
-
|
201 |
-
### Version 0.3 ###
|
202 |
-
|
203 |
-
* Changed methods of calling the image script.
|
204 |
-
* Added more parameters.
|
1 |
=== Get the Image ===
|
2 |
|
3 |
Contributors: greenshady
|
4 |
+
Donate link: https://themehybrid.com/donate
|
5 |
Tags: image, images, thumbnail
|
6 |
Requires at least: 3.9
|
7 |
+
Tested up to: 4.8.2
|
8 |
+
Requires PHP: 5.2
|
9 |
+
Stable tag: 1.1.0
|
10 |
License: GPLv2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
14 |
|
15 |
== Description ==
|
16 |
|
17 |
+
Get the Image is one of the most advanced thumbnail/image scripts ever created for WordPress.
|
18 |
|
19 |
It is used everywhere from small blogs to large, enterprise-level solutions like [WordPress.com VIP](http://vip.wordpress.com/). Get the Image offers something for everybody. Much of the reason for its success is because it uses standard WordPress code and methods for doing what it needs to do, which is to simply grab images.
|
20 |
|
22 |
|
23 |
This is a highly intuitive script that can grab an image by custom field input, WordPress' featured image, post attachment, or extracting it from the post's content. Plus, a lot more!
|
24 |
|
25 |
+
### Before using
|
26 |
+
|
27 |
+
Please note that Get the Image requires that you understand and know how to edit your theme's PHP code, at least to the extent of copying and pasting one line of code. If you're not comfortable doing this, it's best to ask that your theme author integrate the code necessary to support this plugin.
|
28 |
+
|
29 |
+
### A little history
|
30 |
|
31 |
The original plugin was in launched 2008, which means it has several years of solid testing and development behind it. It was created at a time when WordPress had very little native media support. At the time, it was mostly used as a "thumbnail" script for magazine-/news-style sites. But, it has grown into a much more flexible script over the years.
|
32 |
|
36 |
|
37 |
Other image plugins have come and gone, but Get the Image has stood the test of time with several years of successful installs and happy users.
|
38 |
|
39 |
+
### Professional support
|
|
|
|
|
40 |
|
41 |
+
If you need professional plugin support from me, the plugin author, you can join the club at [Theme Hybrid](https://themehybrid.com/club), which is a professional WordPress help/support site where I handle support for all my plugins and themes for a community of 75,000+ users (and growing).
|
42 |
|
43 |
+
### Plugin Development
|
44 |
|
45 |
+
If you're a theme author, plugin author, or just a code hobbyist, you can follow the development of this plugin on its [GitHub repository](https://github.com/justintadlock/get-the-image).
|
46 |
|
47 |
+
### Donations
|
48 |
|
49 |
+
Yes, I do accept donations. If you want to donate, you can do so from my [donations page](https://themehybrid.com/donate) or grab me something from my [Amazon Wish List](http://a.co/flUb0ns).
|
50 |
|
51 |
+
I appreciate all donations, no matter the size. Further development of this plugin is not contingent on donations, but they are always a nice incentive.
|
|
|
|
|
52 |
|
53 |
== Frequently Asked Questions ==
|
54 |
|
55 |
+
### Why was this plugin created?
|
56 |
|
57 |
It was originally created to work with magazine/news themes. These types of themes typically required a lot of work when inputting images to make them look good. This plugin was developed to make that process much easier for the end user. But, at the same time, it needed to be flexible enough to handle anything.
|
58 |
|
59 |
However, over the years, it has grown to be one of the most robust image scripts for WordPress.
|
60 |
|
61 |
+
### How does it grab images?
|
62 |
|
63 |
+
1. Looks for an image by custom field (one of your choosing).
|
64 |
+
2. If no image is added by custom field, check for a featured image.
|
65 |
3. If no image is found, it grabs an image attached to your post.
|
66 |
4. If no image is attached, it can extract an image from your post content (off by default).
|
67 |
5. If no image is found at this point, it will fall back to a default image (not set by default).
|
68 |
|
69 |
+
### How do I add it to my theme?
|
70 |
|
71 |
There are several methods, but in general, you would use this call within The Loop.
|
72 |
|
73 |
+
```
|
74 |
+
<?php if ( function_exists( 'get_the_image' ) ) get_the_image(); ?>
|
75 |
+
```
|
76 |
|
77 |
+
To see all methods and options, refer to the `readme.md` file included with the plugin download or [view the readme online](https://github.com/justintadlock/breadcrumb-trail/blob/master/readme.md).
|
78 |
|
79 |
== Screenshots ==
|
80 |
|
84 |
|
85 |
== Changelog ==
|
86 |
|
87 |
+
Please see the `changelog.md` file included with the plugin file. Or, you can view the [online change log](https://github.com/justintadlock/breadcrumb-trail/blob/master/changelog.md).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|