';
78 |
79 |
80 |
81 | /*
82 | * Queried Term Image ID.
83 | *
84 | * Return the id of the image associated with the currently
85 | * queried term. In the event that no associated image exists,
86 | * the filter should return zero.
87 | *
88 | * In the event that the Taxonomy Images plugin is not installed
89 | * apply_filters() will return it's second parameter.
90 | */
91 | $img = apply_filters( 'taxonomy-images-queried-term-image-id', 'PLEASE INSTALL PLUGIN' );
92 |
93 | print '
taxonomy-images-queried-term-image-id
';
94 | print '
'; var_dump( $img ); print '
';
95 |
96 |
97 |
98 |
99 | /*
100 | * Queried Term Image Object.
101 | *
102 | * Return an object representing the image associated with the
103 | * currently queried term. In the event that no associated image
104 | * exists, the filter should return an empty object.
105 | *
106 | * In the event that the Taxonomy Images plugin is not installed
107 | * apply_filters() will return it's second parameter.
108 | */
109 | $img = apply_filters( 'taxonomy-images-queried-term-image-object', 'PLEASE INSTALL PLUGIN' );
110 |
111 | print '
taxonomy-images-queried-term-image-object
';
112 | print '
'; var_dump( $img ); print '
';
113 |
114 |
115 |
116 |
117 | /*
118 | * Queried Term Image URL.
119 | *
120 | * Return a url to the image associated with the current queried
121 | * term. In the event that no associated image exists, the filter
122 | * should return an empty string.
123 | *
124 | * In the event that the Taxonomy Images plugin is not installed
125 | * apply_filters() will return it's second parameter.
126 | */
127 |
128 |
129 | /* Default */
130 | $img = apply_filters( 'taxonomy-images-queried-term-image-url', 'PLEASE INSTALL PLUGIN' );
131 | print '
';
149 |
150 |
151 |
152 |
153 | /*
154 | * Queried Term Image Data.
155 | *
156 | * Return an array of data about the image associated with the current
157 | * queried term. In the event that no associated image exists, the filter
158 | * should return an empty string.
159 | *
160 | * In the event that the Taxonomy Images plugin is not installed
161 | * apply_filters() will return it's second parameter.
162 | */
163 |
164 |
165 | /* Default */
166 | $img = apply_filters( 'taxonomy-images-queried-term-image-data', 'PLEASE INSTALL PLUGIN' );
167 | print '
';
185 |
--------------------------------------------------------------------------------
/readme.txt:
--------------------------------------------------------------------------------
1 | ===Taxonomy Images===
2 |
3 | Contributors: mfields, jamiemchale
4 | Donate link: http://wordpress.mfields.org/donate/
5 | Tags: taxonomy, tag, category, image, upload, media
6 | Requires at least: 3.1
7 | Tested up to: 3.6
8 | Stable tag: trunk
9 |
10 | Associate images from your media library to categories, tags and custom taxonomies.
11 |
12 | ==Description==
13 |
14 | For usage instructions please view the [screencast](http://screenr.com/zMx).
15 |
16 | = Displaying Your Images in Your Theme =
17 |
18 | There are a few filters that you can use in your theme to display the image associations created by this plugin. Please read below for detailed information.
19 |
20 | = Display a single image representing the term archive =
21 |
22 | The following filter will display the image associated with the term asked for in the query string of the url. This filter only works in views that naturally use templates like category.php, tag.php taxonomy.php and all of their derivatives. Please read about [template hierarchy](http://codex.wordpress.org/Template_Hierarchy) for more information about these templates. The simplest use of this filter looks like:
23 |
24 | `print apply_filters( 'taxonomy-images-queried-term-image', '' );`
25 |
26 | This code will generate and print an image tag. It's output can be modifed by passig an optional third parameter to apply filters. This parameter is an array and the following keys may be set:
27 |
28 | * __after__ (string) - Text to append to the image's HTML.
29 |
30 | * __attr__ (array) - Key/value pairs representing the attributes of the img tag. Available options include: alt, class, src and title. This array will be passed as the fourth parameter to WordPress core function wp_get_attachment_image() without modification.
31 |
32 | * __before__ (string) - Text to prepend to the image's HTML.
33 |
34 | * __image_size__ (string) - May be any image size registered with WordPress. If no image size is specified, 'thumbnail' will be used as a default value. In the event that an unregistered size is specified, this filter will return an empty string.
35 |
36 | Here's an example of what a fully customized version of this filter might look like:
37 |
38 | `print apply_filters( 'taxonomy-images-queried-term-image', '', array(
39 | 'after' => ''
40 | 'attr' => array(
41 | 'alt' => 'Custom alternative text',
42 | 'class' => 'my-class-list bunnies turtles',
43 | 'src' => 'this-is-where-the-image-lives.png',
44 | 'title' => 'Custom Title',
45 | ),
46 | 'before' => '
',
47 | 'image_size' => 'medium',
48 | ) );
49 | `
50 |
51 | = Similar functionality =
52 |
53 | If you just need to get the database ID for the image, you may want to use:
54 |
55 | `$image_id = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );`
56 |
57 | If you need to get the full object of the image, you may want to use:
58 |
59 | `$image = apply_filters( 'taxonomy-images-queried-term-image-object', '' );`
60 |
61 | If you need to get the url to the image, you may want to use the following:
62 |
63 | `$image_url = apply_filters( 'taxonomy-images-queried-term-image-url', '' );`
64 |
65 | You can specify the size of the image in an option third parameter:
66 |
67 | `
68 | $image_url = apply_filters( 'taxonomy-images-queried-term-image-url', '', array(
69 | 'image_size' => 'medium'
70 | ) );
71 | `
72 |
73 | If you need data about the image, you may want to use:
74 |
75 | `$image_data = apply_filters( 'taxonomy-images-queried-term-image-data', '' );`
76 |
77 | You can specify the size of the image in an option third parameter:
78 |
79 | `
80 | $image_data = apply_filters( 'taxonomy-images-queried-term-image-data', '', array(
81 | 'image_size' => 'medium'
82 | ) );
83 | `
84 |
85 | = List term images associated with a post object =
86 |
87 | When a post is being displayed you may want to display all of the images associated with all of the terms that are associated with the post (a mouthful? Yes indeed!). The `taxonomy-images-list-the-terms` filter does this. Here's what it looks like in its simplest form:
88 |
89 | `print apply_filters( 'taxonomy-images-list-the-terms', '' );`
90 |
91 | This filter accepts an optional third parameter that you can use to customize its output. It is an array which recognizes the following keys:
92 |
93 | * __after__ (string) - Text to append to the output. Default value is a closing unordered list element.
94 |
95 | * __after_image__ (string) - Text to append to each image. Default value is a closing list-item element.
96 |
97 | * __before__ (string) - Text to prepend to the output. Default value is an open unordered list element with an class attribute of "taxonomy-images-the-terms".
98 |
99 | * __before_image__ (string) - Text to prepend to each image. Default value is an open list-item element.
100 |
101 | * __image_size__ (string) - Any registered image size. Values will vary from installation to installation. Image sizes defined in core include: "thumbnail", "medium" and "large". "Fullsize" may also be used to get the unmodified image that was uploaded. Defaults to "thumbnail".
102 |
103 | * __post_id__ (int) - The post to retrieve terms from. Defaults to the ID property of the global $post object.
104 |
105 | * __taxonomy__ (string) - Name of a registered taxonomy to return terms from. Defaults to "category".
106 |
107 | Here's an example of what a fully customized version of this filter might look like:
108 |
109 | `
110 | print apply_filters( 'taxonomy-images-list-the-terms', '', array(
111 | 'after' => '
',
112 | 'after_image' => '',
113 | 'before' => '
',
114 | 'before_image' => '',
115 | 'image_size' => 'detail',
116 | 'post_id' => 1234,
117 | 'taxonomy' => 'post_tag',
118 | ) );
119 | `
120 |
121 | = Working with all terms of a given taxonomy =
122 |
123 | You will want to use the 'taxonomy-images-get-terms' filter. This filter is basically a wrapper for WordPress core function [get_terms()](http://codex.wordpress.org/Function_Reference/get_terms). It will return an array of enhanced term objects: each term object will have a custom property named image_id which is an integer representing the database ID of the image associated with the term. This filter can be used to create custom lists of terms. Here's what it's default useage looks like:
124 |
125 | `$terms = apply_filters( 'taxonomy-images-get-terms', '' );`
126 |
127 | Here is what php's print_r() function may return:
128 |
129 | `
130 | Array
131 | (
132 | [0] => stdClass Object
133 | (
134 | [term_id] => 8
135 | [name] => Pirate
136 | [slug] => pirate
137 | [term_group] => 0
138 | [term_taxonomy_id] => 8
139 | [taxonomy] => category
140 | [description] => Pirates live in the ocean and ride around on boats.
141 | [parent] => 0
142 | [count] => 1
143 | [image_id] => 44
144 | )
145 | )
146 | `
147 |
148 | As you can see, all of the goodness of get_terms() is there with an added bonus: the image_id parameter!
149 |
150 | This filter recognizes an optional third parameter which is an array of arguments that can be used to modify its output:
151 |
152 | * __cache_images__ (bool) If this value is true all assocaite images will be queried for and cached for later use in various template tags. If it is set to false, this query will be suppressed. Do not set this value to false unless you have a really good reason for doing so :) Default value is true.
153 |
154 | * __having_images__ (bool) If this value is true then only terms that have associated images will be returned. Setting it to false will return all terms. Default value is true.
155 |
156 | * __taxonomy__ (string) Name of a registered taxonomy to return terms from. Multiple taxonomies may be specified by separating each name by a comma. Defaults to "category".
157 |
158 | * __term_args__ (array) Arguments to pass to [get_terms()](http://codex.wordpress.org/Function_Reference/get_terms) as the second parameter. Default value is an empty array.
159 |
160 | Here's and example of a simple custom loop that you can make to display all term images:
161 |
162 | `
163 | $terms = apply_filters( 'taxonomy-images-get-terms', '' );
164 | if ( ! empty( $terms ) ) {
165 | print '
';
170 | }
171 | `
172 |
173 | = Support =
174 |
175 | If you have questions about integrating this plugin into your site, please [add a new thread to the WordPress Support Forum](http://wordpress.org/tags/taxonomy-images?forum_id=10#postform). I try to answer these, but I may not always be able to. In the event that I cannot there may be someone else who can help.
176 |
177 | = Bugs, Suggestions =
178 |
179 | Development of this plugin is hosted in a public repository on [Github](https://github.com/mfields/Taxonomy-Images). If you find a bug in this plugin or have a suggestion to make it better, please [create a new issue](https://github.com/mfields/Taxonomy-Images/issues/new)
180 |
181 | = Hook it up yo! =
182 |
183 | If you have fallen in love with this plugin and would not be able to sleep without helping out in some way, please see the following list of ways that you can _hook it up!_:
184 |
185 | * __Rate it!__ - Use the star tool on the right-hand sidebar of the [homepage](http://wordpress.org/extend/plugins/taxonomy-images/).
186 |
187 | * __Let me know if it works__ - Use the _Compatibility_ widget on the [homepage](http://wordpress.org/extend/plugins/taxonomy-images/) to let everyone know that the current version works with your version of WordPress.
188 |
189 | * __Do you Twitter?__ Help promote by using this shortlink: [http://bit.ly/taxonomy-images](http://bit.ly/taxonomy-images)
190 |
191 | * __Are you a writer?__ Help promote by writing an article on your website about this plugin.
192 |
193 | * __Are you Super-Wicked-Awesome?__ If so, you can always [make a donation](http://wordpress.mfields.org/donate/).
194 |
195 | = Need More Taxonomy Plugins? =
196 | I've released a handfull of plugins dealing with taxonomies. Please see my [plugin page](http://wordpress.org/extend/plugins/profile/mfields) for more info.
197 |
198 | ==Installation==
199 |
200 | 1. Download
201 | 1. Unzip the package and upload to your /wp-content/plugins/ directory.
202 | 1. Log into WordPress and navigate to the "Plugins" panel.
203 | 1. Activate the plugin.
204 | 1. Click the "Taxonomy Images" link under the Settings section in the admin menu. There you can select the taxonomies that you would like to add image support for.
205 |
206 | == Upgrade Notice ==
207 |
208 | = 0.8 =
209 | Major and minor bug fixes tested with WordPres 3.6
210 |
211 | = 0.7 =
212 | Complete rewrite. Better everything. Many bug fixes.
213 |
214 | ==Changelog==
215 |
216 | = 0.8.0 =
217 | * Pass an empty array as default second parameter of `taxonomy_images_plugin_get_the_terms()` and `taxonomy_images_plugin_list_the_terms()`.
218 | * Use jQuery.on() instead of jQuery.live(). Props [jamiemchale](http://profiles.wordpress.org/jamiemchale).
219 | * Give the button on the custom admin screen a class of `button-primary`.
220 | * Store the return value of `get_posts()` in a variable called `$images`. Not sure why, but this should not harm anything.
221 | * Change license to GPLv2 or later for maximum flexibility and compatibility.
222 | * Add jamiemchale as a contributor.
223 | * Random whitespace fixes.
224 | * Update Documentation.
225 | * CSS coding standards.
226 | * Bump version number.
227 | * Update Readmes.
228 |
229 | = 0.7.3 =
230 | * Fixed the delete image button on edit-terms.php.
231 | * Better escaping.
232 | * Introduced pot file and languages directory.
233 |
234 | = 0.7.2 =
235 | * Return data for fulsize images in archive views. [See this thread](http://wordpress.org/support/topic/image-size-full).
236 |
237 | = 0.7.1 =
238 | * Remove unused link code which is throwing an error when no taxonomies support images.
239 |
240 | = 0.7 =
241 | * No longer breaks display of the [Better Plugin Compatibility Control](http://wordpress.org/extend/plugins/better-plugin-compatibility-control/) plugin.
242 | * Created a custom filter interface for plugin and theme integration.
243 | * Lots of inline documentation added.
244 | * Added custom notices if plugin is used in an unsupported way.
245 | * No notices generated by PHP or WordPress.
246 | * Deprecated function calls removed.
247 | * Security updates.
248 | * All strings are now internationalized.
249 | * Add image to term functionality mimics "Add Featured Image".
250 | * Taxonomy modal button now available in search + upload states.
251 | * Image interface has been added to single term edit screen.
252 | * Users can now choose which taxonomys have image support.
253 | * All functions are now private.
254 | * Shortcode deprecated.
255 | * All global variables and constants have been removed or deprecated.
256 |
257 | = 0.6 =
258 | * Never released.
259 | * Completely recoded.
260 |
261 | = 0.5 =
262 | * __UPDATE:__ Direct link to upload new files from edit-tag.php has been introduced.
263 | * __UPDATE:__ Ability to create an image/term association immediately after upload has been introduced.
264 | * __UPDATE:__ Users can now delete image/term associations.
265 | * __UPDATE:__ Created standalone javascript files - removed inline scripts.
266 | * __UPDATE:__ Obsesive compulsive syntax modifications.
267 | * __UPDATE:__ Localization for strings - still need to "fine-tooth-comb" this.
268 | * __UPDATE:__ Removed all debug functions.
269 |
270 | = 0.4.4 =
271 | * __BUGFIX:__ get_image_html() Now populates the image's alt attribute with appropriate data. Props to [jaygoldman](http://wordpress.org/support/profile/jaygoldman).
272 |
273 | = 0.4.3 =
274 | * __UPDATE:__ Support for WordPress 3.0 has been added. Support for all beta versions of 3.0 has been dropped.
275 | * __COMPAT:__ Removed use of deprecated function is_taxonomy() - props to [anointed](http://profiles.wordpress.org/users/anointed).
276 | * __COMPAT:__ Included a definition for taxonomy_exists() function for backwards compatibility with 2.9 branch. This function is new in WordPress version 3.0.
277 |
278 | = 0.4.2 =
279 | * __UPDATE:__ Changed button name from "Category" to "Taxonomy".
280 | * __UPDATE:__ Support for 2.9 branch has been added again.
281 |
282 | = 0.4.1 =
283 | * __UPDATE:__ Added support for dynamic taxonomy hooks for _tag_row()
284 | * __BROKEN:__ Support for 2.9 branch has been temporarily removed.
285 |
286 | = 0.4 =
287 | * __BUGFIX:__ get_thumb() now returns the fullsize url if there is no appropriate intermediate image.
288 | * __UPDATE:__ Added "taxonomy_images_shortcode".
289 |
290 | = 0.3 =
291 | * __COMPAT:__ Changed the firing order of every hook untilizing the 'category_rows' method to 15. This allows this plugin to be compatible with [Reveal IDs for WP Admin](http://wordpress.org/extend/plugins/reveal-ids-for-wp-admin-25/). Thanks to [Peter Kahoun](http://profiles.wordpress.org/kahi/)
292 | * __COMPAT:__ Added Version check for PHP5.
293 | * __UPDATE:__ `$settings` and `$locale` are now public properties.
294 | * __UPDATE:__ Object name changed to: $taxonomy_images_plugin.
295 | * __UPDATE:__ Added argument $term_tax_id to both print_image_html() and get_image_html().
296 | * __BUGFIX:__ Deleted the register_deactivation_hook() function -> sorry to all 8 who downloaded this plugin so far :)
297 |
298 | = 0.2 =
299 | * Original Release - Works With: wp 2.9.1.
300 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | Taxonomy Images
2 | ===============
3 |
4 | A WordPress plugin that enables you to associate images from your media library to categories, tags and custom taxonomies. For usage instructions please view the [screencast](http://screenr.com/zMx).
5 |
6 |
7 | Displaying Your Images in Your Theme
8 | ------------------------------------
9 |
10 | There are a few filters that you can use in your theme to display the image associations created by this plugin. Please read below for detailed information.
11 |
12 |
13 | Display a single image representing the term archive
14 | ----------------------------------------------------
15 |
16 | The following filter will display the image associated with the term asked for in the query string of the url. This filter only works in views that naturally use templates like category.php, tag.php taxonomy.php and all of their derivatives. Please read about [template hierarchy](http://codex.wordpress.org/Template_Hierarchy) for more information about these templates. The simplest use of this filter looks like:
17 |
18 | print apply_filters( 'taxonomy-images-queried-term-image', '' );
19 |
20 | This code will generate and print an image tag. It's output can be modifed by passig an optional third parameter to apply filters. This parameter is an array and the following keys may be set:
21 |
22 | * __after__ (string) - Text to append to the image's HTML.
23 |
24 | * __attr__ (array) - Key/value pairs representing the attributes of the img tag. Available options include: alt, class, src and title. This array will be passed as the fourth parameter to WordPress core function wp_get_attachment_image() without modification.
25 |
26 | * __before__ (string) - Text to prepend to the image's HTML.
27 |
28 | * __image_size__ (string) - May be any image size registered with WordPress. If no image size is specified, 'thumbnail' will be used as a default value. In the event that an unregistered size is specified, this filter will return an empty string.
29 |
30 | Here's an example of what a fully customized version of this filter might look like:
31 |
32 | print apply_filters( 'taxonomy-images-queried-term-image', '', array(
33 | 'after' => '
',
41 | 'image_size' => 'medium',
42 | ) );
43 |
44 |
45 | Similar functionality
46 | ---------------------
47 |
48 | If you just need to get the database ID for the image, you may want to use:
49 |
50 | $image_id = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
51 |
52 | If you need to get the full object of the image, you may want to use:
53 |
54 | $image = apply_filters( 'taxonomy-images-queried-term-image-object', '' );
55 |
56 | If you need to get the url to the image, you may want to use the following:
57 |
58 | $image_url = apply_filters( 'taxonomy-images-queried-term-image-url', '' );
59 |
60 | You can specify the size of the image in an option third parameter:
61 |
62 | $image_url = apply_filters( 'taxonomy-images-queried-term-image-url', '', array(
63 | 'image_size' => 'medium'
64 | ) );
65 |
66 |
67 | If you need data about the image, you may want to use:
68 |
69 | $image_data = apply_filters( 'taxonomy-images-queried-term-image-data', '' );
70 |
71 | You can specify the size of the image in an option third parameter:
72 |
73 |
74 | $image_data = apply_filters( 'taxonomy-images-queried-term-image-data', '', array(
75 | 'image_size' => 'medium'
76 | ) );
77 |
78 | List term images associated with a post object
79 | ----------------------------------------------
80 |
81 | When a post is being displayed you may want to display all of the images associated with all of the terms that are associated with the post (a mouthful? Yes indeed!). The `taxonomy-images-list-the-terms` filter does this. Here's what it looks like in its simplest form:
82 |
83 | print apply_filters( 'taxonomy-images-list-the-terms', '' );
84 |
85 | This filter accepts an optional third parameter that you can use to customize its output. It is an array which recognizes the following keys:
86 |
87 | * __after__ (string) - Text to append to the output. Default value is a closing unordered list element.
88 |
89 | * __after_image__ (string) - Text to append to each image. Default value is a closing list-item element.
90 |
91 | * __before__ (string) - Text to prepend to the output. Default value is an open unordered list element with an class attribute of "taxonomy-images-the-terms".
92 |
93 | * __before_image__ (string) - Text to prepend to each image. Default value is an open list-item element.
94 |
95 | * __image_size__ (string) - Any registered image size. Values will vary from installation to installation. Image sizes defined in core include: "thumbnail", "medium" and "large". "Fullsize" may also be used to get the unmodified image that was uploaded. Defaults to "thumbnail".
96 |
97 | * __post_id__ (int) - The post to retrieve terms from. Defaults to the ID property of the global $post object.
98 |
99 | * __taxonomy__ (string) - Name of a registered taxonomy to return terms from. Defaults to "category".
100 |
101 | Here's an example of what a fully customized version of this filter might look like:
102 |
103 | print apply_filters( 'taxonomy-images-list-the-terms', '', array(
104 | 'after' => '
',
105 | 'after_image' => '',
106 | 'before' => '
',
107 | 'before_image' => '',
108 | 'image_size' => 'detail',
109 | 'post_id' => 1234,
110 | 'taxonomy' => 'post_tag',
111 | ) );
112 |
113 | Working with all terms of a given taxonomy
114 | ------------------------------------------
115 |
116 | You will want to use the 'taxonomy-images-get-terms' filter. This filter is basically a wrapper for WordPress core function [get_terms()](http://codex.wordpress.org/Function_Reference/get_terms). It will return an array of enhanced term objects: each term object will have a custom property named image_id which is an integer representing the database ID of the image associated with the term. This filter can be used to create custom lists of terms. Here's what it's default useage looks like:
117 |
118 | $terms = apply_filters( 'taxonomy-images-get-terms', '' );
119 |
120 | Here is what php's print_r() function may return:
121 |
122 | Array
123 | (
124 | [0] => stdClass Object
125 | (
126 | [term_id] => 8
127 | [name] => Pirate
128 | [slug] => pirate
129 | [term_group] => 0
130 | [term_taxonomy_id] => 8
131 | [taxonomy] => category
132 | [description] => Pirates live in the ocean and ride around on boats.
133 | [parent] => 0
134 | [count] => 1
135 | [image_id] => 44
136 | )
137 | )
138 |
139 | As you can see, all of the goodness of get_terms() is there with an added bonus: the image_id parameter!
140 |
141 | This filter recognizes an optional third parameter which is an array of arguments that can be used to modify its output:
142 |
143 | * __cache_images__ (bool) If this value is true all assocaite images will be queried for and cached for later use in various template tags. If it is set to false, this query will be suppressed. Do not set this value to false unless you have a really good reason for doing so :) Default value is true.
144 |
145 | * __having_images__ (bool) If this value is true then only terms that have associated images will be returned. Setting it to false will return all terms. Default value is true.
146 |
147 | * __taxonomy__ (string) Name of a registered taxonomy to return terms from. Multiple taxonomies may be specified by separating each name by a comma. Defaults to "category".
148 |
149 | * __term_args__ (array) Arguments to pass to [get_terms()](http://codex.wordpress.org/Function_Reference/get_terms) as the second parameter. Default value is an empty array.
150 |
151 | Here's and example of a simple custom loop that you can make to display all term images:
152 |
153 | $terms = apply_filters( 'taxonomy-images-get-terms', '' );
154 | if ( ! empty( $terms ) ) {
155 | print '
';
160 | }
161 |
162 |
163 | Support
164 | -------
165 |
166 | If you have questions about integrating this plugin into your site, please [add a new thread to the WordPress Support Forum](http://wordpress.org/tags/taxonomy-images?forum_id=10#postform). I try to answer these, but I may not always be able to. In the event that I cannot there may be someone else who can help.
167 |
168 |
169 | Bugs, Suggestions
170 | -----------------
171 |
172 | Development of this plugin is hosted in a public repository on [Github](https://github.com/mfields/Taxonomy-Images). If you find a bug in this plugin or have a suggestion to make it better, please [create a new issue](https://github.com/mfields/Taxonomy-Images/issues/new)
173 |
174 |
175 | Hook it up yo!
176 | --------------
177 |
178 | If you have fallen in love with this plugin and would not be able to sleep without helping out in some way, please see the following list of ways that you can _hook it up!_:
179 |
180 | * __Rate it!__ - Use the star tool on the right-hand sidebar of the [homepage](http://wordpress.org/extend/plugins/taxonomy-images/).
181 |
182 | * __Let me know if it works__ - Use the _Compatibility_ widget on the [homepage](http://wordpress.org/extend/plugins/taxonomy-images/) to let everyone know that the current version works with your version of WordPress.
183 |
184 | * __Do you Twitter?__ Help promote by using this shortlink: [http://bit.ly/taxonomy-images](http://bit.ly/taxonomy-images)
185 |
186 | * __Are you a writer?__ Help promote by writing an article on your website about this plugin.
187 |
188 | * __Are you Super-Wicked-Awesome?__ If so, you can always [make a donation](http://wordpress.mfields.org/donate/).
189 |
190 |
191 | Need More Taxonomy Plugins?
192 | ---------------------------
193 |
194 | I've released a handfull of plugins dealing with taxonomies. Please see my [plugin page](http://wordpress.org/extend/plugins/profile/mfields) for more info.
195 |
196 |
197 | Installation
198 | ------------
199 |
200 | 1. Download
201 | 1. Unzip the package and upload to your /wp-content/plugins/ directory.
202 | 1. Log into WordPress and navigate to the "Plugins" panel.
203 | 1. Activate the plugin.
204 | 1. Click the "Taxonomy Images" link under the Settings section in the admin menu. There you can select the taxonomies that you would like to add image support for.
205 |
206 |
207 | Changelog
208 | ---------
209 |
210 | __0.8.0__
211 |
212 | * Pass an empty array as default second parameter of `taxonomy_images_plugin_get_the_terms()` and `taxonomy_images_plugin_list_the_terms()`.
213 | * Use jQuery.on() instead of jQuery.live(). Props [jamiemchale](http://profiles.wordpress.org/jamiemchale).
214 | * Give the button on the custom admin screen a class of `button-primary`.
215 | * Store the return value of `get_posts()` in a variable called `$images`. Not sure why, but this should not harm anything.
216 | * Change license to GPLv2 or later for maximum flexibility and compatibility.
217 | * Add jamiemchale as a contributor.
218 | * Random whitespace fixes.
219 | * Update Documentation.
220 | * CSS coding standards.
221 | * Bump version number.
222 | * Update Readmes.
223 |
224 | __0.7.3__
225 |
226 | * Fixed the delete image button on edit-terms.php.
227 | * Better escaping.
228 | * Introduced pot file and languages directory.
229 |
230 | __0.7.2__
231 |
232 | * Return data for fulsize images in archive views. [See this thread](http://wordpress.org/support/topic/image-size-full).
233 |
234 | __0.7.1__
235 |
236 | * Remove unused link code which is throwing an error when no taxonomies support images.
237 |
238 | __0.7__
239 |
240 | * No longer breaks display of the [Better Plugin Compatibility Control](http://wordpress.org/extend/plugins/better-plugin-compatibility-control/) plugin.
241 | * Created a custom filter interface for plugin and theme integration.
242 | * Lots of inline documentation added.
243 | * Added custom notices if plugin is used in an unsupported way.
244 | * No notices generated by PHP or WordPress.
245 | * Deprecated function calls removed.
246 | * Security updates.
247 | * All strings are now internationalized.
248 | * Add image to term functionality mimics "Add Featured Image".
249 | * Taxonomy modal button now available in search + upload states.
250 | * Image interface has been added to single term edit screen.
251 | * Users can now choose which taxonomys have image support.
252 | * All functions are now private.
253 | * Shortcode deprecated.
254 | * All global variables and constants have been removed or deprecated.
255 |
256 | __0.6__
257 |
258 | * Never released.
259 | * Completely recoded.
260 |
261 | __0.5__
262 |
263 | * __UPDATE:__ Direct link to upload new files from edit-tag.php has been introduced.
264 | * __UPDATE:__ Ability to create an image/term association immediately after upload has been introduced.
265 | * __UPDATE:__ Users can now delete image/term associations.
266 | * __UPDATE:__ Created standalone javascript files - removed inline scripts.
267 | * __UPDATE:__ Obsesive compulsive syntax modifications.
268 | * __UPDATE:__ Localization for strings - still need to "fine-tooth-comb" this.
269 | * __UPDATE:__ Removed all debug functions.
270 |
271 | __0.4.4__
272 |
273 | * __BUGFIX:__ get_image_html() Now populates the image's alt attribute with appropriate data. Props to [jaygoldman](http://wordpress.org/support/profile/jaygoldman).
274 |
275 | __0.4.3__
276 |
277 | * __UPDATE:__ Support for WordPress 3.0 has been added. Support for all beta versions of 3.0 has been dropped.
278 | * __COMPAT:__ Removed use of deprecated function is_taxonomy() - props to [anointed](http://profiles.wordpress.org/users/anointed).
279 | * __COMPAT:__ Included a definition for taxonomy_exists() function for backwards compatibility with 2.9 branch. This function is new in WordPress version 3.0.
280 |
281 | __0.4.2__
282 |
283 | * __UPDATE:__ Changed button name from "Category" to "Taxonomy".
284 | * __UPDATE:__ Support for 2.9 branch has been added again.
285 |
286 | __0.4.1__
287 |
288 | * __UPDATE:__ Added support for dynamic taxonomy hooks for _tag_row()
289 | * __BROKEN:__ Support for 2.9 branch has been temporarily removed.
290 |
291 | __0.4__
292 |
293 | * __BUGFIX:__ get_thumb() now returns the fullsize url if there is no appropriate intermediate image.
294 | * __UPDATE:__ Added "taxonomy_images_shortcode".
295 |
296 | __0.3__
297 |
298 | * __COMPAT:__ Changed the firing order of every hook untilizing the 'category_rows' method to 15. This allows this plugin to be compatible with [Reveal IDs for WP Admin](http://wordpress.org/extend/plugins/reveal-ids-for-wp-admin-25/). Thanks to [Peter Kahoun](http://profiles.wordpress.org/kahi/)
299 | * __COMPAT:__ Added Version check for PHP5.
300 | * __UPDATE:__ `$settings` and `$locale` are now public properties.
301 | * __UPDATE:__ Object name changed to: $taxonomy_images_plugin.
302 | * __UPDATE:__ Added argument $term_tax_id to both print_image_html() and get_image_html().
303 | * __BUGFIX:__ Deleted the register_deactivation_hook() function -> sorry to all 8 who downloaded this plugin so far :)
304 |
305 | __0.2__
306 |
307 | * Original Release - Works With: wp 2.9.1.
308 |
--------------------------------------------------------------------------------
/public-filters.php:
--------------------------------------------------------------------------------
1 |
15 | * @copyright Copyright (c) 2011, Michael Fields
16 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
17 | * @since 0.7
18 | */
19 |
20 |
21 | add_filter( 'taxonomy-images-get-terms', 'taxonomy_images_plugin_get_terms', 10, 2 );
22 | add_filter( 'taxonomy-images-get-the-terms', 'taxonomy_images_plugin_get_the_terms', 10, 2 );
23 | add_filter( 'taxonomy-images-list-the-terms', 'taxonomy_images_plugin_list_the_terms', 10, 2 );
24 |
25 | add_filter( 'taxonomy-images-queried-term-image', 'taxonomy_images_plugin_get_queried_term_image', 10, 2 );
26 | add_filter( 'taxonomy-images-queried-term-image-data', 'taxonomy_images_plugin_get_queried_term_image_data', 10, 2 );
27 | add_filter( 'taxonomy-images-queried-term-image-id', 'taxonomy_images_plugin_get_queried_term_image_id' );
28 | add_filter( 'taxonomy-images-queried-term-image-object', 'taxonomy_images_plugin_get_queried_term_image_object' );
29 | add_filter( 'taxonomy-images-queried-term-image-url', 'taxonomy_images_plugin_get_queried_term_image_url', 10, 2 );
30 |
31 |
32 | /**
33 | * Get Terms.
34 | *
35 | * This function adds a custom property (image_id) to each
36 | * object returned by WordPress core function get_terms().
37 | * This property will be set for all term objects. In cases
38 | * where a term has an associated image, "image_id" will
39 | * contain the value of the image object's ID property. If
40 | * no image has been associated, this property will contain
41 | * integer with the value of zero.
42 | *
43 | * @see http://codex.wordpress.org/Function_Reference/get_terms
44 | *
45 | * Recognized Arguments:
46 | *
47 | * cache_images (bool) If true, all images will be added to
48 | * WordPress object cache. If false, caching will not occur.
49 | * Defaults to true. Optional.
50 | *
51 | * having_images (bool) If true, the returned array will contain
52 | * only terms that have associated images. If false, all terms
53 | * of the taxonomy will be returned. Defaults to true. Optional.
54 | *
55 | * taxonomy (string) Name of a registered taxonomy to
56 | * return terms from. Defaults to "category". Optional.
57 | *
58 | * term_args (array) Arguments to pass as the second
59 | * parameter of get_terms(). Defaults to an empty array.
60 | * Optional.
61 | *
62 | * @param mixed Default value for apply_filters() to return. Unused.
63 | * @param array Named arguments. Please see above for explantion.
64 | * @return array List of term objects.
65 | *
66 | * @access private Use the 'taxonomy-images-get-terms' filter.
67 | * @since 0.7
68 | */
69 | function taxonomy_images_plugin_get_terms( $default, $args = array() ) {
70 | $filter = 'taxonomy-images-get-terms';
71 | if ( $filter !== current_filter() ) {
72 | taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
73 | }
74 |
75 | $args = wp_parse_args( $args, array(
76 | 'cache_images' => true,
77 | 'having_images' => true,
78 | 'taxonomy' => 'category',
79 | 'term_args' => array(),
80 | ) );
81 |
82 | $args['taxonomy'] = explode( ',', $args['taxonomy'] );
83 | $args['taxonomy'] = array_map( 'trim', $args['taxonomy'] );
84 |
85 | foreach ( $args['taxonomy'] as $taxonomy ) {
86 | if ( ! taxonomy_image_plugin_check_taxonomy( $taxonomy, $filter ) ) {
87 | return array();
88 | }
89 | }
90 |
91 | $assoc = taxonomy_image_plugin_get_associations();
92 | if ( empty( $assoc ) ) {
93 | return array();
94 | }
95 |
96 | $terms = get_terms( $args['taxonomy'], $args['term_args'] );
97 | if ( is_wp_error( $terms ) ) {
98 | return array();
99 | }
100 |
101 | $image_ids = array();
102 | $terms_with_images = array();
103 | foreach ( (array) $terms as $key => $term ) {
104 | $terms[$key]->image_id = 0;
105 | if ( array_key_exists( $term->term_taxonomy_id, $assoc ) ) {
106 | $terms[$key]->image_id = $assoc[$term->term_taxonomy_id];
107 | $image_ids[] = $assoc[$term->term_taxonomy_id];
108 | if ( ! empty( $args['having_images'] ) ) {
109 | $terms_with_images[] = $terms[$key];
110 | }
111 | }
112 | }
113 | $image_ids = array_unique( $image_ids );
114 |
115 | if ( ! empty( $args['cache_images'] ) ) {
116 | $images = array();
117 | if ( ! empty( $image_ids ) ) {
118 | $images = get_children( array( 'include' => implode( ',', $image_ids ) ) );
119 | }
120 | }
121 |
122 | if ( ! empty( $terms_with_images ) ) {
123 | return $terms_with_images;
124 | }
125 | return $terms;
126 | }
127 |
128 |
129 | /**
130 | * Get the Terms.
131 | *
132 | * This function adds a custom property (image_id) to each
133 | * object returned by WordPress core function get_the_terms().
134 | * This property will be set for all term objects. In cases
135 | * where a term has an associated image, "image_id" will
136 | * contain the value of the image object's ID property. If
137 | * no image has been associated, this property will contain
138 | * integer with the value of zero.
139 | *
140 | * @see http://codex.wordpress.org/Function_Reference/get_the_terms
141 | *
142 | * Recognized Arguments:
143 | *
144 | * having_images (bool) If true, the returned array will contain
145 | * only terms that have associated images. If false, all terms
146 | * of the taxonomy will be returned. Defaults to true. Optional.
147 | *
148 | * post_id (int) The post to retrieve terms from. Defaults
149 | * to the ID property of the global $post object. Optional.
150 | *
151 | * taxonomy (string) Name of a registered taxonomy to
152 | * return terms from. Defaults to "category". Optional.
153 | *
154 | * @param mixed Default value for apply_filters() to return. Unused.
155 | * @param array Named arguments. Please see above for explantion.
156 | * @return array List of term objects. Empty array if none were found.
157 | *
158 | * @access private Use the 'taxonomy-images-get-the-terms' filter.
159 | * @since 0.7
160 | */
161 | function taxonomy_images_plugin_get_the_terms( $default, $args = array() ) {
162 | $filter = 'taxonomy-images-get-the-terms';
163 | if ( $filter !== current_filter() ) {
164 | taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
165 | }
166 |
167 | $args = wp_parse_args( $args, array(
168 | 'having_images' => true,
169 | 'post_id' => 0,
170 | 'taxonomy' => 'category',
171 | ) );
172 |
173 | if ( ! taxonomy_image_plugin_check_taxonomy( $args['taxonomy'], $filter ) ) {
174 | return array();
175 | }
176 |
177 | $assoc = taxonomy_image_plugin_get_associations();
178 |
179 | if ( empty( $args['post_id'] ) ) {
180 | $args['post_id'] = get_the_ID();
181 | }
182 |
183 | $terms = get_the_terms( $args['post_id'], $args['taxonomy'] );
184 |
185 | if ( is_wp_error( $terms ) ) {
186 | return array();
187 | }
188 |
189 | if ( empty( $terms ) ) {
190 | return array();
191 | }
192 |
193 | $terms_with_images = array();
194 | foreach ( (array) $terms as $key => $term ) {
195 | $terms[$key]->image_id = 0;
196 | if ( array_key_exists( $term->term_taxonomy_id, $assoc ) ) {
197 | $terms[$key]->image_id = $assoc[$term->term_taxonomy_id];
198 | if ( ! empty( $args['having_images'] ) ) {
199 | $terms_with_images[] = $terms[$key];
200 | }
201 | }
202 | }
203 | if ( ! empty( $terms_with_images ) ) {
204 | return $terms_with_images;
205 | }
206 | return $terms;
207 | }
208 |
209 |
210 | /**
211 | * List the Terms.
212 | *
213 | * Lists all terms associated with a given post that
214 | * have associated images. Terms without images will
215 | * not be included.
216 | *
217 | * Recognized Arguments:
218 | *
219 | * after (string) Text to append to the output.
220 | * Defaults to: ''. Optional.
221 | *
222 | * after_image (string) Text to append to each image in the
223 | * list. Defaults to: ''. Optional.
224 | *
225 | * before (string) Text to preppend to the output.
226 | * Defaults to: '
'.
227 | * Optional.
228 | *
229 | * before_image (string) Text to prepend to each image in the
230 | * list. Defaults to: '
'. Optional.
231 | *
232 | * image_size (string) Any registered image size. Values will
233 | * vary from installation to installation. Image sizes defined
234 | * in core include: "thumbnail", "medium" and "large". "fullsize"
235 | * may also be used to get the unmodified image that was uploaded.
236 | * Optional. Defaults to "thumbnail".
237 | *
238 | * post_id (int) The post to retrieve terms from. Defaults
239 | * to the ID property of the global $post object. Optional.
240 | *
241 | * taxonomy (string) Name of a registered taxonomy to
242 | * return terms from. Defaults to "category". Optional.
243 | *
244 | * @param mixed Default value for apply_filters() to return. Unused.
245 | * @param array Named arguments. Please see above for explantion.
246 | * @return string HTML markup.
247 | *
248 | * @access private Use the 'taxonomy-images-list-the-terms' filter.
249 | * @since 0.7
250 | */
251 | function taxonomy_images_plugin_list_the_terms( $default, $args = array() ) {
252 | $filter = 'taxonomy-images-list-the-terms';
253 | if ( $filter !== current_filter() ) {
254 | taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
255 | }
256 |
257 | $args = wp_parse_args( $args, array(
258 | 'after' => '
',
259 | 'after_image' => '',
260 | 'before' => '
',
261 | 'before_image' => '
',
262 | 'image_size' => 'thumbnail',
263 | 'post_id' => 0,
264 | 'taxonomy' => 'category',
265 | ) );
266 |
267 | $args['having_images'] = true;
268 |
269 | if ( ! taxonomy_image_plugin_check_taxonomy( $args['taxonomy'], $filter ) ) {
270 | return '';
271 | }
272 |
273 | $terms = apply_filters( 'taxonomy-images-get-the-terms', '', $args );
274 |
275 | if ( empty( $terms ) ) {
276 | return '';
277 | }
278 |
279 | $output = '';
280 | foreach( $terms as $term ) {
281 | if ( ! isset( $term->image_id ) ) {
282 | continue;
283 | }
284 | $image = wp_get_attachment_image( $term->image_id, $args['image_size'] );
285 | if ( ! empty( $image ) ) {
286 | $output .= $args['before_image'] . '' . $image .'' . $args['after_image'];
287 | }
288 | }
289 |
290 | if ( ! empty( $output ) ) {
291 | return $args['before'] . $output . $args['after'];
292 | }
293 | return '';
294 | }
295 |
296 |
297 | /**
298 | * Queried Term Image.
299 | *
300 | * Prints html markup for the image associated with
301 | * the current queried term.
302 | *
303 | * Recognized Arguments:
304 | *
305 | * after (string) - Text to append to the image's HTML.
306 | *
307 | * before (string) - Text to prepend to the image's HTML.
308 | *
309 | * image_size (string) - May be any image size registered with
310 | * WordPress. If no image size is specified, 'thumbnail' will be
311 | * used as a default value. In the event that an unregistered size
312 | * is specified, this function will return an empty string.
313 | *
314 | * Designed to be used in archive templates including
315 | * (but not limited to) archive.php, category.php, tag.php,
316 | * taxonomy.php as well as derivatives of these templates.
317 | *
318 | * @param mixed Default value for apply_filters() to return. Unused.
319 | * @param array Named array of arguments.
320 | * @return string HTML markup for the associated image.
321 | *
322 | * @access private Use the 'taxonomy-images-queried-term-image' filter.
323 | * @since 0.7
324 | */
325 | function taxonomy_images_plugin_get_queried_term_image( $default, $args = array() ) {
326 | $filter = 'taxonomy-images-queried-term-image';
327 | if ( $filter !== current_filter() ) {
328 | taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
329 | }
330 |
331 | $args = wp_parse_args( $args, array(
332 | 'after' => '',
333 | 'attr' => array(),
334 | 'before' => '',
335 | 'image_size' => 'thumbnail',
336 | ) );
337 |
338 | $ID = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
339 |
340 | if ( empty( $ID ) ) {
341 | return '';
342 | }
343 |
344 | $html = wp_get_attachment_image( $ID, $args['image_size'], false, $args['attr'] );
345 |
346 | if ( empty( $html ) ) {
347 | return '';
348 | }
349 |
350 | return $args['before'] . $html . $args['after'];
351 | }
352 |
353 |
354 | /**
355 | * Queried Term Image ID.
356 | *
357 | * Designed to be used in archive templates including
358 | * (but not limited to) archive.php, category.php, tag.php,
359 | * taxonomy.php as well as derivatives of these templates.
360 | *
361 | * Returns an integer representing the image attachment's ID.
362 | * In the event that an image has been associated zero will
363 | * be returned.
364 | *
365 | * This function should never be called directly in any file
366 | * however it may be access in any template file via the
367 | * 'taxonomy-images-queried-term-image-id' filter.
368 | *
369 | * @param mixed Default value for apply_filters() to return. Unused.
370 | * @return int Image attachment's ID.
371 | *
372 | * @access private Use the 'taxonomy-images-queried-term-image-id' filter.
373 | * @since 0.7
374 | */
375 | function taxonomy_images_plugin_get_queried_term_image_id( $default ) {
376 | $filter = 'taxonomy-images-queried-term-image-id';
377 | if ( $filter !== current_filter() ) {
378 | taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
379 | }
380 |
381 | $obj = get_queried_object();
382 |
383 | /* Return early is we are not in a term archive. */
384 | if ( ! isset( $obj->term_taxonomy_id ) ) {
385 | trigger_error( sprintf( esc_html__( '%1$s is not a property of the current queried object. This usually happens when the %2$s filter is used in an unsupported template file. This filter has been designed to work in taxonomy archives which are traditionally served by one of the following template files: category.php, tag.php or taxonomy.php. Learn more about %3$s.', 'taxonomy-images' ),
386 | '' . esc_html__( 'term_taxonomy_id', 'taxonomy-images' ) . '',
387 | '' . esc_html( $filter ) . '',
388 | '' . esc_html( 'template hierarchy', 'taxonomy-images' ) . ''
389 | ) );
390 | return 0;
391 | }
392 |
393 | if ( ! taxonomy_image_plugin_check_taxonomy( $obj->taxonomy, $filter ) ) {
394 | return 0;
395 | }
396 |
397 | $associations = taxonomy_image_plugin_get_associations();
398 | $tt_id = absint( $obj->term_taxonomy_id );
399 |
400 | $ID = 0;
401 | if ( array_key_exists( $tt_id, $associations ) ) {
402 | $ID = absint( $associations[$tt_id] );
403 | }
404 |
405 | return $ID;
406 | }
407 |
408 |
409 | /**
410 | * Queried Term Image Object.
411 | *
412 | * Returns all data stored in the WordPress posts table for
413 | * the image associated with the term in object form. In the
414 | * event that no image is found an empty object will be returned.
415 | *
416 | * Designed to be used in archive templates including
417 | * (but not limited to) archive.php, category.php, tag.php,
418 | * taxonomy.php as well as derivatives of these templates.
419 | *
420 | * This function should never be called directly in any file
421 | * however it may be access in any template file via the
422 | * 'taxonomy-images-queried-term-image' filter.
423 | *
424 | * @param mixed Default value for apply_filters() to return. Unused.
425 | * @return stdClass WordPress Post object.
426 | *
427 | * @access private Use the 'taxonomy-images-queried-term-image-object' filter.
428 | * @since 0.7
429 | */
430 | function taxonomy_images_plugin_get_queried_term_image_object( $default ) {
431 | $filter = 'taxonomy-images-queried-term-image-object';
432 | if ( $filter !== current_filter() ) {
433 | taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
434 | }
435 |
436 | $ID = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
437 |
438 | $image = new stdClass;
439 | if ( ! empty( $ID ) ) {
440 | $image = get_post( $ID );
441 | }
442 | return $image;
443 | }
444 |
445 | /**
446 | * Queried Term Image URL.
447 | *
448 | * Returns a url to the image associated with the current queried
449 | * term. In the event that no image is found an empty string will
450 | * be returned.
451 | *
452 | * Designed to be used in archive templates including
453 | * (but not limited to) archive.php, category.php, tag.php,
454 | * taxonomy.php as well as derivatives of these templates.
455 | *
456 | * Recognized Arguments
457 | *
458 | * image_size (string) - May be any image size registered with
459 | * WordPress. If no image size is specified, 'thumbnail' will be
460 | * used as a default value. In the event that an unregistered size
461 | * is specified, this function will return an empty string.
462 | *
463 | * @param mixed Default value for apply_filters() to return. Unused.
464 | * @param array Named Arguments.
465 | * @return string Image URL.
466 | *
467 | * @access private Use the 'taxonomy-images-queried-term-image-url' filter.
468 | * @since 0.7
469 | */
470 | function taxonomy_images_plugin_get_queried_term_image_url( $default, $args = array() ) {
471 | $filter = 'taxonomy-images-queried-term-image-url';
472 | if ( $filter !== current_filter() ) {
473 | taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
474 | }
475 |
476 | $args = wp_parse_args( $args, array(
477 | 'image_size' => 'thumbnail',
478 | ) );
479 |
480 | $data = apply_filters( 'taxonomy-images-queried-term-image-data', array(), $args );
481 |
482 | $url = '';
483 | if ( isset( $data['url'] ) ) {
484 | $url = $data['url'];
485 | }
486 | return $url;
487 | }
488 |
489 |
490 | /**
491 | * Queried Term Image Data.
492 | *
493 | * Returns a url to the image associated with the current queried
494 | * term. In the event that no image is found an empty string will
495 | * be returned.
496 | *
497 | * Designed to be used in archive templates including
498 | * (but not limited to) archive.php, category.php, tag.php,
499 | * taxonomy.php as well as derivatives of these templates.
500 | *
501 | * Recognized Arguments
502 | *
503 | * image_size (string) - May be any image size registered with
504 | * WordPress. If no image size is specified, 'thumbnail' will be
505 | * used as a default value. In the event that an unregistered size
506 | * is specified, this function will return an empty array.
507 | *
508 | * @param mixed Default value for apply_filters() to return. Unused.
509 | * @param array Named Arguments.
510 | * @return array Image data: url, width and height.
511 | *
512 | * @access private Use the 'taxonomy-images-queried-term-image-data' filter.
513 | * @since 0.7
514 | * @alter 0.7.2
515 | */
516 | function taxonomy_images_plugin_get_queried_term_image_data( $default, $args = array() ) {
517 | $filter = 'taxonomy-images-queried-term-image-data';
518 | if ( $filter !== current_filter() ) {
519 | taxonomy_image_plugin_please_use_filter( __FUNCTION__, $filter );
520 | }
521 |
522 | $args = wp_parse_args( $args, array(
523 | 'image_size' => 'thumbnail',
524 | ) );
525 |
526 | $ID = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
527 |
528 | if ( empty( $ID ) ) {
529 | return array();
530 | }
531 |
532 | $data = array();
533 |
534 | if ( in_array( $args['image_size'], array( 'full', 'fullsize' ) ) ) {
535 | $src = wp_get_attachment_image_src( $ID, 'full' );
536 |
537 | if ( isset( $src[0] ) ) {
538 | $data['url'] = $src[0];
539 | }
540 | if ( isset( $src[1] ) ) {
541 | $data['width'] = $src[1];
542 | }
543 | if ( isset( $src[2] ) ) {
544 | $data['height'] = $src[2];
545 | }
546 | }
547 | else {
548 | $data = image_get_intermediate_size( $ID, $args['image_size'] );
549 | }
550 |
551 | if ( ! empty( $data ) ) {
552 | return $data;
553 | }
554 |
555 | return array();
556 | }
557 |
--------------------------------------------------------------------------------
/taxonomy-images.php:
--------------------------------------------------------------------------------
1 | 'detail',
72 | 'size' => array( 75, 75, true )
73 | );
74 | }
75 |
76 |
77 | /**
78 | * Register custom image size with WordPress.
79 | *
80 | * @access private
81 | * @since 2010-10-28
82 | */
83 | function taxonomy_image_plugin_add_image_size() {
84 | $detail = taxonomy_image_plugin_detail_image_size();
85 | add_image_size(
86 | $detail['name'],
87 | $detail['size'][0],
88 | $detail['size'][1],
89 | $detail['size'][2]
90 | );
91 | }
92 | add_action( 'init', 'taxonomy_image_plugin_add_image_size' );
93 |
94 |
95 | /**
96 | * Load Plugin Text Domain.
97 | *
98 | * @access private
99 | * @since 0.7.3
100 | */
101 | function taxonomy_image_plugin_text_domain() {
102 | load_plugin_textdomain( 'taxonomy-images', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
103 | }
104 | add_action( 'init', 'taxonomy_image_plugin_text_domain' );
105 |
106 |
107 | /**
108 | * Modal Button.
109 | *
110 | * Create a button in the modal media window to associate the current image to the term.
111 | *
112 | * @param array Multidimensional array representing the images form.
113 | * @param stdClass WordPress post object.
114 | * @return array The image's form array with added button if modal window was accessed by this script.
115 | *
116 | * @access private
117 | * @since 2010-10-28
118 | * @alter 0.7
119 | */
120 | function taxonomy_image_plugin_modal_button( $fields, $post ) {
121 | if ( isset( $fields['image-size'] ) && isset( $post->ID ) ) {
122 | $image_id = (int) $post->ID;
123 |
124 | $o = '