Version Description
- Pass an empty array as default second parameter of
taxonomy_images_plugin_get_the_terms()
andtaxonomy_images_plugin_list_the_terms()
. - Use jQuery.on() instead of jQuery.live(). Props jamiemchale.
- Give the button on the custom admin screen a class of
button-primary
. - Store the return value of
get_posts()
in a variable called$images
. Not sure why, but this should not harm anything. - Change license to GPLv2 or later for maximum flexibility and compatibility.
- Add jamiemchale as a contributor.
- Random whitespace fixes.
- Update Documentation.
- CSS coding standards.
- Bump version number.
- Update Readmes.
Download this release
Release Info
Developer | husobj |
Plugin | Taxonomy Images |
Version | 0.8.0 |
Comparing to | |
See all releases |
Version 0.8.0
- admin.css +57 -0
- blank.png +0 -0
- code-snippets.php +184 -0
- controls.png +0 -0
- default.png +0 -0
- deprecated.php +103 -0
- edit-tags.js +32 -0
- languages/taxonomy-images.pot +221 -0
- media-upload-popup.js +136 -0
- public-filters.php +556 -0
- readme.md +307 -0
- readme.txt +299 -0
- style.css +24 -0
- taxonomy-images.php +1184 -0
admin.css
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.taxonomy-images-modal .create-association .term-name {
|
2 |
+
font-style: italic;
|
3 |
+
}
|
4 |
+
.taxonomy-images-modal .create-association {
|
5 |
+
display: inline;
|
6 |
+
}
|
7 |
+
.taxonomy-images-modal .remove-association {
|
8 |
+
color: #bc0b0b;
|
9 |
+
cursor: pointer;
|
10 |
+
display: none;
|
11 |
+
text-decoration: underline;
|
12 |
+
}
|
13 |
+
.taxonomy-images-modal #tab-type_url,
|
14 |
+
.taxonomy-images-modal .savesend input {
|
15 |
+
display: none !important;
|
16 |
+
}
|
17 |
+
.taxonomy-image-thumbnail {
|
18 |
+
display: block;
|
19 |
+
margin-bottom: 3px;
|
20 |
+
overflow: hidden;
|
21 |
+
text-align: center;
|
22 |
+
width: 77px;
|
23 |
+
height: 77px;
|
24 |
+
}
|
25 |
+
.taxonomy-image-control .control {
|
26 |
+
background: url( controls.png );
|
27 |
+
background-repeat: no-repeat;
|
28 |
+
display: block;
|
29 |
+
float: left;
|
30 |
+
text-indent: -9999em;
|
31 |
+
width: 15px;
|
32 |
+
height: 15px;
|
33 |
+
}
|
34 |
+
.taxonomy-image-control .control:hover {
|
35 |
+
cursor: pointer;
|
36 |
+
}
|
37 |
+
.taxonomy-image-control .upload {
|
38 |
+
background-position: 0 0;
|
39 |
+
}
|
40 |
+
.taxonomy-image-control .upload:hover {
|
41 |
+
background-position: -15px 0;
|
42 |
+
}
|
43 |
+
.taxonomy-image-control .remove {
|
44 |
+
background-position: -30px 0;
|
45 |
+
}
|
46 |
+
.taxonomy-image-control .remove:hover {
|
47 |
+
background-position: -45px 0;
|
48 |
+
}
|
49 |
+
.taxonomy-image-control .library {
|
50 |
+
background-position: -60px 0;
|
51 |
+
}
|
52 |
+
.taxonomy-image-control .hide {
|
53 |
+
visibility: hidden;
|
54 |
+
}
|
55 |
+
.taxonomy-image-control .show {
|
56 |
+
visibility: visible;
|
57 |
+
}
|
blank.png
ADDED
Binary file
|
code-snippets.php
ADDED
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Tests for various filters.
|
4 |
+
*/
|
5 |
+
|
6 |
+
|
7 |
+
exit;
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
/*
|
12 |
+
* Append the term images to content + excerpt.
|
13 |
+
*/
|
14 |
+
function mytheme_append_the_term_images( $content ) {
|
15 |
+
return $content . apply_filters( 'taxonomy-images-list-the-terms', '', array(
|
16 |
+
'image_size' => 'detail',
|
17 |
+
) );
|
18 |
+
}
|
19 |
+
add_filter( 'the_content', 'mytheme_append_the_term_images' );
|
20 |
+
add_filter( 'the_excerpt', 'mytheme_append_the_term_images' );
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
/*
|
25 |
+
* Queried Term Image.
|
26 |
+
*
|
27 |
+
* Return html markup representing the image associated with the
|
28 |
+
* currently queried term. In the event that no associated image
|
29 |
+
* exists, the filter should return an empty object.
|
30 |
+
*
|
31 |
+
* In the event that the Taxonomy Images plugin is not installed
|
32 |
+
* apply_filters() will return it's second parameter.
|
33 |
+
*/
|
34 |
+
|
35 |
+
|
36 |
+
/* Default */
|
37 |
+
$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN' );
|
38 |
+
print '<h2>taxonomy-images-queried-term-image</h2>';
|
39 |
+
print '<pre>' . htmlentities( $img ) . '</pre>';
|
40 |
+
|
41 |
+
|
42 |
+
/* Inside a yellow box */
|
43 |
+
$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN', array(
|
44 |
+
'before' => '<div style="padding:20px;background-color:yellow;">',
|
45 |
+
'after' => '</div>',
|
46 |
+
) );
|
47 |
+
print '<h2>taxonomy-images-queried-term-image - custom wrapper element.</h2>';
|
48 |
+
print '<pre>' . htmlentities( $img ) . '</pre>';
|
49 |
+
|
50 |
+
|
51 |
+
/* Medium Size */
|
52 |
+
$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN', array(
|
53 |
+
'image_size' => 'medium',
|
54 |
+
) );
|
55 |
+
print '<h2>taxonomy-images-queried-term-image - medium image size</h2>';
|
56 |
+
print '<pre>' . htmlentities( $img ) . '</pre>';
|
57 |
+
|
58 |
+
|
59 |
+
/* Unrecognized size */
|
60 |
+
$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN', array(
|
61 |
+
'image_size' => 'this-is-probably-not-a-real-image-size',
|
62 |
+
) );
|
63 |
+
print '<h2>taxonomy-images-queried-term-image - unknown image size</h2>';
|
64 |
+
print '<pre>' . htmlentities( $img ) . '</pre>';
|
65 |
+
|
66 |
+
|
67 |
+
/* Custom attributes. */
|
68 |
+
$img = apply_filters( 'taxonomy-images-queried-term-image', 'PLEASE INSTALL PLUGIN', array(
|
69 |
+
'attr' => array(
|
70 |
+
'alt' => 'Custom alternative text',
|
71 |
+
'class' => 'my-class-list bunnies turtles',
|
72 |
+
'src' => 'this-is-where-the-image-lives.png',
|
73 |
+
'title' => 'Custom Title',
|
74 |
+
),
|
75 |
+
) );
|
76 |
+
print '<h2>taxonomy-images-queried-term-image - custom attributes</h2>';
|
77 |
+
print '<pre>' . htmlentities( $img ) . '</pre>';
|
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 '<h2>taxonomy-images-queried-term-image-id</h2>';
|
94 |
+
print '<pre>'; var_dump( $img ); print '</pre>';
|
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 '<h2>taxonomy-images-queried-term-image-object</h2>';
|
112 |
+
print '<pre>'; var_dump( $img ); print '</pre>';
|
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 '<h2>taxonomy-images-queried-term-image-url - Default</h2>';
|
132 |
+
print '<pre>'; var_dump( $img ); print '</pre>';
|
133 |
+
|
134 |
+
|
135 |
+
/* Medium Size */
|
136 |
+
$img = apply_filters( 'taxonomy-images-queried-term-image-url', 'PLEASE INSTALL PLUGIN', array(
|
137 |
+
'image_size' => 'medium'
|
138 |
+
) );
|
139 |
+
print '<h2>taxonomy-images-queried-term-image-url - Medium</h2>';
|
140 |
+
print '<pre>'; var_dump( $img ); print '</pre>';
|
141 |
+
|
142 |
+
|
143 |
+
/* Unregistered Size */
|
144 |
+
$img = apply_filters( 'taxonomy-images-queried-term-image-url', 'PLEASE INSTALL PLUGIN', array(
|
145 |
+
'image_size' => 'this-is-not-real-size-probably-I-hope'
|
146 |
+
) );
|
147 |
+
print '<h2>taxonomy-images-queried-term-image-url - Unregistered</h2>';
|
148 |
+
print '<pre>'; var_dump( $img ); print '</pre>';
|
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 '<h2>taxonomy-images-queried-term-image-data - Default</h2>';
|
168 |
+
print '<pre>'; var_dump( $img ); print '</pre>';
|
169 |
+
|
170 |
+
|
171 |
+
/* Medium Size */
|
172 |
+
$img = apply_filters( 'taxonomy-images-queried-term-image-data', 'PLEASE INSTALL PLUGIN', array(
|
173 |
+
'image_size' => 'medium'
|
174 |
+
) );
|
175 |
+
print '<h2>taxonomy-images-queried-term-image-data - Medium</h2>';
|
176 |
+
print '<pre>'; var_dump( $img ); print '</pre>';
|
177 |
+
|
178 |
+
|
179 |
+
/* Unregistered Size */
|
180 |
+
$img = apply_filters( 'taxonomy-images-queried-term-image-data', 'PLEASE INSTALL PLUGIN', array(
|
181 |
+
'image_size' => 'this-is-not-real-size-probably-I-hope'
|
182 |
+
) );
|
183 |
+
print '<h2>taxonomy-images-queried-term-image-data - Unregistered</h2>';
|
184 |
+
print '<pre>'; var_dump( $img ); print '</pre>';
|
controls.png
ADDED
Binary file
|
default.png
ADDED
Binary file
|
deprecated.php
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Deprecated Shortcode.
|
5 |
+
*
|
6 |
+
* @return void
|
7 |
+
* @access private
|
8 |
+
*/
|
9 |
+
function taxonomy_images_plugin_shortcode_deprecated( $atts = array() ) { // DEPRECATED
|
10 |
+
$o = '';
|
11 |
+
$defaults = array(
|
12 |
+
'taxonomy' => 'category',
|
13 |
+
'size' => 'detail',
|
14 |
+
'template' => 'list'
|
15 |
+
);
|
16 |
+
|
17 |
+
extract( shortcode_atts( $defaults, $atts ) );
|
18 |
+
|
19 |
+
/* No taxonomy defined return an html comment. */
|
20 |
+
if ( ! taxonomy_exists( $taxonomy ) ) {
|
21 |
+
$tax = strip_tags( trim( $taxonomy ) );
|
22 |
+
return '<!-- taxonomy_image_plugin error: Taxonomy "' . $taxonomy . '" is not defined.-->';
|
23 |
+
}
|
24 |
+
|
25 |
+
$terms = get_terms( $taxonomy );
|
26 |
+
$associations = taxonomy_image_plugin_get_associations( $refresh = false );
|
27 |
+
|
28 |
+
if ( ! is_wp_error( $terms ) ) {
|
29 |
+
foreach( (array) $terms as $term ) {
|
30 |
+
$url = get_term_link( $term, $term->taxonomy );
|
31 |
+
$title = apply_filters( 'the_title', $term->name );
|
32 |
+
$title_attr = esc_attr( $term->name . ' (' . $term->count . ')' );
|
33 |
+
$description = apply_filters( 'the_content', $term->description );
|
34 |
+
|
35 |
+
$img = '';
|
36 |
+
if ( array_key_exists( $term->term_taxonomy_id, $associations ) ) {
|
37 |
+
$img = wp_get_attachment_image( $associations[$term->term_taxonomy_id], 'detail', false );
|
38 |
+
}
|
39 |
+
|
40 |
+
if( $template === 'grid' ) {
|
41 |
+
$o.= "\n\t" . '<div class="taxonomy_image_plugin-' . $template . '">';
|
42 |
+
$o.= "\n\t\t" . '<a style="float:left;" title="' . $title_attr . '" href="' . $url . '">' . $img . '</a>';
|
43 |
+
$o.= "\n\t" . '</div>';
|
44 |
+
}
|
45 |
+
else {
|
46 |
+
$o.= "\n\t\t" . '<a title="' . $title_attr . '" href="' . $url . '">' . $img . '</a>';;
|
47 |
+
$o.= "\n\t\t" . '<h2 style="clear:none;margin-top:0;padding-top:0;line-height:1em;"><a href="' . $url . '">' . $title . '</a></h2>';
|
48 |
+
$o.= $description;
|
49 |
+
$o.= "\n\t" . '<div style="clear:both;height:1.5em"></div>';
|
50 |
+
$o.= "\n";
|
51 |
+
}
|
52 |
+
}
|
53 |
+
}
|
54 |
+
return $o;
|
55 |
+
}
|
56 |
+
add_shortcode( 'taxonomy_image_plugin', 'taxonomy_images_plugin_shortcode_deprecated' );
|
57 |
+
|
58 |
+
|
59 |
+
/**
|
60 |
+
* This class has been left for backward compatibility with versions
|
61 |
+
* of this plugin 0.5 and under. Please do not use any methods or
|
62 |
+
* properties directly in your theme.
|
63 |
+
*
|
64 |
+
* @access private This class is deprecated. Do not use!!!
|
65 |
+
*/
|
66 |
+
class taxonomy_images_plugin {
|
67 |
+
public $settings = array();
|
68 |
+
public function __construct() {
|
69 |
+
$this->settings = taxonomy_image_plugin_get_associations();
|
70 |
+
add_action( 'taxonomy_image_plugin_print_image_html', array( &$this, 'print_image_html' ), 1, 3 );
|
71 |
+
}
|
72 |
+
public function get_thumb( $id ) {
|
73 |
+
return taxonomy_image_plugin_get_image_src( $id );
|
74 |
+
}
|
75 |
+
public function print_image_html( $size = 'medium', $term_tax_id = false, $title = true, $align = 'none' ) {
|
76 |
+
print $this->get_image_html( $size, $term_tax_id, $title, $align );
|
77 |
+
}
|
78 |
+
public function get_image_html( $size = 'medium', $term_tax_id = false, $title = true, $align = 'none' ) {
|
79 |
+
$o = '';
|
80 |
+
if ( false === $term_tax_id ) {
|
81 |
+
global $wp_query;
|
82 |
+
$obj = $wp_query->get_queried_object();
|
83 |
+
if ( isset( $obj->term_taxonomy_id ) ) {
|
84 |
+
$term_tax_id = $obj->term_taxonomy_id;
|
85 |
+
}
|
86 |
+
else {
|
87 |
+
return false;
|
88 |
+
}
|
89 |
+
}
|
90 |
+
$term_tax_id = (int) $term_tax_id;
|
91 |
+
if ( isset( $this->settings[ $term_tax_id ] ) ) {
|
92 |
+
$attachment_id = (int) $this->settings[ $term_tax_id ];
|
93 |
+
$alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true );
|
94 |
+
$attachment = get_post( $attachment_id );
|
95 |
+
/* Just in case an attachment was deleted, but there is still a record for it in this plugins settings. */
|
96 |
+
if ( $attachment !== NULL ) {
|
97 |
+
$o = get_image_tag( $attachment_id, $alt, '', $align, $size );
|
98 |
+
}
|
99 |
+
}
|
100 |
+
return $o;
|
101 |
+
}
|
102 |
+
}
|
103 |
+
$taxonomy_images_plugin = new taxonomy_images_plugin();
|
edit-tags.js
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
jQuery( document ).ready( function( $ ) {
|
2 |
+
|
3 |
+
$( 'body' ).on( 'click', '.taxonomy-image-control a', function () {
|
4 |
+
taxonomyImagesPlugin.tt_id = parseInt( $( this ).parent().find( 'input.tt_id' ).val() );
|
5 |
+
taxonomyImagesPlugin.term_name = $( this ).parent().find( 'input.term_name' ).val();
|
6 |
+
taxonomyImagesPlugin.image_id = parseInt( $( this ).parent().find( 'input.image_id' ).val() );
|
7 |
+
} );
|
8 |
+
|
9 |
+
$( 'body' ).on( 'click', '.taxonomy-image-control .remove', function () {
|
10 |
+
$.ajax( {
|
11 |
+
url: ajaxurl,
|
12 |
+
type: "POST",
|
13 |
+
dataType: 'json',
|
14 |
+
data: {
|
15 |
+
'action' : 'taxonomy_image_plugin_remove_association',
|
16 |
+
'wp_nonce' : taxonomyImagesPlugin.nonce,
|
17 |
+
'tt_id' : taxonomyImagesPlugin.tt_id
|
18 |
+
},
|
19 |
+
cache: false,
|
20 |
+
success: function ( response ) {
|
21 |
+
if ( 'good' === response.status ) {
|
22 |
+
$( '#remove-' + taxonomyImagesPlugin.tt_id ).addClass( 'hide' );
|
23 |
+
$( '#taxonomy_image_plugin_' + taxonomyImagesPlugin.tt_id ).attr( 'src', taxonomyImagesPlugin.img_src );
|
24 |
+
}
|
25 |
+
else if ( 'bad' === response.status ) {
|
26 |
+
alert( response.why );
|
27 |
+
}
|
28 |
+
}
|
29 |
+
} );
|
30 |
+
return false;
|
31 |
+
} );
|
32 |
+
} );
|
languages/taxonomy-images.pot
ADDED
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) 2011 Taxonomy Images
|
2 |
+
# This file is distributed under the same license as the Taxonomy Images package.
|
3 |
+
msgid ""
|
4 |
+
msgstr ""
|
5 |
+
"Project-Id-Version: Taxonomy Images 0.7.2\n"
|
6 |
+
"Report-Msgid-Bugs-To: http://wordpress.org/tag/taxonomy-images\n"
|
7 |
+
"POT-Creation-Date: 2011-06-20 17:47:57+00:00\n"
|
8 |
+
"MIME-Version: 1.0\n"
|
9 |
+
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
+
"Content-Transfer-Encoding: 8bit\n"
|
11 |
+
"PO-Revision-Date: 2010-MO-DA HO:MI+ZONE\n"
|
12 |
+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
13 |
+
"Language-Team: LANGUAGE <LL@li.org>\n"
|
14 |
+
|
15 |
+
#: taxonomy-images.php:125
|
16 |
+
msgid "Associate with %1$s"
|
17 |
+
msgstr ""
|
18 |
+
|
19 |
+
#: taxonomy-images.php:125 taxonomy-images.php:127
|
20 |
+
msgid "this term"
|
21 |
+
msgstr ""
|
22 |
+
|
23 |
+
#: taxonomy-images.php:127
|
24 |
+
msgid "Remove association with %1$s"
|
25 |
+
msgstr ""
|
26 |
+
|
27 |
+
#. translators: Notice displayed on the custom administration page.
|
28 |
+
#: taxonomy-images.php:281
|
29 |
+
msgid "Image support for taxonomies successfully updated"
|
30 |
+
msgstr ""
|
31 |
+
|
32 |
+
#. translators: Notice displayed on the custom administration page.
|
33 |
+
#: taxonomy-images.php:284
|
34 |
+
msgid "Image support has been disabled for all taxonomies."
|
35 |
+
msgstr ""
|
36 |
+
|
37 |
+
#: taxonomy-images.php:324 taxonomy-images.php:1170
|
38 |
+
msgid "Settings"
|
39 |
+
msgstr ""
|
40 |
+
|
41 |
+
#: taxonomy-images.php:330
|
42 |
+
msgid "Taxonomies"
|
43 |
+
msgstr ""
|
44 |
+
|
45 |
+
#. #-#-#-#-# plugin.pot (Taxonomy Images 0.7.2) #-#-#-#-#
|
46 |
+
#. Plugin Name of the plugin/theme
|
47 |
+
#: taxonomy-images.php:349 taxonomy-images.php:350
|
48 |
+
msgid "Taxonomy Images"
|
49 |
+
msgstr ""
|
50 |
+
|
51 |
+
#. translators: Heading of the custom administration page.
|
52 |
+
#: taxonomy-images.php:377
|
53 |
+
msgid "Taxonomy Images Plugin Settings"
|
54 |
+
msgstr ""
|
55 |
+
|
56 |
+
#. translators: Button on the custom administration page.
|
57 |
+
#: taxonomy-images.php:385
|
58 |
+
msgid "Save Changes"
|
59 |
+
msgstr ""
|
60 |
+
|
61 |
+
#. translators: An ajax request has failed for an unknown reason.
|
62 |
+
#: taxonomy-images.php:432
|
63 |
+
msgid "Unknown error encountered"
|
64 |
+
msgstr ""
|
65 |
+
|
66 |
+
#: taxonomy-images.php:507 taxonomy-images.php:589
|
67 |
+
msgid "tt_id not sent"
|
68 |
+
msgstr ""
|
69 |
+
|
70 |
+
#: taxonomy-images.php:515 taxonomy-images.php:597
|
71 |
+
msgid "tt_id is empty"
|
72 |
+
msgstr ""
|
73 |
+
|
74 |
+
#: taxonomy-images.php:522 taxonomy-images.php:604
|
75 |
+
msgid "You do not have the correct capability to manage this term"
|
76 |
+
msgstr ""
|
77 |
+
|
78 |
+
#: taxonomy-images.php:529
|
79 |
+
msgid "No nonce included."
|
80 |
+
msgstr ""
|
81 |
+
|
82 |
+
#: taxonomy-images.php:536 taxonomy-images.php:618
|
83 |
+
msgid "Nonce did not match"
|
84 |
+
msgstr ""
|
85 |
+
|
86 |
+
#: taxonomy-images.php:543
|
87 |
+
msgid "Image id not sent"
|
88 |
+
msgstr ""
|
89 |
+
|
90 |
+
#: taxonomy-images.php:551
|
91 |
+
msgid "Image id is not a positive integer"
|
92 |
+
msgstr ""
|
93 |
+
|
94 |
+
#: taxonomy-images.php:560
|
95 |
+
msgid "Image successfully associated"
|
96 |
+
msgstr ""
|
97 |
+
|
98 |
+
#: taxonomy-images.php:567
|
99 |
+
msgid "Association could not be created"
|
100 |
+
msgstr ""
|
101 |
+
|
102 |
+
#: taxonomy-images.php:611
|
103 |
+
msgid "No nonce included"
|
104 |
+
msgstr ""
|
105 |
+
|
106 |
+
#: taxonomy-images.php:626
|
107 |
+
msgid "Nothing to remove"
|
108 |
+
msgstr ""
|
109 |
+
|
110 |
+
#: taxonomy-images.php:635
|
111 |
+
msgid "Association successfully removed"
|
112 |
+
msgstr ""
|
113 |
+
|
114 |
+
#: taxonomy-images.php:641
|
115 |
+
msgid "Association could not be removed"
|
116 |
+
msgstr ""
|
117 |
+
|
118 |
+
#: taxonomy-images.php:711 taxonomy-images.php:760
|
119 |
+
msgid "Image"
|
120 |
+
msgstr ""
|
121 |
+
|
122 |
+
#: taxonomy-images.php:754 taxonomy-images.php:790
|
123 |
+
msgid "term"
|
124 |
+
msgstr ""
|
125 |
+
|
126 |
+
#: taxonomy-images.php:764
|
127 |
+
msgid "Associate an image from your media library to this %1$s."
|
128 |
+
msgstr ""
|
129 |
+
|
130 |
+
#: taxonomy-images.php:808
|
131 |
+
msgid "Associate an image with the %1$s named “%2$s”."
|
132 |
+
msgstr ""
|
133 |
+
|
134 |
+
#: taxonomy-images.php:809
|
135 |
+
msgid "Upload a new image for this %s."
|
136 |
+
msgstr ""
|
137 |
+
|
138 |
+
#: taxonomy-images.php:809
|
139 |
+
msgid "Upload."
|
140 |
+
msgstr ""
|
141 |
+
|
142 |
+
#: taxonomy-images.php:810
|
143 |
+
msgid "Remove image from this %s."
|
144 |
+
msgstr ""
|
145 |
+
|
146 |
+
#: taxonomy-images.php:810
|
147 |
+
msgid "Delete"
|
148 |
+
msgstr ""
|
149 |
+
|
150 |
+
#: taxonomy-images.php:839
|
151 |
+
msgid "“"
|
152 |
+
msgstr ""
|
153 |
+
|
154 |
+
#: taxonomy-images.php:840
|
155 |
+
msgid "”"
|
156 |
+
msgstr ""
|
157 |
+
|
158 |
+
#: taxonomy-images.php:841
|
159 |
+
msgid "Associating …"
|
160 |
+
msgstr ""
|
161 |
+
|
162 |
+
#: taxonomy-images.php:842
|
163 |
+
msgid "Successfully Associated"
|
164 |
+
msgstr ""
|
165 |
+
|
166 |
+
#: taxonomy-images.php:843
|
167 |
+
msgid "Removing …"
|
168 |
+
msgstr ""
|
169 |
+
|
170 |
+
#: taxonomy-images.php:844
|
171 |
+
msgid "Successfully Removed"
|
172 |
+
msgstr ""
|
173 |
+
|
174 |
+
#: taxonomy-images.php:1098
|
175 |
+
msgid ""
|
176 |
+
"The %1$s argument for %2$s is set to %3$s which is not a registered "
|
177 |
+
"taxonomy. Please check the spelling and update the argument."
|
178 |
+
msgstr ""
|
179 |
+
|
180 |
+
#: taxonomy-images.php:1099
|
181 |
+
msgid "taxonomy"
|
182 |
+
msgstr ""
|
183 |
+
|
184 |
+
#: taxonomy-images.php:1109
|
185 |
+
msgid "No taxonomies have image support. %1$s"
|
186 |
+
msgstr ""
|
187 |
+
|
188 |
+
#: taxonomy-images.php:1114
|
189 |
+
msgid "The %1$s taxonomy does not have image support. %2$s"
|
190 |
+
msgstr ""
|
191 |
+
|
192 |
+
#: taxonomy-images.php:1139
|
193 |
+
msgid "The %1$s has been called directly. Please use the %2$s filter instead."
|
194 |
+
msgstr ""
|
195 |
+
|
196 |
+
#: taxonomy-images.php:1175
|
197 |
+
msgid "Donate"
|
198 |
+
msgstr ""
|
199 |
+
|
200 |
+
#: taxonomy-images.php:1193
|
201 |
+
msgid "Manage Settings"
|
202 |
+
msgstr ""
|
203 |
+
|
204 |
+
#: public-filters.php:376
|
205 |
+
msgid ""
|
206 |
+
"%1$s is not a property of the current queried object. This usually happens "
|
207 |
+
"when the %2$s filter is used in an unsupported template file. This filter "
|
208 |
+
"has been designed to work in taxonomy archives which are traditionally "
|
209 |
+
"served by one of the following template files: category.php, tag.php or "
|
210 |
+
"taxonomy.php. Learn more about %3$s."
|
211 |
+
msgstr ""
|
212 |
+
|
213 |
+
#: public-filters.php:377
|
214 |
+
msgid "term_taxonomy_id"
|
215 |
+
msgstr ""
|
216 |
+
|
217 |
+
#. Description of the plugin/theme
|
218 |
+
msgid ""
|
219 |
+
"Associate images from your media library to categories, tags and custom "
|
220 |
+
"taxonomies."
|
221 |
+
msgstr ""
|
media-upload-popup.js
ADDED
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var TaxonomyImagesCreateAssociation;
|
2 |
+
|
3 |
+
jQuery( document ).ready( function( $ ) {
|
4 |
+
var ID = 0, below;
|
5 |
+
|
6 |
+
/* Get window that opened the thickbox. */
|
7 |
+
below = window.dialogArguments || opener || parent || top;
|
8 |
+
|
9 |
+
if ( null !== below && 'taxonomyImagesPlugin' in below ) {
|
10 |
+
/* Set the value of ID. */
|
11 |
+
if ( 'tt_id' in below.taxonomyImagesPlugin ) {
|
12 |
+
ID = parseInt( below.taxonomyImagesPlugin.tt_id );
|
13 |
+
if ( isNaN( ID ) ) {
|
14 |
+
ID = 0;
|
15 |
+
}
|
16 |
+
}
|
17 |
+
/* Replace term name. */
|
18 |
+
if ( 'term_name' in below.taxonomyImagesPlugin ) {
|
19 |
+
$( '.create-association .term-name' ).html( TaxonomyImagesModal.termBefore + below.taxonomyImagesPlugin.term_name + TaxonomyImagesModal.termAfter );
|
20 |
+
}
|
21 |
+
}
|
22 |
+
|
23 |
+
if ( 0 < ID ) {
|
24 |
+
$( 'body' ).addClass( 'taxonomy-images-modal' );
|
25 |
+
|
26 |
+
var buttons = $( '.taxonomy-images-modal .create-association' );
|
27 |
+
|
28 |
+
/* Add hidden input to search form. */
|
29 |
+
$( '#filter' ).prepend( '<input type="hidden" name="taxonomy_images_plugin" value="' + ID + '" />' );
|
30 |
+
|
31 |
+
if ( 'image_id' in below.taxonomyImagesPlugin ) {
|
32 |
+
buttons.each( function( i, e ) {
|
33 |
+
var image_id = $( e ).parent().find( '.taxonomy-image-button-image-id' ).val();
|
34 |
+
if ( image_id == below.taxonomyImagesPlugin.image_id ) {
|
35 |
+
$( e ).hide();
|
36 |
+
$( e ).parent().find( '.remove-association' ).css( 'display', 'inline' );
|
37 |
+
}
|
38 |
+
} );
|
39 |
+
}
|
40 |
+
}
|
41 |
+
|
42 |
+
$( '.taxonomy-images-modal' ).on( 'click', '.remove-association', function () {
|
43 |
+
var button = $( this );
|
44 |
+
originalText = button.html();
|
45 |
+
button.html( TaxonomyImagesModal.removing );
|
46 |
+
|
47 |
+
$.ajax( {
|
48 |
+
url: ajaxurl,
|
49 |
+
type: "POST",
|
50 |
+
dataType: 'json',
|
51 |
+
data: {
|
52 |
+
'action' : 'taxonomy_image_plugin_remove_association',
|
53 |
+
'wp_nonce' : $( this ).parent().find( '.taxonomy-image-button-nonce-remove' ).val(),
|
54 |
+
'tt_id' : ID
|
55 |
+
},
|
56 |
+
cache: false,
|
57 |
+
success: function ( response ) {
|
58 |
+
if ( 'good' === response.status ) {
|
59 |
+
button.html( TaxonomyImagesModal.removed ).fadeOut( 200, function() {
|
60 |
+
$( this ).hide();
|
61 |
+
var selector = parent.document.getElementById( 'taxonomy_image_plugin_' + ID );
|
62 |
+
$( selector ).attr( 'src', below.taxonomyImagesPlugin.img_src );
|
63 |
+
$( this ).parent().find( '.create-association' ).show();
|
64 |
+
$( this ).html( originalText );
|
65 |
+
} );
|
66 |
+
}
|
67 |
+
else if ( 'bad' === response.status ) {
|
68 |
+
alert( response.why );
|
69 |
+
}
|
70 |
+
}
|
71 |
+
} );
|
72 |
+
return false;
|
73 |
+
} );
|
74 |
+
|
75 |
+
$( '.taxonomy-images-modal' ).on( 'click', '.create-association', function () {
|
76 |
+
var button, selector, originalText;
|
77 |
+
if ( 0 == ID ) {
|
78 |
+
return;
|
79 |
+
}
|
80 |
+
|
81 |
+
button = $( this );
|
82 |
+
originalText = button.html();
|
83 |
+
button.html( TaxonomyImagesModal.associating );
|
84 |
+
|
85 |
+
$.ajax( {
|
86 |
+
url : ajaxurl,
|
87 |
+
type : "POST",
|
88 |
+
dataType : 'json',
|
89 |
+
data: {
|
90 |
+
'action' : 'taxonomy_image_create_association',
|
91 |
+
'wp_nonce' : $( this ).parent().find( '.taxonomy-image-button-nonce-create' ).val(),
|
92 |
+
'attachment_id' : $( this ).parent().find( '.taxonomy-image-button-image-id' ).val(),
|
93 |
+
'tt_id' : parseInt( ID )
|
94 |
+
},
|
95 |
+
success: function ( response ) {
|
96 |
+
if ( 'good' === response.status ) {
|
97 |
+
var parent_id = button.parent().attr( 'id' );
|
98 |
+
|
99 |
+
/* Set state of all other buttons. */
|
100 |
+
$( '.taxonomy-image-modal-control' ).each( function( i, e ) {
|
101 |
+
if ( parent_id == $( e ).attr( 'id' ) ) {
|
102 |
+
return true;
|
103 |
+
}
|
104 |
+
$( e ).find( '.create-association' ).show();
|
105 |
+
$( e ).find( '.remove-association' ).hide();
|
106 |
+
} );
|
107 |
+
|
108 |
+
selector = parent.document.getElementById( 'taxonomy-image-control-' + ID );
|
109 |
+
|
110 |
+
/* Update the image on the screen below */
|
111 |
+
$( selector ).find( '.taxonomy-image-thumbnail img' ).each( function ( i, e ) {
|
112 |
+
$( e ).attr( 'src', response.attachment_thumb_src );
|
113 |
+
} );
|
114 |
+
|
115 |
+
/* Show delete control on the screen below */
|
116 |
+
$( selector ).find( '.remove' ).each( function ( i, e ) {
|
117 |
+
$( e ).removeClass( 'hide' );
|
118 |
+
} );
|
119 |
+
|
120 |
+
button.show().html( TaxonomyImagesModal.success ).fadeOut( 200, function() {
|
121 |
+
var remove = button.parent().find( '.remove-association' );
|
122 |
+
if ( undefined !== remove[0] ) {
|
123 |
+
$( remove ).css( 'display', 'inline' );
|
124 |
+
button.hide();
|
125 |
+
button.html( originalText );
|
126 |
+
}
|
127 |
+
} );
|
128 |
+
}
|
129 |
+
else if ( 'bad' === response.status ) {
|
130 |
+
alert( response.why );
|
131 |
+
}
|
132 |
+
}
|
133 |
+
} );
|
134 |
+
return false;
|
135 |
+
} );
|
136 |
+
} );
|
public-filters.php
ADDED
@@ -0,0 +1,556 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Interface.
|
4 |
+
*
|
5 |
+
* All functions defined in this plugin should be considered
|
6 |
+
* private meaning that they are not to be used in any other
|
7 |
+
* WordPress extension including plugins and themes. Direct
|
8 |
+
* use of functions defined herein constitutes unsupported use
|
9 |
+
* and is strongly discouraged. This file contains custom filters
|
10 |
+
* which enable extension authors to interact with this plugin in
|
11 |
+
* a responsible manner.
|
12 |
+
*
|
13 |
+
* @package Taxonomy Images
|
14 |
+
* @author Michael Fields <michael@mfields.org>
|
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: '</ul>'. Optional.
|
221 |
+
*
|
222 |
+
* after_image (string) Text to append to each image in the
|
223 |
+
* list. Defaults to: '</li>'. Optional.
|
224 |
+
*
|
225 |
+
* before (string) Text to preppend to the output.
|
226 |
+
* Defaults to: '<ul class="taxonomy-images-the-terms">'.
|
227 |
+
* Optional.
|
228 |
+
*
|
229 |
+
* before_image (string) Text to prepend to each image in the
|
230 |
+
* list. Defaults to: '<li>'. 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' => '</ul>',
|
259 |
+
'after_image' => '</li>',
|
260 |
+
'before' => '<ul class="taxonomy-images-the-terms">',
|
261 |
+
'before_image' => '<li>',
|
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'] . '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . $image .'</a>' . $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 |
+
'<code>' . esc_html__( 'term_taxonomy_id', 'taxonomy-images' ) . '</code>',
|
387 |
+
'<code>' . esc_html( $filter ) . '</code>',
|
388 |
+
'<a href="http://codex.wordpress.org/Template_Hierarchy">' . esc_html( 'template hierarchy', 'taxonomy-images' ) . '</a>'
|
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 |
+
}
|
readme.md
ADDED
@@ -0,0 +1,307 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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' => '</div>'
|
34 |
+
'attr' => array(
|
35 |
+
'alt' => 'Custom alternative text',
|
36 |
+
'class' => 'my-class-list bunnies turtles',
|
37 |
+
'src' => 'this-is-where-the-image-lives.png',
|
38 |
+
'title' => 'Custom Title',
|
39 |
+
),
|
40 |
+
'before' => '<div id="my-custom-div">',
|
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' => '</div>',
|
105 |
+
'after_image' => '</span>',
|
106 |
+
'before' => '<div class="my-custom-class-name">',
|
107 |
+
'before_image' => '<span>',
|
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 '<ul>';
|
156 |
+
foreach( (array) $terms as $term ) {
|
157 |
+
print '<li><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'detail' ) . '</li>';
|
158 |
+
}
|
159 |
+
print '</ul>';
|
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.
|
readme.txt
ADDED
@@ -0,0 +1,299 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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' => '</div>'
|
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' => '<div id="my-custom-div">',
|
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' => '</div>',
|
112 |
+
'after_image' => '</span>',
|
113 |
+
'before' => '<div class="my-custom-class-name">',
|
114 |
+
'before_image' => '<span>',
|
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 '<ul>';
|
166 |
+
foreach( (array) $terms as $term ) {
|
167 |
+
print '<li><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'detail' ) . '</li>';
|
168 |
+
}
|
169 |
+
print '</ul>';
|
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.
|
style.css
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.taxonomy-images-the-terms {
|
2 |
+
margin: 10px 0;
|
3 |
+
padding: 0;
|
4 |
+
zoom: 1;
|
5 |
+
}
|
6 |
+
.taxonomy-images-the-terms:before,
|
7 |
+
.taxonomy-images-the-terms:after {
|
8 |
+
clear: both;
|
9 |
+
content: "\0020";
|
10 |
+
display: block;
|
11 |
+
height: 0;
|
12 |
+
visibility: hidden;
|
13 |
+
}
|
14 |
+
.taxonomy-images-the-terms li,
|
15 |
+
.taxonomy-images-the-terms a,
|
16 |
+
.taxonomy-images-the-terms img {
|
17 |
+
float:left;
|
18 |
+
margin:0;
|
19 |
+
padding:0;
|
20 |
+
}
|
21 |
+
.taxonomy-images-the-terms li {
|
22 |
+
list-style-type:none;
|
23 |
+
margin:0 10px 10px 0;
|
24 |
+
}
|
taxonomy-images.php
ADDED
@@ -0,0 +1,1184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Taxonomy Images
|
4 |
+
Plugin URI: http://wordpress.mfields.org/plugins/taxonomy-images/
|
5 |
+
Description: Associate images from your media library to categories, tags and custom taxonomies.
|
6 |
+
Version: 0.8.0
|
7 |
+
Author: Michael Fields
|
8 |
+
Author URI: http://wordpress.mfields.org/
|
9 |
+
License: GNU General Public License v2 or later
|
10 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
+
|
12 |
+
Copyright 2010-2011 Michael Fields michael@mfields.org
|
13 |
+
|
14 |
+
This program is free software; you can redistribute it and/or modify
|
15 |
+
it under the terms of the GNU General Public License version 2 as published by
|
16 |
+
the Free Software Foundation.
|
17 |
+
|
18 |
+
This program is distributed in the hope that it will be useful,
|
19 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
+
GNU General Public License for more details.
|
22 |
+
|
23 |
+
You should have received a copy of the GNU General Public License
|
24 |
+
along with this program; if not, write to the Free Software
|
25 |
+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
26 |
+
*/
|
27 |
+
|
28 |
+
|
29 |
+
require_once( trailingslashit( dirname( __FILE__ ) ) . 'deprecated.php' );
|
30 |
+
require_once( trailingslashit( dirname( __FILE__ ) ) . 'public-filters.php' );
|
31 |
+
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Version Number.
|
35 |
+
*
|
36 |
+
* @return string The plugin's version number.
|
37 |
+
* @access private
|
38 |
+
* @since 0.7
|
39 |
+
* @alter 0.7.4
|
40 |
+
*/
|
41 |
+
function taxonomy_image_plugin_version() {
|
42 |
+
return '0.8.0';
|
43 |
+
}
|
44 |
+
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Get a url to a file in this plugin.
|
48 |
+
*
|
49 |
+
* @return string
|
50 |
+
* @access private
|
51 |
+
* @since 0.7
|
52 |
+
*/
|
53 |
+
function taxonomy_image_plugin_url( $file = '' ) {
|
54 |
+
static $path = '';
|
55 |
+
if ( empty( $path ) ) {
|
56 |
+
$path = plugin_dir_url( __FILE__ );
|
57 |
+
}
|
58 |
+
return $path . $file;
|
59 |
+
}
|
60 |
+
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Detail Image Size.
|
64 |
+
*
|
65 |
+
* @return array Configuration for the "detail" image size.
|
66 |
+
* @access private
|
67 |
+
* @since 0.7
|
68 |
+
*/
|
69 |
+
function taxonomy_image_plugin_detail_image_size() {
|
70 |
+
return array(
|
71 |
+
'name' => '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 = '<div class="taxonomy-image-modal-control" id="' . esc_attr( 'taxonomy-image-modal-control-' . $image_id ) . '">';
|
125 |
+
|
126 |
+
$o.= '<span class="button create-association">' . sprintf( esc_html__( 'Associate with %1$s', 'taxonomy-images' ), '<span class="term-name">' . esc_html__( 'this term', 'taxonomy-images' ) . '</span>' ) . '</span>';
|
127 |
+
|
128 |
+
$o.= '<span class="remove-association">' . sprintf( esc_html__( 'Remove association with %1$s', 'taxonomy-images' ), '<span class="term-name">' . esc_html__( 'this term', 'taxonomy-images' ) . '</span>' ) . '</span>';
|
129 |
+
|
130 |
+
$o.= '<input class="taxonomy-image-button-image-id" name="' . esc_attr( 'taxonomy-image-button-image-id-' . $image_id ) . '" type="hidden" value="' . esc_attr( $image_id ) . '" />';
|
131 |
+
|
132 |
+
$o.= '<input class="taxonomy-image-button-nonce-create" name="' . esc_attr( 'taxonomy-image-button-nonce-create-' . $image_id ) . '" type="hidden" value="' . esc_attr( wp_create_nonce( 'taxonomy-image-plugin-create-association' ) ) . '" />';
|
133 |
+
|
134 |
+
$o.= '<input class="taxonomy-image-button-nonce-remove" name="' . esc_attr( 'taxonomy-image-button-nonce-remove-' . $image_id ) . '" type="hidden" value="' . esc_attr( wp_create_nonce( 'taxonomy-image-plugin-remove-association' ) ) . '" />';
|
135 |
+
|
136 |
+
$o.= '</div>';
|
137 |
+
|
138 |
+
$fields['image-size']['extra_rows']['taxonomy-image-plugin-button']['html'] = $o;
|
139 |
+
}
|
140 |
+
return $fields;
|
141 |
+
}
|
142 |
+
add_filter( 'attachment_fields_to_edit', 'taxonomy_image_plugin_modal_button', 20, 2 );
|
143 |
+
|
144 |
+
|
145 |
+
/**
|
146 |
+
* Get Image Source.
|
147 |
+
*
|
148 |
+
* Return a uri to a custom image size.
|
149 |
+
*
|
150 |
+
* If size doesn't exist, attempt to create a resized version.
|
151 |
+
* The output of this function should be escaped before printing to the browser.
|
152 |
+
*
|
153 |
+
* @param int Image ID.
|
154 |
+
* @return string URI of custom image on success; emtpy string otherwise.
|
155 |
+
*
|
156 |
+
* @access private.
|
157 |
+
* @since 2010-10-28
|
158 |
+
*/
|
159 |
+
function taxonomy_image_plugin_get_image_src( $id ) {
|
160 |
+
$detail = taxonomy_image_plugin_detail_image_size();
|
161 |
+
|
162 |
+
/* Return url to custom intermediate size if it exists. */
|
163 |
+
$img = image_get_intermediate_size( $id, $detail['name'] );
|
164 |
+
if ( isset( $img['url'] ) )
|
165 |
+
return $img['url'];
|
166 |
+
|
167 |
+
/* Detail image does not exist, attempt to create it. */
|
168 |
+
$wp_upload_dir = wp_upload_dir();
|
169 |
+
if ( isset( $wp_upload_dir['basedir'] ) ) {
|
170 |
+
|
171 |
+
/* Create path to original uploaded image. */
|
172 |
+
$path = trailingslashit( $wp_upload_dir['basedir'] ) . get_post_meta( $id, '_wp_attached_file', true );
|
173 |
+
if ( is_file( $path ) ) {
|
174 |
+
|
175 |
+
/* Attempt to create a new downsized version of the original image. */
|
176 |
+
$new = image_resize( $path,
|
177 |
+
$detail['size'][0],
|
178 |
+
$detail['size'][1],
|
179 |
+
$detail['size'][2]
|
180 |
+
);
|
181 |
+
|
182 |
+
/* Image creation successful. Generate and cache image metadata. Return url. */
|
183 |
+
if ( ! is_wp_error( $new ) ) {
|
184 |
+
$meta = wp_generate_attachment_metadata( $id, $path );
|
185 |
+
wp_update_attachment_metadata( $id, $meta );
|
186 |
+
$img = image_get_intermediate_size( $id, $detail['name'] );
|
187 |
+
if ( isset( $img['url'] ) ) {
|
188 |
+
return $img['url'];
|
189 |
+
}
|
190 |
+
}
|
191 |
+
}
|
192 |
+
}
|
193 |
+
|
194 |
+
/* Custom intermediate size cannot be created, try for thumbnail. */
|
195 |
+
$img = image_get_intermediate_size( $id, 'thumbnail' );
|
196 |
+
if ( isset( $img['url'] ) )
|
197 |
+
return $img['url'];
|
198 |
+
|
199 |
+
/* Thumbnail cannot be found, try fullsize. */
|
200 |
+
$url = wp_get_attachment_url( $id );
|
201 |
+
if ( ! empty( $url ) )
|
202 |
+
return $url;
|
203 |
+
|
204 |
+
/*
|
205 |
+
* No image can be found.
|
206 |
+
* This is most likely caused by a user deleting an attachment before deleting it's association with a taxonomy.
|
207 |
+
* If we are in the administration panels:
|
208 |
+
* - Delete the association.
|
209 |
+
* - Return uri to default.png.
|
210 |
+
*/
|
211 |
+
if ( is_admin() ) {
|
212 |
+
$assoc = taxonomy_image_plugin_get_associations();
|
213 |
+
foreach ( $assoc as $term => $img ) {
|
214 |
+
if ( $img === $id ) {
|
215 |
+
unset( $assoc[$term] );
|
216 |
+
}
|
217 |
+
}
|
218 |
+
update_option( 'taxonomy_image_plugin', $assoc );
|
219 |
+
return taxonomy_image_plugin_url( 'default.png' );
|
220 |
+
}
|
221 |
+
|
222 |
+
/*
|
223 |
+
* No image can be found.
|
224 |
+
* Return path to blank-image.png.
|
225 |
+
*/
|
226 |
+
return taxonomy_image_plugin_url( 'blank.png' );
|
227 |
+
}
|
228 |
+
|
229 |
+
|
230 |
+
/**
|
231 |
+
* Sanitize Associations.
|
232 |
+
*
|
233 |
+
* Ensures that all key/value pairs are positive integers.
|
234 |
+
* This filter will discard all zero and negative values.
|
235 |
+
*
|
236 |
+
* @param array An array of term_taxonomy_id/attachment_id pairs.
|
237 |
+
* @return array Sanitized version of parameter.
|
238 |
+
*
|
239 |
+
* @access private
|
240 |
+
*/
|
241 |
+
function taxonomy_image_plugin_sanitize_associations( $associations ) {
|
242 |
+
$o = array();
|
243 |
+
foreach ( (array) $associations as $tt_id => $im_id ) {
|
244 |
+
$tt_id = absint( $tt_id );
|
245 |
+
$im_id = absint( $im_id );
|
246 |
+
if ( 0 < $tt_id && 0 < $im_id )
|
247 |
+
$o[$tt_id] = $im_id;
|
248 |
+
}
|
249 |
+
return $o;
|
250 |
+
}
|
251 |
+
|
252 |
+
|
253 |
+
/**
|
254 |
+
* Sanitize Settings.
|
255 |
+
*
|
256 |
+
* This function is responsible for ensuring that
|
257 |
+
* all values within the 'taxonomy_image_plugin_settings'
|
258 |
+
* options are of the appropriate type.
|
259 |
+
*
|
260 |
+
* @param array Unknown.
|
261 |
+
* @return array Multi-dimensional array of sanitized settings.
|
262 |
+
*
|
263 |
+
* @access private
|
264 |
+
* @since 0.7
|
265 |
+
*/
|
266 |
+
function taxonomy_image_plugin_settings_sanitize( $dirty ) {
|
267 |
+
$clean = array();
|
268 |
+
if ( isset( $dirty['taxonomies'] ) ) {
|
269 |
+
$taxonomies = get_taxonomies();
|
270 |
+
foreach ( (array) $dirty['taxonomies'] as $taxonomy ) {
|
271 |
+
if ( in_array( $taxonomy, $taxonomies ) )
|
272 |
+
$clean['taxonomies'][] = $taxonomy;
|
273 |
+
}
|
274 |
+
}
|
275 |
+
|
276 |
+
/* translators: Notice displayed on the custom administration page. */
|
277 |
+
$message = __( 'Image support for taxonomies successfully updated', 'taxonomy-images' );
|
278 |
+
if ( empty( $clean ) ) {
|
279 |
+
/* translators: Notice displayed on the custom administration page. */
|
280 |
+
$message = __( 'Image support has been disabled for all taxonomies.', 'taxonomy-images' );
|
281 |
+
}
|
282 |
+
|
283 |
+
add_settings_error( 'taxonomy_image_plugin_settings', 'taxonomies_updated', esc_html( $message ), 'updated' );
|
284 |
+
|
285 |
+
return $clean;
|
286 |
+
}
|
287 |
+
|
288 |
+
|
289 |
+
/**
|
290 |
+
* Register settings with WordPress.
|
291 |
+
*
|
292 |
+
* This plugin will store to sets of settings in the
|
293 |
+
* options table. The first is named 'taxonomy_image_plugin'
|
294 |
+
* and stores the associations between terms and images. The
|
295 |
+
* keys in this array represent the term_taxonomy_id of the
|
296 |
+
* term while the value represents the ID of the image
|
297 |
+
* attachment.
|
298 |
+
*
|
299 |
+
* The second setting is used to store everything else. As of
|
300 |
+
* version 0.7 it has one key named 'taxonomies' whichi is a
|
301 |
+
* flat array consisting of taxonomy names representing a
|
302 |
+
* black-list of registered taxonomies. These taxonomies will
|
303 |
+
* NOT be given an image UI.
|
304 |
+
*
|
305 |
+
* @access private
|
306 |
+
*/
|
307 |
+
function taxonomy_image_plugin_register_settings() {
|
308 |
+
register_setting(
|
309 |
+
'taxonomy_image_plugin',
|
310 |
+
'taxonomy_image_plugin',
|
311 |
+
'taxonomy_image_plugin_sanitize_associations'
|
312 |
+
);
|
313 |
+
register_setting(
|
314 |
+
'taxonomy_image_plugin_settings',
|
315 |
+
'taxonomy_image_plugin_settings',
|
316 |
+
'taxonomy_image_plugin_settings_sanitize'
|
317 |
+
);
|
318 |
+
add_settings_section(
|
319 |
+
'taxonomy_image_plugin_settings',
|
320 |
+
esc_html__( 'Settings', 'taxonomy-images' ),
|
321 |
+
'__return_false',
|
322 |
+
'taxonomy_image_plugin_settings'
|
323 |
+
);
|
324 |
+
add_settings_field(
|
325 |
+
'taxonomy-images',
|
326 |
+
esc_html__( 'Taxonomies', 'taxonomy-images' ),
|
327 |
+
'taxonomy_image_plugin_control_taxonomies',
|
328 |
+
'taxonomy_image_plugin_settings',
|
329 |
+
'taxonomy_image_plugin_settings'
|
330 |
+
);
|
331 |
+
}
|
332 |
+
add_action( 'admin_init', 'taxonomy_image_plugin_register_settings' );
|
333 |
+
|
334 |
+
|
335 |
+
/**
|
336 |
+
* Admin Menu.
|
337 |
+
*
|
338 |
+
* Create the admin menu link for the settings page.
|
339 |
+
*
|
340 |
+
* @access private
|
341 |
+
* @since 0.7
|
342 |
+
*/
|
343 |
+
function taxonomy_images_settings_menu() {
|
344 |
+
add_options_page(
|
345 |
+
esc_html__( 'Taxonomy Images', 'taxonomy-images' ), /* HTML <title> tag. */
|
346 |
+
esc_html__( 'Taxonomy Images', 'taxonomy-images' ), /* Link text in admin menu. */
|
347 |
+
'manage_options',
|
348 |
+
'taxonomy_image_plugin_settings',
|
349 |
+
'taxonomy_image_plugin_settings_page'
|
350 |
+
);
|
351 |
+
}
|
352 |
+
add_action( 'admin_menu', 'taxonomy_images_settings_menu' );
|
353 |
+
|
354 |
+
|
355 |
+
/**
|
356 |
+
* Settings Page Template.
|
357 |
+
*
|
358 |
+
* This function in conjunction with others usei the WordPress
|
359 |
+
* Settings API to create a settings page where users can adjust
|
360 |
+
* the behaviour of this plugin. Please see the following functions
|
361 |
+
* for more insight on the output generated by this function:
|
362 |
+
*
|
363 |
+
* taxonomy_image_plugin_control_taxonomies()
|
364 |
+
*
|
365 |
+
* @access private
|
366 |
+
* @since 0.7
|
367 |
+
*/
|
368 |
+
function taxonomy_image_plugin_settings_page() {
|
369 |
+
print "\n" . '<div class="wrap">';
|
370 |
+
screen_icon();
|
371 |
+
|
372 |
+
/* translators: Heading of the custom administration page. */
|
373 |
+
print "\n" . '<h2>' . esc_html__( 'Taxonomy Images Plugin Settings', 'taxonomy-images' ) . '</h2>';
|
374 |
+
print "\n" . '<div id="taxonomy-images">';
|
375 |
+
print "\n" . '<form action="options.php" method="post">';
|
376 |
+
|
377 |
+
settings_fields( 'taxonomy_image_plugin_settings' );
|
378 |
+
do_settings_sections( 'taxonomy_image_plugin_settings' );
|
379 |
+
|
380 |
+
/* translators: Button on the custom administration page. */
|
381 |
+
print "\n" . '<div class="button-holder"><input class="button-primary" name="submit" type="submit" value="' . esc_attr__( 'Save Changes', 'taxonomy-images' ) . '" /></div>';
|
382 |
+
print "\n" . '</div></form></div>';
|
383 |
+
}
|
384 |
+
|
385 |
+
|
386 |
+
/**
|
387 |
+
* Taxonomy Checklist.
|
388 |
+
*
|
389 |
+
* @access private
|
390 |
+
*/
|
391 |
+
function taxonomy_image_plugin_control_taxonomies() {
|
392 |
+
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
393 |
+
$taxonomies = get_taxonomies( array(), 'objects' );
|
394 |
+
foreach ( (array) $taxonomies as $taxonomy ) {
|
395 |
+
if ( ! isset( $taxonomy->name ) )
|
396 |
+
continue;
|
397 |
+
|
398 |
+
if ( ! isset( $taxonomy->label ) )
|
399 |
+
continue;
|
400 |
+
|
401 |
+
if ( ! isset( $taxonomy->show_ui ) || empty( $taxonomy->show_ui ) )
|
402 |
+
continue;
|
403 |
+
|
404 |
+
$id = 'taxonomy-images-' . $taxonomy->name;
|
405 |
+
|
406 |
+
$checked = '';
|
407 |
+
if ( isset( $settings['taxonomies'] ) && in_array( $taxonomy->name, (array) $settings['taxonomies'] ) )
|
408 |
+
$checked = ' checked="checked"';
|
409 |
+
|
410 |
+
print "\n" . '<p><label for="' . esc_attr( $id ) . '">';
|
411 |
+
print '<input' . $checked . ' id="' . esc_attr( $id ) . '" type="checkbox" name="taxonomy_image_plugin_settings[taxonomies][]" value="' . esc_attr( $taxonomy->name ) . '">';
|
412 |
+
print ' ' . esc_html( $taxonomy->label ) . '</label></p>';
|
413 |
+
}
|
414 |
+
}
|
415 |
+
|
416 |
+
|
417 |
+
/**
|
418 |
+
* JSON Respose.
|
419 |
+
* Terminates script execution.
|
420 |
+
*
|
421 |
+
* @param array Associative array of values to be encoded in JSON.
|
422 |
+
*
|
423 |
+
* @access private
|
424 |
+
*/
|
425 |
+
function taxonomy_image_plugin_json_response( $args ) {
|
426 |
+
/* translators: An ajax request has failed for an unknown reason. */
|
427 |
+
$response = wp_parse_args( $args, array(
|
428 |
+
'status' => 'bad',
|
429 |
+
'why' => esc_html__( 'Unknown error encountered', 'taxonomy-images' )
|
430 |
+
) );
|
431 |
+
header( 'Content-type: application/jsonrequest' );
|
432 |
+
print json_encode( $response );
|
433 |
+
exit;
|
434 |
+
}
|
435 |
+
|
436 |
+
|
437 |
+
/**
|
438 |
+
* Get Term Info.
|
439 |
+
*
|
440 |
+
* Returns term info by term_taxonomy_id.
|
441 |
+
*
|
442 |
+
* @param int term_taxonomy_id
|
443 |
+
* @return array Keys: term_id (int) and taxonomy (string).
|
444 |
+
*
|
445 |
+
* @access private
|
446 |
+
*/
|
447 |
+
function taxonomy_image_plugin_get_term_info( $tt_id ) {
|
448 |
+
static $cache = array();
|
449 |
+
if ( isset( $cache[$tt_id] ) ) {
|
450 |
+
return $cache[$tt_id];
|
451 |
+
}
|
452 |
+
|
453 |
+
global $wpdb;
|
454 |
+
|
455 |
+
$data = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d LIMIT 1", $tt_id ) );
|
456 |
+
if ( isset( $data[0]->term_id ) )
|
457 |
+
$cache[$tt_id]['term_id'] = absint( $data[0]->term_id );
|
458 |
+
|
459 |
+
if ( isset( $data[0]->taxonomy ) )
|
460 |
+
$cache[$tt_id]['taxonomy'] = sanitize_title_with_dashes( $data[0]->taxonomy );
|
461 |
+
|
462 |
+
if ( isset( $cache[$tt_id] ) )
|
463 |
+
return $cache[$tt_id];
|
464 |
+
|
465 |
+
return array();
|
466 |
+
}
|
467 |
+
|
468 |
+
|
469 |
+
/**
|
470 |
+
* Check Taxonomy Permissions.
|
471 |
+
*
|
472 |
+
* Allows a permission check to be performed on a term
|
473 |
+
* when all you know is the term_taxonomy_id.
|
474 |
+
*
|
475 |
+
* @param int term_taxonomy_id
|
476 |
+
* @return bool True if user can edit terms, False if not.
|
477 |
+
*
|
478 |
+
* @access private
|
479 |
+
*/
|
480 |
+
function taxonomy_image_plugin_check_permissions( $tt_id ) {
|
481 |
+
$data = taxonomy_image_plugin_get_term_info( $tt_id );
|
482 |
+
if ( ! isset( $data['taxonomy'] ) )
|
483 |
+
return false;
|
484 |
+
|
485 |
+
$taxonomy = get_taxonomy( $data['taxonomy'] );
|
486 |
+
if ( ! isset( $taxonomy->cap->edit_terms ) )
|
487 |
+
return false;
|
488 |
+
|
489 |
+
return current_user_can( $taxonomy->cap->edit_terms );
|
490 |
+
}
|
491 |
+
|
492 |
+
|
493 |
+
/**
|
494 |
+
* Create an association.
|
495 |
+
*
|
496 |
+
* Callback for the wp_ajax_{$_GET['action']} hook.
|
497 |
+
*
|
498 |
+
* @access private
|
499 |
+
*/
|
500 |
+
function taxonomy_image_plugin_create_association() {
|
501 |
+
if ( ! isset( $_POST['tt_id'] ) ) {
|
502 |
+
taxonomy_image_plugin_json_response( array(
|
503 |
+
'status' => 'bad',
|
504 |
+
'why' => esc_html__( 'tt_id not sent', 'taxonomy-images' ),
|
505 |
+
) );
|
506 |
+
}
|
507 |
+
|
508 |
+
$tt_id = absint( $_POST['tt_id'] );
|
509 |
+
if ( empty( $tt_id ) ) {
|
510 |
+
taxonomy_image_plugin_json_response( array(
|
511 |
+
'status' => 'bad',
|
512 |
+
'why' => esc_html__( 'tt_id is empty', 'taxonomy-images' ),
|
513 |
+
) );
|
514 |
+
}
|
515 |
+
|
516 |
+
if ( ! taxonomy_image_plugin_check_permissions( $tt_id ) ) {
|
517 |
+
taxonomy_image_plugin_json_response( array(
|
518 |
+
'status' => 'bad',
|
519 |
+
'why' => esc_html__( 'You do not have the correct capability to manage this term', 'taxonomy-images' ),
|
520 |
+
) );
|
521 |
+
}
|
522 |
+
|
523 |
+
if ( ! isset( $_POST['wp_nonce'] ) ) {
|
524 |
+
taxonomy_image_plugin_json_response( array(
|
525 |
+
'status' => 'bad',
|
526 |
+
'why' => esc_html__( 'No nonce included.', 'taxonomy-images' ),
|
527 |
+
) );
|
528 |
+
}
|
529 |
+
|
530 |
+
if ( ! wp_verify_nonce( $_POST['wp_nonce'], 'taxonomy-image-plugin-create-association' ) ) {
|
531 |
+
taxonomy_image_plugin_json_response( array(
|
532 |
+
'status' => 'bad',
|
533 |
+
'why' => esc_html__( 'Nonce did not match', 'taxonomy-images' ),
|
534 |
+
) );
|
535 |
+
}
|
536 |
+
|
537 |
+
if ( ! isset( $_POST['attachment_id'] ) ) {
|
538 |
+
taxonomy_image_plugin_json_response( array(
|
539 |
+
'status' => 'bad',
|
540 |
+
'why' => esc_html__( 'Image id not sent', 'taxonomy-images' )
|
541 |
+
) );
|
542 |
+
}
|
543 |
+
|
544 |
+
$image_id = absint( $_POST['attachment_id'] );
|
545 |
+
if ( empty( $image_id ) ) {
|
546 |
+
taxonomy_image_plugin_json_response( array(
|
547 |
+
'status' => 'bad',
|
548 |
+
'why' => esc_html__( 'Image id is not a positive integer', 'taxonomy-images' )
|
549 |
+
) );
|
550 |
+
}
|
551 |
+
|
552 |
+
$assoc = taxonomy_image_plugin_get_associations();
|
553 |
+
$assoc[$tt_id] = $image_id;
|
554 |
+
if ( update_option( 'taxonomy_image_plugin', taxonomy_image_plugin_sanitize_associations( $assoc ) ) ) {
|
555 |
+
taxonomy_image_plugin_json_response( array(
|
556 |
+
'status' => 'good',
|
557 |
+
'why' => esc_html__( 'Image successfully associated', 'taxonomy-images' ),
|
558 |
+
'attachment_thumb_src' => taxonomy_image_plugin_get_image_src( $image_id )
|
559 |
+
) );
|
560 |
+
}
|
561 |
+
else {
|
562 |
+
taxonomy_image_plugin_json_response( array(
|
563 |
+
'status' => 'bad',
|
564 |
+
'why' => esc_html__( 'Association could not be created', 'taxonomy-images' )
|
565 |
+
) );
|
566 |
+
}
|
567 |
+
|
568 |
+
/* Don't know why, but something didn't work. */
|
569 |
+
taxonomy_image_plugin_json_response();
|
570 |
+
}
|
571 |
+
add_action( 'wp_ajax_taxonomy_image_create_association', 'taxonomy_image_plugin_create_association' );
|
572 |
+
|
573 |
+
|
574 |
+
/**
|
575 |
+
* Remove an association.
|
576 |
+
*
|
577 |
+
* Removes an association from the setting stored in the database.
|
578 |
+
* Print json encoded message and terminates script execution.
|
579 |
+
*
|
580 |
+
* @access private
|
581 |
+
*/
|
582 |
+
function taxonomy_image_plugin_remove_association() {
|
583 |
+
if ( ! isset( $_POST['tt_id'] ) ) {
|
584 |
+
taxonomy_image_plugin_json_response( array(
|
585 |
+
'status' => 'bad',
|
586 |
+
'why' => esc_html__( 'tt_id not sent', 'taxonomy-images' ),
|
587 |
+
) );
|
588 |
+
}
|
589 |
+
|
590 |
+
$tt_id = absint( $_POST['tt_id'] );
|
591 |
+
if ( empty( $tt_id ) ) {
|
592 |
+
taxonomy_image_plugin_json_response( array(
|
593 |
+
'status' => 'bad',
|
594 |
+
'why' => esc_html__( 'tt_id is empty', 'taxonomy-images' ),
|
595 |
+
) );
|
596 |
+
}
|
597 |
+
|
598 |
+
if ( ! taxonomy_image_plugin_check_permissions( $tt_id ) ) {
|
599 |
+
taxonomy_image_plugin_json_response( array(
|
600 |
+
'status' => 'bad',
|
601 |
+
'why' => esc_html__( 'You do not have the correct capability to manage this term', 'taxonomy-images' ),
|
602 |
+
) );
|
603 |
+
}
|
604 |
+
|
605 |
+
if ( ! isset( $_POST['wp_nonce'] ) ) {
|
606 |
+
taxonomy_image_plugin_json_response( array(
|
607 |
+
'status' => 'bad',
|
608 |
+
'why' => esc_html__( 'No nonce included', 'taxonomy-images' ),
|
609 |
+
) );
|
610 |
+
}
|
611 |
+
|
612 |
+
if ( ! wp_verify_nonce( $_POST['wp_nonce'], 'taxonomy-image-plugin-remove-association') ) {
|
613 |
+
taxonomy_image_plugin_json_response( array(
|
614 |
+
'status' => 'bad',
|
615 |
+
'why' => esc_html__( 'Nonce did not match', 'taxonomy-images' ),
|
616 |
+
) );
|
617 |
+
}
|
618 |
+
|
619 |
+
$assoc = taxonomy_image_plugin_get_associations();
|
620 |
+
if ( ! isset( $assoc[$tt_id] ) ) {
|
621 |
+
taxonomy_image_plugin_json_response( array(
|
622 |
+
'status' => 'good',
|
623 |
+
'why' => esc_html__( 'Nothing to remove', 'taxonomy-images' )
|
624 |
+
) );
|
625 |
+
}
|
626 |
+
|
627 |
+
unset( $assoc[$tt_id] );
|
628 |
+
|
629 |
+
if ( update_option( 'taxonomy_image_plugin', $assoc ) ) {
|
630 |
+
taxonomy_image_plugin_json_response( array(
|
631 |
+
'status' => 'good',
|
632 |
+
'why' => esc_html__( 'Association successfully removed', 'taxonomy-images' )
|
633 |
+
) );
|
634 |
+
}
|
635 |
+
else {
|
636 |
+
taxonomy_image_plugin_json_response( array(
|
637 |
+
'status' => 'bad',
|
638 |
+
'why' => esc_html__( 'Association could not be removed', 'taxonomy-images' )
|
639 |
+
) );
|
640 |
+
}
|
641 |
+
|
642 |
+
/* Don't know why, but something didn't work. */
|
643 |
+
taxonomy_image_plugin_json_response();
|
644 |
+
}
|
645 |
+
add_action( 'wp_ajax_taxonomy_image_plugin_remove_association', 'taxonomy_image_plugin_remove_association' );
|
646 |
+
|
647 |
+
|
648 |
+
/**
|
649 |
+
* Get a list of user-defined associations.
|
650 |
+
* Associations are stored in the WordPress options table.
|
651 |
+
*
|
652 |
+
* @param bool Should WordPress query the database for the results
|
653 |
+
* @return array List of associations. Key => taxonomy_term_id; Value => image_id
|
654 |
+
*
|
655 |
+
* @access private
|
656 |
+
*/
|
657 |
+
function taxonomy_image_plugin_get_associations( $refresh = false ) {
|
658 |
+
static $associations = array();
|
659 |
+
if ( empty( $associations ) || $refresh )
|
660 |
+
$associations = taxonomy_image_plugin_sanitize_associations( get_option( 'taxonomy_image_plugin' ) );
|
661 |
+
|
662 |
+
return $associations;
|
663 |
+
}
|
664 |
+
add_action( 'init', 'taxonomy_image_plugin_get_associations' );
|
665 |
+
|
666 |
+
|
667 |
+
/**
|
668 |
+
* Dynamically create hooks for each taxonomy.
|
669 |
+
*
|
670 |
+
* Adds hooks for each taxonomy that the user has given
|
671 |
+
* an image interface to via settings page. These hooks
|
672 |
+
* enable the image interface on wp-admin/edit-tags.php.
|
673 |
+
*
|
674 |
+
* @access private
|
675 |
+
* @since 0.4.3
|
676 |
+
* @alter 0.7
|
677 |
+
*/
|
678 |
+
function taxonomy_image_plugin_add_dynamic_hooks() {
|
679 |
+
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
680 |
+
if ( ! isset( $settings['taxonomies'] ) )
|
681 |
+
return;
|
682 |
+
|
683 |
+
foreach ( $settings['taxonomies'] as $taxonomy ) {
|
684 |
+
add_filter( 'manage_' . $taxonomy . '_custom_column', 'taxonomy_image_plugin_taxonomy_rows', 15, 3 );
|
685 |
+
add_filter( 'manage_edit-' . $taxonomy . '_columns', 'taxonomy_image_plugin_taxonomy_columns' );
|
686 |
+
add_action( $taxonomy . '_edit_form_fields', 'taxonomy_image_plugin_edit_tag_form', 10, 2 );
|
687 |
+
}
|
688 |
+
}
|
689 |
+
add_action( 'admin_init', 'taxonomy_image_plugin_add_dynamic_hooks' );
|
690 |
+
|
691 |
+
|
692 |
+
/**
|
693 |
+
* Edit Term Columns.
|
694 |
+
*
|
695 |
+
* Insert a new column on wp-admin/edit-tags.php.
|
696 |
+
*
|
697 |
+
* @see taxonomy_image_plugin_add_dynamic_hooks()
|
698 |
+
*
|
699 |
+
* @param array A list of columns.
|
700 |
+
* @return array List of columns with "Images" inserted after the checkbox.
|
701 |
+
*
|
702 |
+
* @access private
|
703 |
+
* @since 0.4.3
|
704 |
+
*/
|
705 |
+
function taxonomy_image_plugin_taxonomy_columns( $original_columns ) {
|
706 |
+
$new_columns = $original_columns;
|
707 |
+
array_splice( $new_columns, 1 );
|
708 |
+
$new_columns['taxonomy_image_plugin'] = esc_html__( 'Image', 'taxonomy-images' );
|
709 |
+
return array_merge( $new_columns, $original_columns );
|
710 |
+
}
|
711 |
+
|
712 |
+
|
713 |
+
/**
|
714 |
+
* Edit Term Rows.
|
715 |
+
*
|
716 |
+
* Create image control for each term row of wp-admin/edit-tags.php.
|
717 |
+
*
|
718 |
+
* @see taxonomy_image_plugin_add_dynamic_hooks()
|
719 |
+
*
|
720 |
+
* @param string Row.
|
721 |
+
* @param string Name of the current column.
|
722 |
+
* @param int Term ID.
|
723 |
+
* @return string @see taxonomy_image_plugin_control_image()
|
724 |
+
*
|
725 |
+
* @access private
|
726 |
+
* @since 2010-11-08
|
727 |
+
*/
|
728 |
+
function taxonomy_image_plugin_taxonomy_rows( $row, $column_name, $term_id ) {
|
729 |
+
if ( 'taxonomy_image_plugin' === $column_name ) {
|
730 |
+
global $taxonomy;
|
731 |
+
return $row . taxonomy_image_plugin_control_image( $term_id, $taxonomy );
|
732 |
+
}
|
733 |
+
return $row;
|
734 |
+
}
|
735 |
+
|
736 |
+
|
737 |
+
/**
|
738 |
+
* Edit Term Control.
|
739 |
+
*
|
740 |
+
* Create image control for wp-admin/edit-tag-form.php.
|
741 |
+
* Hooked into the '{$taxonomy}_edit_form_fields' action.
|
742 |
+
*
|
743 |
+
* @param stdClass Term object.
|
744 |
+
* @param string Taxonomy slug.
|
745 |
+
*
|
746 |
+
* @access private
|
747 |
+
* @since 2010-11-08
|
748 |
+
*/
|
749 |
+
function taxonomy_image_plugin_edit_tag_form( $term, $taxonomy ) {
|
750 |
+
$taxonomy = get_taxonomy( $taxonomy );
|
751 |
+
$name = __( 'term', 'taxonomy-images' );
|
752 |
+
if ( isset( $taxonomy->labels->singular_name ) )
|
753 |
+
$name = strtolower( $taxonomy->labels->singular_name );
|
754 |
+
?>
|
755 |
+
<tr class="form-field hide-if-no-js">
|
756 |
+
<th scope="row" valign="top"><label for="description"><?php print esc_html__( 'Image', 'taxonomy-images' ) ?></label></th>
|
757 |
+
<td>
|
758 |
+
<?php print taxonomy_image_plugin_control_image( $term->term_id, $taxonomy->name ); ?>
|
759 |
+
<div class="clear"></div>
|
760 |
+
<span class="description"><?php printf( esc_html__( 'Associate an image from your media library to this %1$s.', 'taxonomy-images' ), esc_html( $name ) ); ?></span>
|
761 |
+
</td>
|
762 |
+
</tr>
|
763 |
+
<?php
|
764 |
+
}
|
765 |
+
|
766 |
+
/**
|
767 |
+
* Image Control.
|
768 |
+
*
|
769 |
+
* Creates all image controls on edit-tags.php.
|
770 |
+
*
|
771 |
+
* @todo Remove rel tag from link... will need to adjust js to accomodate.
|
772 |
+
* @since 0.7
|
773 |
+
* @access private
|
774 |
+
*/
|
775 |
+
function taxonomy_image_plugin_control_image( $term_id, $taxonomy ) {
|
776 |
+
|
777 |
+
$term = get_term( $term_id, $taxonomy );
|
778 |
+
|
779 |
+
$tt_id = 0;
|
780 |
+
if ( isset( $term->term_taxonomy_id ) )
|
781 |
+
$tt_id = (int) $term->term_taxonomy_id;
|
782 |
+
|
783 |
+
$taxonomy = get_taxonomy( $taxonomy );
|
784 |
+
|
785 |
+
$name = esc_html__( 'term', 'taxonomy-images' );
|
786 |
+
if ( isset( $taxonomy->labels->singular_name ) )
|
787 |
+
$name = strtolower( $taxonomy->labels->singular_name );
|
788 |
+
|
789 |
+
$hide = ' hide';
|
790 |
+
$attachment_id = 0;
|
791 |
+
$associations = taxonomy_image_plugin_get_associations();
|
792 |
+
if ( isset( $associations[ $tt_id ] ) ) {
|
793 |
+
$attachment_id = (int) $associations[ $tt_id ];
|
794 |
+
$hide = '';
|
795 |
+
}
|
796 |
+
|
797 |
+
$img = taxonomy_image_plugin_get_image_src( $attachment_id );
|
798 |
+
|
799 |
+
$term = get_term( $term_id, $taxonomy->name );
|
800 |
+
|
801 |
+
$o = "\n" . '<div id="' . esc_attr( 'taxonomy-image-control-' . $tt_id ) . '" class="taxonomy-image-control hide-if-no-js">';
|
802 |
+
$o.= "\n" . '<a class="thickbox taxonomy-image-thumbnail" href="' . esc_url( admin_url( 'media-upload.php' ) . '?type=image&tab=library&post_id=0&TB_iframe=true' ) . '" title="' . esc_attr( sprintf( __( 'Associate an image with the %1$s named “%2$s”.', 'taxonomy-images' ), $name, $term->name ) ) . '"><img id="' . esc_attr( 'taxonomy_image_plugin_' . $tt_id ) . '" src="' . esc_url( $img ) . '" alt="" /></a>';
|
803 |
+
$o.= "\n" . '<a class="control upload thickbox" href="' . esc_url( admin_url( 'media-upload.php' ) . '?type=image&tab=type&post_id=0&TB_iframe=true' ) . '" title="' . esc_attr( sprintf( __( 'Upload a new image for this %s.', 'taxonomy-images' ), $name ) ) . '">' . esc_html__( 'Upload.', 'taxonomy-images' ) . '</a>';
|
804 |
+
$o.= "\n" . '<a class="control remove' . $hide . '" href="#" id="' . esc_attr( 'remove-' . $tt_id ) . '" rel="' . esc_attr( $tt_id ) . '" title="' . esc_attr( sprintf( __( 'Remove image from this %s.', 'taxonomy-images' ), $name ) ) . '">' . esc_html__( 'Delete', 'taxonomy-images' ) . '</a>';
|
805 |
+
$o.= "\n" . '<input type="hidden" class="tt_id" name="' . esc_attr( 'tt_id-' . $tt_id ) . '" value="' . esc_attr( $tt_id ) . '" />';
|
806 |
+
|
807 |
+
$o.= "\n" . '<input type="hidden" class="image_id" name="' . esc_attr( 'image_id-' . $tt_id ) . '" value="' . esc_attr( $attachment_id ) . '" />';
|
808 |
+
|
809 |
+
if ( isset( $term->name ) && isset( $term->slug ) )
|
810 |
+
$o.= "\n" . '<input type="hidden" class="term_name" name="' . esc_attr( 'term_name-' . $term->slug ) . '" value="' . esc_attr( $term->name ) . '" />';
|
811 |
+
|
812 |
+
$o.= "\n" . '</div>';
|
813 |
+
return $o;
|
814 |
+
}
|
815 |
+
|
816 |
+
|
817 |
+
/**
|
818 |
+
* Custom javascript for modal media box.
|
819 |
+
*
|
820 |
+
* This script need to be added to all instance of the media upload box.
|
821 |
+
*
|
822 |
+
* @access private
|
823 |
+
*/
|
824 |
+
function taxonomy_image_plugin_media_upload_popup_js() {
|
825 |
+
wp_enqueue_script(
|
826 |
+
'taxonomy-images-media-upload-popup',
|
827 |
+
taxonomy_image_plugin_url( 'media-upload-popup.js' ),
|
828 |
+
array( 'jquery' ),
|
829 |
+
taxonomy_image_plugin_version()
|
830 |
+
);
|
831 |
+
wp_localize_script( 'taxonomy-images-media-upload-popup', 'TaxonomyImagesModal', array (
|
832 |
+
'termBefore' => esc_html__( '“', 'taxonomy-images' ),
|
833 |
+
'termAfter' => esc_html__( '”', 'taxonomy-images' ),
|
834 |
+
'associating' => esc_html__( 'Associating …', 'taxonomy-images' ),
|
835 |
+
'success' => esc_html__( 'Successfully Associated', 'taxonomy-images' ),
|
836 |
+
'removing' => esc_html__( 'Removing …', 'taxonomy-images' ),
|
837 |
+
'removed' => esc_html__( 'Successfully Removed', 'taxonomy-images' )
|
838 |
+
) );
|
839 |
+
}
|
840 |
+
add_action( 'admin_print_scripts-media-upload-popup', 'taxonomy_image_plugin_media_upload_popup_js' );
|
841 |
+
|
842 |
+
|
843 |
+
/**
|
844 |
+
* Custom javascript for wp-admin/edit-tags.php.
|
845 |
+
*
|
846 |
+
* @access private
|
847 |
+
*/
|
848 |
+
function taxonomy_image_plugin_edit_tags_js() {
|
849 |
+
if ( false == taxonomy_image_plugin_is_screen_active() )
|
850 |
+
return;
|
851 |
+
|
852 |
+
wp_enqueue_script(
|
853 |
+
'taxonomy-image-plugin-edit-tags',
|
854 |
+
taxonomy_image_plugin_url( 'edit-tags.js' ),
|
855 |
+
array( 'jquery', 'thickbox' ),
|
856 |
+
taxonomy_image_plugin_version()
|
857 |
+
);
|
858 |
+
wp_localize_script( 'taxonomy-image-plugin-edit-tags', 'taxonomyImagesPlugin', array (
|
859 |
+
'nonce' => wp_create_nonce( 'taxonomy-image-plugin-remove-association' ),
|
860 |
+
'img_src' => taxonomy_image_plugin_url( 'default.png' ),
|
861 |
+
'tt_id' => 0,
|
862 |
+
'image_id' => 0,
|
863 |
+
) );
|
864 |
+
}
|
865 |
+
add_action( 'admin_print_scripts-edit-tags.php', 'taxonomy_image_plugin_edit_tags_js' );
|
866 |
+
|
867 |
+
|
868 |
+
/**
|
869 |
+
* Custom styles.
|
870 |
+
*
|
871 |
+
* @since 0.7
|
872 |
+
* @access private
|
873 |
+
*/
|
874 |
+
function taxonomy_image_plugin_css_admin() {
|
875 |
+
if ( false == taxonomy_image_plugin_is_screen_active() && 'admin_print_styles-media-upload-popup' != current_filter() )
|
876 |
+
return;
|
877 |
+
|
878 |
+
wp_enqueue_style(
|
879 |
+
'taxonomy-image-plugin-edit-tags',
|
880 |
+
taxonomy_image_plugin_url( 'admin.css' ),
|
881 |
+
array(),
|
882 |
+
taxonomy_image_plugin_version(),
|
883 |
+
'screen'
|
884 |
+
);
|
885 |
+
}
|
886 |
+
add_action( 'admin_print_styles-edit-tags.php', 'taxonomy_image_plugin_css_admin' );
|
887 |
+
add_action( 'admin_print_styles-media-upload-popup', 'taxonomy_image_plugin_css_admin' );
|
888 |
+
|
889 |
+
|
890 |
+
/**
|
891 |
+
* Thickbox styles.
|
892 |
+
*
|
893 |
+
* @since 0.7
|
894 |
+
* @access private
|
895 |
+
*/
|
896 |
+
function taxonomy_image_plugin_css_thickbox() {
|
897 |
+
if ( false == taxonomy_image_plugin_is_screen_active() )
|
898 |
+
return;
|
899 |
+
|
900 |
+
wp_enqueue_style( 'thickbox' );
|
901 |
+
}
|
902 |
+
add_action( 'admin_print_styles-edit-tags.php', 'taxonomy_image_plugin_css_thickbox' );
|
903 |
+
|
904 |
+
|
905 |
+
/**
|
906 |
+
* Public Styles.
|
907 |
+
*
|
908 |
+
* Prints custom css to all public pages. If you do not
|
909 |
+
* wish to have these styles included for you, please
|
910 |
+
* insert the following code into your theme's functions.php
|
911 |
+
* file:
|
912 |
+
*
|
913 |
+
* add_filter( 'taxonomy-images-disable-public-css', '__return_true' );
|
914 |
+
*
|
915 |
+
* @since 0.7
|
916 |
+
* @access private
|
917 |
+
*/
|
918 |
+
function taxonomy_image_plugin_css_public() {
|
919 |
+
if ( apply_filters( 'taxonomy-images-disable-public-css', false ) )
|
920 |
+
return;
|
921 |
+
|
922 |
+
wp_enqueue_style(
|
923 |
+
'taxonomy-image-plugin-public',
|
924 |
+
taxonomy_image_plugin_url( 'style.css' ),
|
925 |
+
array(),
|
926 |
+
taxonomy_image_plugin_version(),
|
927 |
+
'screen'
|
928 |
+
);
|
929 |
+
}
|
930 |
+
add_action( 'wp_print_styles', 'taxonomy_image_plugin_css_public' );
|
931 |
+
|
932 |
+
|
933 |
+
/**
|
934 |
+
* Activation.
|
935 |
+
*
|
936 |
+
* Two entries in the options table will created when this
|
937 |
+
* plugin is activated in the event that they do not exist.
|
938 |
+
*
|
939 |
+
* 'taxonomy_image_plugin' (array) A flat list of all assocaitions
|
940 |
+
* made by this plugin. Keys are integers representing the
|
941 |
+
* term_taxonomy_id of terms. Values are integers representing the
|
942 |
+
* ID property of an image attachment.
|
943 |
+
*
|
944 |
+
* 'taxonomy_image_plugin_settings' (array) A multi-dimensional array
|
945 |
+
* of user-defined settings. As of version 0.7, only one key is used:
|
946 |
+
* 'taxonomies' which is a whitelist of registered taxonomies having ui
|
947 |
+
* that support the custom image ui provided by this plugin.
|
948 |
+
*
|
949 |
+
* @access private
|
950 |
+
* @alter 0.7
|
951 |
+
*/
|
952 |
+
function taxonomy_image_plugin_activate() {
|
953 |
+
$associations = get_option( 'taxonomy_image_plugin' );
|
954 |
+
if ( false === $associations )
|
955 |
+
add_option( 'taxonomy_image_plugin', array() );
|
956 |
+
|
957 |
+
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
958 |
+
if ( false === $settings ) {
|
959 |
+
add_option( 'taxonomy_image_plugin_settings', array(
|
960 |
+
'taxonomies' => array()
|
961 |
+
) );
|
962 |
+
}
|
963 |
+
}
|
964 |
+
register_activation_hook( __FILE__, 'taxonomy_image_plugin_activate' );
|
965 |
+
|
966 |
+
|
967 |
+
/**
|
968 |
+
* Is Screen Active?
|
969 |
+
*
|
970 |
+
* @return bool
|
971 |
+
*
|
972 |
+
* @access private
|
973 |
+
* @since 0.7
|
974 |
+
*/
|
975 |
+
function taxonomy_image_plugin_is_screen_active() {
|
976 |
+
$screen = get_current_screen();
|
977 |
+
if ( ! isset( $screen->taxonomy ) )
|
978 |
+
return false;
|
979 |
+
|
980 |
+
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
981 |
+
if ( ! isset( $settings['taxonomies'] ) )
|
982 |
+
return false;
|
983 |
+
|
984 |
+
if ( in_array( $screen->taxonomy, $settings['taxonomies'] ) )
|
985 |
+
return true;
|
986 |
+
|
987 |
+
return false;
|
988 |
+
}
|
989 |
+
|
990 |
+
|
991 |
+
/**
|
992 |
+
* Cache Images
|
993 |
+
*
|
994 |
+
* Sets the WordPress object cache for all term images
|
995 |
+
* associated to the posts in the provided array. This
|
996 |
+
* function has been created to minimize queries when
|
997 |
+
* using this plugins get_the_terms() style function.
|
998 |
+
*
|
999 |
+
* @param array Post objects.
|
1000 |
+
*
|
1001 |
+
* @access private
|
1002 |
+
* @since 1.1
|
1003 |
+
*/
|
1004 |
+
function taxonomy_image_plugin_cache_images( $posts ) {
|
1005 |
+
$assoc = taxonomy_image_plugin_get_associations();
|
1006 |
+
if ( empty( $assoc ) )
|
1007 |
+
return;
|
1008 |
+
|
1009 |
+
$tt_ids = array();
|
1010 |
+
foreach ( (array) $posts as $post ) {
|
1011 |
+
if ( ! isset( $post->ID ) || ! isset( $post->post_type ) )
|
1012 |
+
continue;
|
1013 |
+
|
1014 |
+
$taxonomies = get_object_taxonomies( $post->post_type );
|
1015 |
+
if ( empty( $taxonomies ) )
|
1016 |
+
continue;
|
1017 |
+
|
1018 |
+
foreach ( $taxonomies as $taxonomy ) {
|
1019 |
+
$the_terms = get_the_terms( $post->ID, $taxonomy );
|
1020 |
+
foreach ( (array) $the_terms as $term ) {
|
1021 |
+
if ( ! isset( $term->term_taxonomy_id ) ) {
|
1022 |
+
continue;
|
1023 |
+
}
|
1024 |
+
$tt_ids[] = $term->term_taxonomy_id;
|
1025 |
+
}
|
1026 |
+
}
|
1027 |
+
}
|
1028 |
+
$tt_ids = array_filter( array_unique( $tt_ids ) );
|
1029 |
+
|
1030 |
+
$image_ids = array();
|
1031 |
+
foreach ( $tt_ids as $tt_id ) {
|
1032 |
+
if ( ! isset( $assoc[$tt_id] ) )
|
1033 |
+
continue;
|
1034 |
+
|
1035 |
+
if ( in_array( $assoc[$tt_id], $image_ids ) )
|
1036 |
+
continue;
|
1037 |
+
|
1038 |
+
$image_ids[] = $assoc[$tt_id];
|
1039 |
+
}
|
1040 |
+
|
1041 |
+
if ( empty( $image_ids ) )
|
1042 |
+
return;
|
1043 |
+
|
1044 |
+
$images = get_posts( array(
|
1045 |
+
'include' => $image_ids,
|
1046 |
+
'post_type' => 'attachment'
|
1047 |
+
) );
|
1048 |
+
}
|
1049 |
+
|
1050 |
+
|
1051 |
+
/**
|
1052 |
+
* Cache Images
|
1053 |
+
*
|
1054 |
+
* Cache all term images associated with posts in
|
1055 |
+
* the main WordPress query.
|
1056 |
+
*
|
1057 |
+
* @param array Post objects.
|
1058 |
+
*
|
1059 |
+
* @access private
|
1060 |
+
* @since 0.7
|
1061 |
+
*/
|
1062 |
+
function taxonomy_image_plugin_cache_queried_images() {
|
1063 |
+
global $posts;
|
1064 |
+
taxonomy_image_plugin_cache_images( $posts );
|
1065 |
+
}
|
1066 |
+
add_action( 'template_redirect', 'taxonomy_image_plugin_cache_queried_images' );
|
1067 |
+
|
1068 |
+
|
1069 |
+
/**
|
1070 |
+
* Check Taxonomy
|
1071 |
+
*
|
1072 |
+
* Wrapper for WordPress core functions taxonomy_exists().
|
1073 |
+
* In the event that an unregistered taxonomy is passed a
|
1074 |
+
* E_USER_NOTICE will be generated.
|
1075 |
+
*
|
1076 |
+
* @param string Taxonomy name as registered with WordPress.
|
1077 |
+
* @param string Name of the current function or filter.
|
1078 |
+
* @return bool True if taxonomy exists, False if not.
|
1079 |
+
*
|
1080 |
+
* @access private
|
1081 |
+
* @since 0.7
|
1082 |
+
*/
|
1083 |
+
function taxonomy_image_plugin_check_taxonomy( $taxonomy, $filter ) {
|
1084 |
+
if ( ! taxonomy_exists( $taxonomy ) ) {
|
1085 |
+
trigger_error( sprintf( esc_html__( 'The %1$s argument for %2$s is set to %3$s which is not a registered taxonomy. Please check the spelling and update the argument.', 'taxonomy-images' ),
|
1086 |
+
'<var>' . esc_html__( 'taxonomy', 'taxonomy-images' ) . '</var>',
|
1087 |
+
'<code>' . esc_html( $filter ) . '</code>',
|
1088 |
+
'<strong>' . esc_html( $taxonomy ) . '</strong>'
|
1089 |
+
) );
|
1090 |
+
return false;
|
1091 |
+
}
|
1092 |
+
|
1093 |
+
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
1094 |
+
|
1095 |
+
if ( ! isset( $settings['taxonomies'] ) ) {
|
1096 |
+
trigger_error( sprintf( esc_html__( 'No taxonomies have image support. %1$s', 'taxonomy-images' ), taxonomy_images_plugin_settings_page_link() ) );
|
1097 |
+
return false;
|
1098 |
+
}
|
1099 |
+
|
1100 |
+
if ( ! in_array( $taxonomy, (array) $settings['taxonomies'] ) ) {
|
1101 |
+
trigger_error( sprintf( esc_html__( 'The %1$s taxonomy does not have image support. %2$s', 'taxonomy-images' ),
|
1102 |
+
'<strong>' . esc_html( $taxonomy ) . '</strong>',
|
1103 |
+
taxonomy_images_plugin_settings_page_link()
|
1104 |
+
) );
|
1105 |
+
return false;
|
1106 |
+
}
|
1107 |
+
|
1108 |
+
return true;
|
1109 |
+
}
|
1110 |
+
|
1111 |
+
|
1112 |
+
/**
|
1113 |
+
* Please Use Filter.
|
1114 |
+
*
|
1115 |
+
* Report to user that they are directly calling a function
|
1116 |
+
* instead of using supported filters. A E_USER_NOTICE will
|
1117 |
+
* be generated.
|
1118 |
+
*
|
1119 |
+
* @param string Name of function called.
|
1120 |
+
* @param string Name of filter to use instead.
|
1121 |
+
*
|
1122 |
+
* @access private
|
1123 |
+
* @since 0.7
|
1124 |
+
*/
|
1125 |
+
function taxonomy_image_plugin_please_use_filter( $function, $filter ) {
|
1126 |
+
trigger_error( sprintf( esc_html__( 'The %1$s has been called directly. Please use the %2$s filter instead.', 'taxonomy-images' ),
|
1127 |
+
'<code>' . esc_html( $function . '()' ) . '</code>',
|
1128 |
+
'<code>' . esc_html( $filter ) . '</code>'
|
1129 |
+
) );
|
1130 |
+
}
|
1131 |
+
|
1132 |
+
|
1133 |
+
/**
|
1134 |
+
* Plugin Meta Links.
|
1135 |
+
*
|
1136 |
+
* Add a link to this plugin's setting page when it
|
1137 |
+
* displays in the table on wp-admin/plugins.php.
|
1138 |
+
*
|
1139 |
+
* @param array List of links.
|
1140 |
+
* @param string Current plugin being displayed in plugins.php.
|
1141 |
+
* @return array Potentially modified list of links.
|
1142 |
+
*
|
1143 |
+
* @access private
|
1144 |
+
* @since 0.7
|
1145 |
+
*/
|
1146 |
+
function taxonomy_images_plugin_row_meta( $links, $file ) {
|
1147 |
+
static $plugin_name = '';
|
1148 |
+
|
1149 |
+
if ( empty( $plugin_name ) )
|
1150 |
+
$plugin_name = plugin_basename( __FILE__ );
|
1151 |
+
|
1152 |
+
if ( $plugin_name != $file )
|
1153 |
+
return $links;
|
1154 |
+
|
1155 |
+
$link = taxonomy_images_plugin_settings_page_link( __( 'Settings', 'taxonomy-images' ) );
|
1156 |
+
if ( ! empty( $link ) )
|
1157 |
+
$links[] = $link;
|
1158 |
+
|
1159 |
+
$links[] = '<a href="http://wordpress.mfields.org/donate/">' . __( 'Donate', 'taxonomy-images' ) . '</a>';
|
1160 |
+
|
1161 |
+
return $links;
|
1162 |
+
}
|
1163 |
+
add_filter( 'plugin_row_meta', 'taxonomy_images_plugin_row_meta', 10, 2 );
|
1164 |
+
|
1165 |
+
|
1166 |
+
/**
|
1167 |
+
* Settings Page Link.
|
1168 |
+
*
|
1169 |
+
* @param array Localized link text.
|
1170 |
+
* @return string HTML link to settings page.
|
1171 |
+
*
|
1172 |
+
* @access private
|
1173 |
+
* @since 0.7
|
1174 |
+
*/
|
1175 |
+
function taxonomy_images_plugin_settings_page_link( $link_text = '' ) {
|
1176 |
+
if ( empty( $link_text ) )
|
1177 |
+
$link_text = __( 'Manage Settings', 'taxonomy-images' );
|
1178 |
+
|
1179 |
+
$link = '';
|
1180 |
+
if ( current_user_can( 'manage_options' ) )
|
1181 |
+
$link = '<a href="' . esc_url( add_query_arg( array( 'page' => 'taxonomy_image_plugin_settings' ), admin_url( 'options-general.php' ) ) ) . '">' . esc_html( $link_text ) . '</a>';
|
1182 |
+
|
1183 |
+
return $link;
|
1184 |
+
}
|