Version Description
Fixed full image size sometimes not being returned. Prepare plugin structure for term meta compatibility.
Download this release
Release Info
Developer | husobj |
Plugin | Taxonomy Images |
Version | 1.0 |
Comparing to | |
See all releases |
Code changes from version 0.9.7 to 1.0
- CHANGELOG.md +11 -1
- README.md +7 -1
- controls.png +0 -0
- css/admin.css +47 -22
- blank.png → images/blank.png +0 -0
- default.png → images/default.png +0 -0
- code-snippets.php → legacy/includes/code-snippets.php +0 -0
- legacy/includes/config.php +164 -0
- deprecated.php → legacy/includes/deprecated.php +110 -9
- legacy/includes/functions.php +1077 -0
- public-filters.php → legacy/includes/public-filters.php +88 -41
- legacy/includes/term.php +284 -0
- legacy/plugin.php +78 -0
- plugin/assets/css/admin.css +77 -0
- plugin/assets/css/theme.css +28 -0
- plugin/assets/images/blank.png +0 -0
- plugin/assets/images/default.png +0 -0
- plugin/assets/js/media-modal.js +165 -0
- plugin/includes/cache-class.php +145 -0
- plugin/includes/image-admin-ajax-class.php +266 -0
- plugin/includes/image-type-class.php +133 -0
- plugin/includes/image-types-class.php +121 -0
- plugin/includes/legacy-class.php +25 -0
- plugin/includes/legacy-hooks.php +608 -0
- plugin/includes/settings-admin-class.php +224 -0
- plugin/includes/supported-class.php +68 -0
- plugin/includes/term-image-admin-control-class.php +220 -0
- plugin/includes/term-image-class.php +199 -0
- plugin/includes/terms-admin-class.php +222 -0
- plugin/includes/theme-class.php +42 -0
- plugin/includes/upgrade-class.php +55 -0
- plugin/plugin.php +349 -0
- readme.txt +21 -4
- taxonomy-images.php +11 -1225
CHANGELOG.md
CHANGED
@@ -4,6 +4,15 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4 |
|
5 |
## [Unreleased]
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
## [0.9.7] - 2017-02-16
|
8 |
|
9 |
### Changed
|
@@ -214,7 +223,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
214 |
### Added
|
215 |
- Original Release - Works with WordPress 2.9.1.
|
216 |
|
217 |
-
[Unreleased]: https://github.com/benhuson/Taxonomy-Images/compare/0
|
|
|
218 |
[0.9.7]: https://github.com/benhuson/Taxonomy-Images/compare/0.9.6...0.9.7
|
219 |
[0.9.6]: https://github.com/benhuson/Taxonomy-Images/compare/0.9.5...0.9.6
|
220 |
[0.9.5]: https://github.com/benhuson/Taxonomy-Images/compare/0.9.4...0.9.5
|
4 |
|
5 |
## [Unreleased]
|
6 |
|
7 |
+
## [1.0] - 2019-06-20
|
8 |
+
|
9 |
+
### Fixed
|
10 |
+
- Fixed full image size sometimes not being returned.
|
11 |
+
|
12 |
+
### Changed
|
13 |
+
- Control, blank and default images moves to `images` folder.
|
14 |
+
- Prepare plugin structure for term meta compatibility.
|
15 |
+
|
16 |
## [0.9.7] - 2017-02-16
|
17 |
|
18 |
### Changed
|
223 |
### Added
|
224 |
- Original Release - Works with WordPress 2.9.1.
|
225 |
|
226 |
+
[Unreleased]: https://github.com/benhuson/Taxonomy-Images/compare/1.0...HEAD
|
227 |
+
[1.0]: https://github.com/benhuson/Taxonomy-Images/compare/0.9.7...1.0
|
228 |
[0.9.7]: https://github.com/benhuson/Taxonomy-Images/compare/0.9.6...0.9.7
|
229 |
[0.9.6]: https://github.com/benhuson/Taxonomy-Images/compare/0.9.5...0.9.6
|
230 |
[0.9.5]: https://github.com/benhuson/Taxonomy-Images/compare/0.9.4...0.9.5
|
README.md
CHANGED
@@ -175,7 +175,7 @@ $terms = apply_filters( 'taxonomy-images-get-terms', '' );
|
|
175 |
if ( ! empty( $terms ) ) {
|
176 |
print '<ul>';
|
177 |
foreach ( (array) $terms as $term ) {
|
178 |
-
print '<li><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'detail' ) . '</li>';
|
179 |
}
|
180 |
print '</ul>';
|
181 |
}
|
@@ -221,6 +221,12 @@ Installation
|
|
221 |
Upgrade Notice
|
222 |
--------------
|
223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
### 0.9.6
|
225 |
Fixed issue where if no terms have images but 'having_images' is false, nothing would be returned (props Matt).
|
226 |
|
175 |
if ( ! empty( $terms ) ) {
|
176 |
print '<ul>';
|
177 |
foreach ( (array) $terms as $term ) {
|
178 |
+
print '<li><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'detail' ) . '</a></li>';
|
179 |
}
|
180 |
print '</ul>';
|
181 |
}
|
221 |
Upgrade Notice
|
222 |
--------------
|
223 |
|
224 |
+
### 1.0
|
225 |
+
Fixed full image size sometimes not being returned. Prepare plugin structure for term meta compatibility.
|
226 |
+
|
227 |
+
### 0.9.7
|
228 |
+
Remove use of deprecated `image_resize` function. Bump minimum WordPress version to 3.5.
|
229 |
+
|
230 |
### 0.9.6
|
231 |
Fixed issue where if no terms have images but 'having_images' is false, nothing would be returned (props Matt).
|
232 |
|
controls.png
DELETED
Binary file
|
css/admin.css
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
|
|
|
|
|
2 |
.taxonomy-images-modal .create-association .term-name {
|
3 |
font-style: italic;
|
4 |
}
|
@@ -19,6 +21,12 @@
|
|
19 |
display: none !important;
|
20 |
}
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
.taxonomy-image-thumbnail {
|
23 |
display: block;
|
24 |
margin-bottom: 3px;
|
@@ -33,38 +41,59 @@
|
|
33 |
height: 75px;
|
34 |
}
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
.taxonomy-image-control .control {
|
37 |
-
background:
|
38 |
-
|
|
|
39 |
display: block;
|
40 |
float: left;
|
|
|
|
|
|
|
41 |
text-indent: -9999em;
|
42 |
-
width:
|
43 |
-
height:
|
44 |
}
|
45 |
|
46 |
-
.taxonomy-image-control .
|
47 |
-
|
48 |
-
}
|
49 |
-
|
50 |
-
.taxonomy-image-control .upload {
|
51 |
-
background-position: 0 0;
|
52 |
}
|
53 |
|
54 |
-
.taxonomy-image-control .
|
55 |
-
background-
|
56 |
}
|
57 |
|
58 |
-
.taxonomy-image-control .
|
59 |
-
|
|
|
|
|
|
|
|
|
60 |
}
|
61 |
|
62 |
-
.taxonomy-image-control .
|
63 |
-
|
|
|
|
|
|
|
|
|
64 |
}
|
65 |
|
66 |
-
.taxonomy-image-control .
|
67 |
-
|
|
|
|
|
|
|
68 |
}
|
69 |
|
70 |
.taxonomy-image-control .hide {
|
@@ -74,7 +103,3 @@
|
|
74 |
.taxonomy-image-control .show {
|
75 |
visibility: visible;
|
76 |
}
|
77 |
-
|
78 |
-
body.taxonomy-images-modal {
|
79 |
-
background: #f1f1f1 !important;
|
80 |
-
}
|
1 |
|
2 |
+
/* Modal */
|
3 |
+
|
4 |
.taxonomy-images-modal .create-association .term-name {
|
5 |
font-style: italic;
|
6 |
}
|
21 |
display: none !important;
|
22 |
}
|
23 |
|
24 |
+
body.taxonomy-images-modal {
|
25 |
+
background: #f1f1f1 !important;
|
26 |
+
}
|
27 |
+
|
28 |
+
/* Thumbnail */
|
29 |
+
|
30 |
.taxonomy-image-thumbnail {
|
31 |
display: block;
|
32 |
margin-bottom: 3px;
|
41 |
height: 75px;
|
42 |
}
|
43 |
|
44 |
+
.taxonomy-image-thumbnail-large {
|
45 |
+
width: 120px;
|
46 |
+
height: 120px;
|
47 |
+
}
|
48 |
+
|
49 |
+
.taxonomy-image-thumbnail-large img {
|
50 |
+
width: 120px;
|
51 |
+
height: 120px;
|
52 |
+
}
|
53 |
+
|
54 |
.taxonomy-image-control .control {
|
55 |
+
background-color: #b3b9bf;
|
56 |
+
border-radius: 50%;
|
57 |
+
cursor: pointer;
|
58 |
display: block;
|
59 |
float: left;
|
60 |
+
margin: 0 3px 3px 0;
|
61 |
+
overflow: hidden;
|
62 |
+
position: relative;
|
63 |
text-indent: -9999em;
|
64 |
+
width: 12px;
|
65 |
+
height: 12px;
|
66 |
}
|
67 |
|
68 |
+
.taxonomy-image-control .upload:hover {
|
69 |
+
background-color: #00a2d7;
|
|
|
|
|
|
|
|
|
70 |
}
|
71 |
|
72 |
+
.taxonomy-image-control .remove:hover {
|
73 |
+
background-color: #d00;
|
74 |
}
|
75 |
|
76 |
+
.taxonomy-image-control .upload::before,
|
77 |
+
.taxonomy-image-control .remove::before,
|
78 |
+
.taxonomy-image-control .upload::after {
|
79 |
+
display: block;
|
80 |
+
content: ' ';
|
81 |
+
position: absolute;
|
82 |
}
|
83 |
|
84 |
+
.taxonomy-image-control .upload::before,
|
85 |
+
.taxonomy-image-control .remove::before {
|
86 |
+
border-top: 2px solid #fff;
|
87 |
+
width: 8px;
|
88 |
+
top: 5px;
|
89 |
+
left: 2px;
|
90 |
}
|
91 |
|
92 |
+
.taxonomy-image-control .upload::after {
|
93 |
+
border-left: 2px solid #fff;
|
94 |
+
height: 8px;
|
95 |
+
top: 2px;
|
96 |
+
left: 5px;
|
97 |
}
|
98 |
|
99 |
.taxonomy-image-control .hide {
|
103 |
.taxonomy-image-control .show {
|
104 |
visibility: visible;
|
105 |
}
|
|
|
|
|
|
|
|
blank.png → images/blank.png
RENAMED
File without changes
|
default.png → images/default.png
RENAMED
File without changes
|
code-snippets.php → legacy/includes/code-snippets.php
RENAMED
File without changes
|
legacy/includes/config.php
ADDED
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Config Class
|
5 |
+
*/
|
6 |
+
class Taxonomy_Images_Config {
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Plugin File
|
10 |
+
*
|
11 |
+
* @var string
|
12 |
+
*/
|
13 |
+
private static $plugin_file = __FILE__;
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Version
|
17 |
+
*
|
18 |
+
* @var string
|
19 |
+
*/
|
20 |
+
private static $version = '';
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Basename
|
24 |
+
*
|
25 |
+
* @var string
|
26 |
+
*/
|
27 |
+
private static $basename = null;
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Dirname
|
31 |
+
*
|
32 |
+
* @var string
|
33 |
+
*/
|
34 |
+
private static $dirname = null;
|
35 |
+
|
36 |
+
/**
|
37 |
+
* URL
|
38 |
+
*
|
39 |
+
* @var string
|
40 |
+
*/
|
41 |
+
private static $url = null;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Set Plugin File
|
45 |
+
*
|
46 |
+
* @param string $plugin_file The full path and filename of the main plugin file.
|
47 |
+
*/
|
48 |
+
public static function set_plugin_file( $plugin_file ) {
|
49 |
+
|
50 |
+
self::$plugin_file = $plugin_file;
|
51 |
+
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Set Version
|
56 |
+
*
|
57 |
+
* @return string Version string.
|
58 |
+
*/
|
59 |
+
public static function set_version( $version ) {
|
60 |
+
|
61 |
+
self::$version = $version;
|
62 |
+
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Get Version
|
67 |
+
*
|
68 |
+
* @return string Version string.
|
69 |
+
*/
|
70 |
+
public static function get_version() {
|
71 |
+
|
72 |
+
return self::$version;
|
73 |
+
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Check if a WordPress feature is supported
|
78 |
+
*
|
79 |
+
* @param string $feature Feature.
|
80 |
+
* @return boolean
|
81 |
+
*/
|
82 |
+
public static function supports( $feature ) {
|
83 |
+
|
84 |
+
switch ( $feature ) {
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Media Modal Supported?
|
88 |
+
*
|
89 |
+
* @see WordPress 3.5 Blog Post
|
90 |
+
* https://wordpress.org/news/2012/12/elvin/
|
91 |
+
*
|
92 |
+
* @see WordPress JavaScript wp.media
|
93 |
+
* https://codex.wordpress.org/Javascript_Reference/wp.media
|
94 |
+
*/
|
95 |
+
case 'media_modal':
|
96 |
+
return version_compare( get_bloginfo( 'version' ), 3.5 ) >= 0;
|
97 |
+
|
98 |
+
}
|
99 |
+
|
100 |
+
return false;
|
101 |
+
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Plugin Basename
|
106 |
+
*
|
107 |
+
* @return string Plugin basename.
|
108 |
+
*/
|
109 |
+
public static function basename() {
|
110 |
+
|
111 |
+
// Get and cache basename
|
112 |
+
if ( is_null( self::$basename ) ) {
|
113 |
+
self::$basename = plugin_basename( self::$plugin_file );
|
114 |
+
}
|
115 |
+
|
116 |
+
return self::$basename;
|
117 |
+
|
118 |
+
}
|
119 |
+
|
120 |
+
/**
|
121 |
+
* Plugin Sub Directory
|
122 |
+
*
|
123 |
+
* @param string $file Optional. File path to append.
|
124 |
+
* @return string Plugin folder name and filepath.
|
125 |
+
*/
|
126 |
+
public static function dirname( $file = '' ) {
|
127 |
+
|
128 |
+
// Get and cache dirname
|
129 |
+
if ( is_null( self::$dirname ) ) {
|
130 |
+
self::$dirname = dirname( self::basename() );
|
131 |
+
}
|
132 |
+
|
133 |
+
// Add file path
|
134 |
+
if ( ! empty( $file ) ) {
|
135 |
+
return trailingslashit( self::$dirname ) . $file;
|
136 |
+
}
|
137 |
+
|
138 |
+
return self::$dirname;
|
139 |
+
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Plugin URL
|
144 |
+
*
|
145 |
+
* @param string $file Optional. File path to append.
|
146 |
+
* @return string Plugin directory URL and filepath.
|
147 |
+
*/
|
148 |
+
public static function url( $file = '' ) {
|
149 |
+
|
150 |
+
// Get and cache URL
|
151 |
+
if ( is_null( self::$url ) ) {
|
152 |
+
self::$url = plugin_dir_url( self::$plugin_file );
|
153 |
+
}
|
154 |
+
|
155 |
+
// Add file path
|
156 |
+
if ( ! empty( $file ) ) {
|
157 |
+
return trailingslashit( self::$url ) . $file;
|
158 |
+
}
|
159 |
+
|
160 |
+
return self::$url;
|
161 |
+
|
162 |
+
}
|
163 |
+
|
164 |
+
}
|
deprecated.php → legacy/includes/deprecated.php
RENAMED
@@ -1,5 +1,102 @@
|
|
1 |
<?php
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
/**
|
4 |
* Deprecated Shortcode.
|
5 |
*
|
@@ -25,7 +122,6 @@ function taxonomy_images_plugin_shortcode_deprecated( $atts = array() ) {
|
|
25 |
}
|
26 |
|
27 |
$terms = get_terms( $taxonomy );
|
28 |
-
$associations = taxonomy_image_plugin_get_associations( $refresh = false );
|
29 |
|
30 |
if ( ! is_wp_error( $terms ) ) {
|
31 |
foreach( (array) $terms as $term ) {
|
@@ -34,10 +130,10 @@ function taxonomy_images_plugin_shortcode_deprecated( $atts = array() ) {
|
|
34 |
$title_attr = esc_attr( $term->name . ' (' . $term->count . ')' );
|
35 |
$description = apply_filters( 'the_content', $term->description );
|
36 |
|
37 |
-
$
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
|
42 |
if ( 'grid' == $template ) {
|
43 |
$o .= "\n\t" . '<div class="taxonomy_image_plugin-' . $template . '">';
|
@@ -88,14 +184,19 @@ class taxonomy_images_plugin {
|
|
88 |
global $wp_query;
|
89 |
$obj = $wp_query->get_queried_object();
|
90 |
if ( isset( $obj->term_taxonomy_id ) ) {
|
91 |
-
$
|
92 |
} else {
|
93 |
return false;
|
94 |
}
|
|
|
|
|
|
|
|
|
95 |
}
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
99 |
$alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true );
|
100 |
$attachment = get_post( $attachment_id );
|
101 |
/* Just in case an attachment was deleted, but there is still a record for it in this plugins settings. */
|
1 |
<?php
|
2 |
|
3 |
+
/**
|
4 |
+
* Check Taxonomy Permissions.
|
5 |
+
*
|
6 |
+
* Allows a permission check to be performed on a term
|
7 |
+
* when all you know is the term_taxonomy_id.
|
8 |
+
*
|
9 |
+
* @param int term_taxonomy_id
|
10 |
+
* @return bool True if user can edit terms, False if not.
|
11 |
+
*
|
12 |
+
* @access private
|
13 |
+
*/
|
14 |
+
function taxonomy_image_plugin_check_permissions( $tt_id ) {
|
15 |
+
|
16 |
+
$t = new Taxonomy_Images_Term( $tt_id, true );
|
17 |
+
|
18 |
+
return $t->current_user_can_edit();
|
19 |
+
|
20 |
+
}
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Please Use Filter.
|
24 |
+
*
|
25 |
+
* Report to user that they are directly calling a function
|
26 |
+
* instead of using supported filters. A E_USER_NOTICE will
|
27 |
+
* be generated.
|
28 |
+
*
|
29 |
+
* @param string Name of function called.
|
30 |
+
* @param string Name of filter to use instead.
|
31 |
+
*
|
32 |
+
* @access private
|
33 |
+
* @since 0.7
|
34 |
+
*/
|
35 |
+
function taxonomy_image_plugin_please_use_filter( $function, $filter ) {
|
36 |
+
|
37 |
+
Taxonomy_Images_Public_Filters::please_use_filter( $function, $filter );
|
38 |
+
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Get Term Info.
|
43 |
+
*
|
44 |
+
* Returns term info by term_taxonomy_id.
|
45 |
+
*
|
46 |
+
* @deprecated
|
47 |
+
*
|
48 |
+
* @param int term_taxonomy_id
|
49 |
+
* @return array Keys: term_id (int) and taxonomy (string).
|
50 |
+
*
|
51 |
+
* @access private
|
52 |
+
*/
|
53 |
+
function taxonomy_image_plugin_get_term_info( $tt_id ) {
|
54 |
+
|
55 |
+
$t = new Taxonomy_Images_Term( $tt_id, true );
|
56 |
+
$term = $t->get_term();
|
57 |
+
|
58 |
+
if ( $term ) {
|
59 |
+
return array(
|
60 |
+
'term_id' => $term->term_id,
|
61 |
+
'taxonomy' => $term->taxonomy
|
62 |
+
);
|
63 |
+
}
|
64 |
+
|
65 |
+
return array();
|
66 |
+
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Version Number.
|
71 |
+
*
|
72 |
+
* @deprecated
|
73 |
+
*
|
74 |
+
* @return string The plugin's version number.
|
75 |
+
* @access private
|
76 |
+
* @since 0.7
|
77 |
+
* @alter 0.7.4
|
78 |
+
*/
|
79 |
+
function taxonomy_image_plugin_version() {
|
80 |
+
|
81 |
+
return Taxonomy_Images_Config::get_version();
|
82 |
+
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Get a url to a file in this plugin.
|
87 |
+
*
|
88 |
+
* @deprecated
|
89 |
+
*
|
90 |
+
* @return string
|
91 |
+
* @access private
|
92 |
+
* @since 0.7
|
93 |
+
*/
|
94 |
+
function taxonomy_image_plugin_url( $file = '' ) {
|
95 |
+
|
96 |
+
return Taxonomy_Images_Config::url( $file );
|
97 |
+
|
98 |
+
}
|
99 |
+
|
100 |
/**
|
101 |
* Deprecated Shortcode.
|
102 |
*
|
122 |
}
|
123 |
|
124 |
$terms = get_terms( $taxonomy );
|
|
|
125 |
|
126 |
if ( ! is_wp_error( $terms ) ) {
|
127 |
foreach( (array) $terms as $term ) {
|
130 |
$title_attr = esc_attr( $term->name . ' (' . $term->count . ')' );
|
131 |
$description = apply_filters( 'the_content', $term->description );
|
132 |
|
133 |
+
$t = new Taxonomy_Images_Term( $term );
|
134 |
+
$img_id = $t->get_image_id();
|
135 |
+
|
136 |
+
$img = $img_id ? wp_get_attachment_image( $img_id, 'detail', false ) : '';
|
137 |
|
138 |
if ( 'grid' == $template ) {
|
139 |
$o .= "\n\t" . '<div class="taxonomy_image_plugin-' . $template . '">';
|
184 |
global $wp_query;
|
185 |
$obj = $wp_query->get_queried_object();
|
186 |
if ( isset( $obj->term_taxonomy_id ) ) {
|
187 |
+
$t = new Taxonomy_Images_Term( $obj );
|
188 |
} else {
|
189 |
return false;
|
190 |
}
|
191 |
+
} else {
|
192 |
+
|
193 |
+
$t = new Taxonomy_Images_Term( $term_tax_id, true );
|
194 |
+
|
195 |
}
|
196 |
+
|
197 |
+
$attachment_id = $t->get_image_id();
|
198 |
+
|
199 |
+
if ( $attachment_id ) {
|
200 |
$alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true );
|
201 |
$attachment = get_post( $attachment_id );
|
202 |
/* Just in case an attachment was deleted, but there is still a record for it in this plugins settings. */
|
legacy/includes/functions.php
ADDED
@@ -0,0 +1,1077 @@
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @package Taxononomy Images
|
5 |
+
* @subpackage Functions
|
6 |
+
*/
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Detail Image Size.
|
10 |
+
*
|
11 |
+
* @return array Configuration for the "detail" image size.
|
12 |
+
* @access private
|
13 |
+
* @since 0.7
|
14 |
+
*/
|
15 |
+
function taxonomy_image_plugin_detail_image_size() {
|
16 |
+
return array(
|
17 |
+
'name' => 'detail',
|
18 |
+
'size' => array( 150, 150, true )
|
19 |
+
);
|
20 |
+
}
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Register custom image size with WordPress.
|
24 |
+
*
|
25 |
+
* @access private
|
26 |
+
* @since 2010-10-28
|
27 |
+
*/
|
28 |
+
function taxonomy_image_plugin_add_image_size() {
|
29 |
+
$detail = taxonomy_image_plugin_detail_image_size();
|
30 |
+
add_image_size(
|
31 |
+
$detail['name'],
|
32 |
+
$detail['size'][0],
|
33 |
+
$detail['size'][1],
|
34 |
+
$detail['size'][2]
|
35 |
+
);
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Load Plugin Text Domain.
|
40 |
+
*
|
41 |
+
* @access private
|
42 |
+
* @since 0.7.3
|
43 |
+
*/
|
44 |
+
function taxonomy_image_plugin_text_domain() {
|
45 |
+
load_plugin_textdomain( 'taxonomy-images', false, Taxonomy_Images_Config::dirname( 'languages' ) );
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Modal Button.
|
50 |
+
*
|
51 |
+
* Create a button in the modal media window to associate the current image to the term.
|
52 |
+
*
|
53 |
+
* @param array Multidimensional array representing the images form.
|
54 |
+
* @param stdClass WordPress post object.
|
55 |
+
* @return array The image's form array with added button if modal window was accessed by this script.
|
56 |
+
*
|
57 |
+
* @access private
|
58 |
+
* @since 2010-10-28
|
59 |
+
* @alter 0.7
|
60 |
+
*/
|
61 |
+
function taxonomy_image_plugin_modal_button( $fields, $post ) {
|
62 |
+
if ( isset( $fields['image-size'] ) && isset( $post->ID ) ) {
|
63 |
+
$image_id = (int) $post->ID;
|
64 |
+
|
65 |
+
$o = '<div class="taxonomy-image-modal-control" id="' . esc_attr( 'taxonomy-image-modal-control-' . $image_id ) . '">';
|
66 |
+
$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>';
|
67 |
+
$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>';
|
68 |
+
$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 ) . '" />';
|
69 |
+
$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' ) ) . '" />';
|
70 |
+
$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' ) ) . '" />';
|
71 |
+
$o .= '</div>';
|
72 |
+
|
73 |
+
$fields['image-size']['extra_rows']['taxonomy-image-plugin-button']['html'] = $o;
|
74 |
+
}
|
75 |
+
return $fields;
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Get Image Source.
|
80 |
+
*
|
81 |
+
* Return a uri to a custom image size.
|
82 |
+
*
|
83 |
+
* If size doesn't exist, attempt to create a resized version.
|
84 |
+
* The output of this function should be escaped before printing to the browser.
|
85 |
+
*
|
86 |
+
* @param int Image ID.
|
87 |
+
* @return string URI of custom image on success; emtpy string otherwise.
|
88 |
+
*
|
89 |
+
* @access private.
|
90 |
+
* @since 2010-10-28
|
91 |
+
*/
|
92 |
+
function taxonomy_image_plugin_get_image_src( $id ) {
|
93 |
+
$detail = taxonomy_image_plugin_detail_image_size();
|
94 |
+
|
95 |
+
/* Return url to custom intermediate size if it exists. */
|
96 |
+
$img = image_get_intermediate_size( $id, $detail['name'] );
|
97 |
+
if ( isset( $img['url'] ) ) {
|
98 |
+
return $img['url'];
|
99 |
+
}
|
100 |
+
|
101 |
+
// Detail image does not exist, attempt to create it.
|
102 |
+
$wp_upload_dir = wp_upload_dir();
|
103 |
+
|
104 |
+
if ( isset( $wp_upload_dir['basedir'] ) ) {
|
105 |
+
|
106 |
+
/* Create path to original uploaded image. */
|
107 |
+
$path = trailingslashit( $wp_upload_dir['basedir'] ) . get_post_meta( $id, '_wp_attached_file', true );
|
108 |
+
if ( is_file( $path ) ) {
|
109 |
+
|
110 |
+
// Attempt to create a new downsized version of the original image
|
111 |
+
$new = wp_get_image_editor( $path );
|
112 |
+
|
113 |
+
// Image editor instance OK
|
114 |
+
if ( ! is_wp_error( $new ) ) {
|
115 |
+
|
116 |
+
$resized = $new->resize(
|
117 |
+
$detail['size'][0],
|
118 |
+
$detail['size'][1],
|
119 |
+
absint( $detail['size'][2] )
|
120 |
+
);
|
121 |
+
|
122 |
+
// Image resize successful. Generate and cache image metadata. Return url.
|
123 |
+
if ( ! is_wp_error( $resized ) ) {
|
124 |
+
|
125 |
+
$path = $new->generate_filename();
|
126 |
+
$new->save( $path );
|
127 |
+
|
128 |
+
$meta = wp_generate_attachment_metadata( $id, $path );
|
129 |
+
wp_update_attachment_metadata( $id, $meta );
|
130 |
+
$img = image_get_intermediate_size( $id, $detail['name'] );
|
131 |
+
|
132 |
+
if ( isset( $img['url'] ) ) {
|
133 |
+
return $img['url'];
|
134 |
+
}
|
135 |
+
|
136 |
+
}
|
137 |
+
|
138 |
+
}
|
139 |
+
|
140 |
+
}
|
141 |
+
|
142 |
+
}
|
143 |
+
|
144 |
+
/* Custom intermediate size cannot be created, try for thumbnail. */
|
145 |
+
$img = image_get_intermediate_size( $id, 'thumbnail' );
|
146 |
+
if ( isset( $img['url'] ) ) {
|
147 |
+
return $img['url'];
|
148 |
+
}
|
149 |
+
|
150 |
+
/* Thumbnail cannot be found, try fullsize. */
|
151 |
+
$url = wp_get_attachment_url( $id );
|
152 |
+
if ( ! empty( $url ) ) {
|
153 |
+
return $url;
|
154 |
+
}
|
155 |
+
|
156 |
+
/**
|
157 |
+
* No image can be found.
|
158 |
+
* This is most likely caused by a user deleting an attachment before deleting it's association with a taxonomy.
|
159 |
+
* If we are in the administration panels:
|
160 |
+
* - Delete the association.
|
161 |
+
* - Return uri to default.png.
|
162 |
+
*/
|
163 |
+
if ( is_admin() ) {
|
164 |
+
$assoc = taxonomy_image_plugin_get_associations();
|
165 |
+
foreach ( $assoc as $term => $img ) {
|
166 |
+
if ( $img === $id ) {
|
167 |
+
unset( $assoc[ $term ] );
|
168 |
+
}
|
169 |
+
}
|
170 |
+
update_option( 'taxonomy_image_plugin', $assoc );
|
171 |
+
|
172 |
+
return Taxonomy_Images_Config::url( 'images/default.png' );
|
173 |
+
|
174 |
+
}
|
175 |
+
|
176 |
+
/*
|
177 |
+
* No image can be found.
|
178 |
+
* Return path to blank-image.png.
|
179 |
+
*/
|
180 |
+
return Taxonomy_Images_Config::url( 'images/blank.png' );
|
181 |
+
|
182 |
+
}
|
183 |
+
|
184 |
+
/**
|
185 |
+
* Sanitize Associations.
|
186 |
+
*
|
187 |
+
* Ensures that all key/value pairs are positive integers.
|
188 |
+
* This filter will discard all zero and negative values.
|
189 |
+
*
|
190 |
+
* @param array An array of term_taxonomy_id/attachment_id pairs.
|
191 |
+
* @return array Sanitized version of parameter.
|
192 |
+
*
|
193 |
+
* @access private
|
194 |
+
*/
|
195 |
+
function taxonomy_image_plugin_sanitize_associations( $associations ) {
|
196 |
+
$o = array();
|
197 |
+
foreach ( (array) $associations as $tt_id => $im_id ) {
|
198 |
+
$tt_id = absint( $tt_id );
|
199 |
+
$im_id = absint( $im_id );
|
200 |
+
if ( 0 < $tt_id && 0 < $im_id )
|
201 |
+
$o[ $tt_id ] = $im_id;
|
202 |
+
}
|
203 |
+
return $o;
|
204 |
+
}
|
205 |
+
|
206 |
+
/**
|
207 |
+
* Sanitize Settings.
|
208 |
+
*
|
209 |
+
* This function is responsible for ensuring that
|
210 |
+
* all values within the 'taxonomy_image_plugin_settings'
|
211 |
+
* options are of the appropriate type.
|
212 |
+
*
|
213 |
+
* @param array Unknown.
|
214 |
+
* @return array Multi-dimensional array of sanitized settings.
|
215 |
+
*
|
216 |
+
* @access private
|
217 |
+
* @since 0.7
|
218 |
+
*/
|
219 |
+
function taxonomy_image_plugin_settings_sanitize( $dirty ) {
|
220 |
+
$clean = array();
|
221 |
+
if ( isset( $dirty['taxonomies'] ) ) {
|
222 |
+
$taxonomies = get_taxonomies();
|
223 |
+
foreach ( (array) $dirty['taxonomies'] as $taxonomy ) {
|
224 |
+
if ( in_array( $taxonomy, $taxonomies ) )
|
225 |
+
$clean['taxonomies'][] = $taxonomy;
|
226 |
+
}
|
227 |
+
}
|
228 |
+
|
229 |
+
/* translators: Notice displayed on the custom administration page. */
|
230 |
+
$message = __( 'Image support for taxonomies successfully updated', 'taxonomy-images' );
|
231 |
+
if ( empty( $clean ) ) {
|
232 |
+
/* translators: Notice displayed on the custom administration page. */
|
233 |
+
$message = __( 'Image support has been disabled for all taxonomies.', 'taxonomy-images' );
|
234 |
+
}
|
235 |
+
|
236 |
+
add_settings_error( 'taxonomy_image_plugin_settings', 'taxonomies_updated', esc_html( $message ), 'updated' );
|
237 |
+
|
238 |
+
return $clean;
|
239 |
+
}
|
240 |
+
|
241 |
+
/**
|
242 |
+
* Register settings with WordPress.
|
243 |
+
*
|
244 |
+
* This plugin will store to sets of settings in the
|
245 |
+
* options table. The first is named 'taxonomy_image_plugin'
|
246 |
+
* and stores the associations between terms and images. The
|
247 |
+
* keys in this array represent the term_taxonomy_id of the
|
248 |
+
* term while the value represents the ID of the image
|
249 |
+
* attachment.
|
250 |
+
*
|
251 |
+
* The second setting is used to store everything else. As of
|
252 |
+
* version 0.7 it has one key named 'taxonomies' whichi is a
|
253 |
+
* flat array consisting of taxonomy names representing a
|
254 |
+
* black-list of registered taxonomies. These taxonomies will
|
255 |
+
* NOT be given an image UI.
|
256 |
+
*
|
257 |
+
* @access private
|
258 |
+
*/
|
259 |
+
function taxonomy_image_plugin_register_settings() {
|
260 |
+
register_setting(
|
261 |
+
'taxonomy_image_plugin',
|
262 |
+
'taxonomy_image_plugin',
|
263 |
+
'taxonomy_image_plugin_sanitize_associations'
|
264 |
+
);
|
265 |
+
register_setting(
|
266 |
+
'taxonomy_image_plugin_settings',
|
267 |
+
'taxonomy_image_plugin_settings',
|
268 |
+
'taxonomy_image_plugin_settings_sanitize'
|
269 |
+
);
|
270 |
+
add_settings_section(
|
271 |
+
'taxonomy_image_plugin_settings',
|
272 |
+
esc_html__( 'Settings', 'taxonomy-images' ),
|
273 |
+
'__return_false',
|
274 |
+
'taxonomy_image_plugin_settings'
|
275 |
+
);
|
276 |
+
add_settings_field(
|
277 |
+
'taxonomy-images',
|
278 |
+
esc_html__( 'Taxonomies', 'taxonomy-images' ),
|
279 |
+
'taxonomy_image_plugin_control_taxonomies',
|
280 |
+
'taxonomy_image_plugin_settings',
|
281 |
+
'taxonomy_image_plugin_settings'
|
282 |
+
);
|
283 |
+
}
|
284 |
+
|
285 |
+
/**
|
286 |
+
* Admin Menu.
|
287 |
+
*
|
288 |
+
* Create the admin menu link for the settings page.
|
289 |
+
*
|
290 |
+
* @access private
|
291 |
+
* @since 0.7
|
292 |
+
*/
|
293 |
+
function taxonomy_images_settings_menu() {
|
294 |
+
add_options_page(
|
295 |
+
esc_html__( 'Taxonomy Images', 'taxonomy-images' ), // HTML <title> tag.
|
296 |
+
esc_html__( 'Taxonomy Images', 'taxonomy-images' ), // Link text in admin menu.
|
297 |
+
'manage_options',
|
298 |
+
'taxonomy_image_plugin_settings',
|
299 |
+
'taxonomy_image_plugin_settings_page'
|
300 |
+
);
|
301 |
+
}
|
302 |
+
|
303 |
+
/**
|
304 |
+
* Settings Page Template.
|
305 |
+
*
|
306 |
+
* This function in conjunction with others usei the WordPress
|
307 |
+
* Settings API to create a settings page where users can adjust
|
308 |
+
* the behaviour of this plugin. Please see the following functions
|
309 |
+
* for more insight on the output generated by this function:
|
310 |
+
*
|
311 |
+
* taxonomy_image_plugin_control_taxonomies()
|
312 |
+
*
|
313 |
+
* @access private
|
314 |
+
* @since 0.7
|
315 |
+
*/
|
316 |
+
function taxonomy_image_plugin_settings_page() {
|
317 |
+
print "\n" . '<div class="wrap">';
|
318 |
+
|
319 |
+
/* translators: Heading of the custom administration page. */
|
320 |
+
print "\n" . '<h2>' . esc_html__( 'Taxonomy Images Plugin Settings', 'taxonomy-images' ) . '</h2>';
|
321 |
+
print "\n" . '<div id="taxonomy-images">';
|
322 |
+
print "\n" . '<form action="options.php" method="post">';
|
323 |
+
|
324 |
+
settings_fields( 'taxonomy_image_plugin_settings' );
|
325 |
+
do_settings_sections( 'taxonomy_image_plugin_settings' );
|
326 |
+
|
327 |
+
/* translators: Button on the custom administration page. */
|
328 |
+
print "\n" . '<div class="button-holder"><input class="button-primary" name="submit" type="submit" value="' . esc_attr__( 'Save Changes', 'taxonomy-images' ) . '" /></div>';
|
329 |
+
print "\n" . '</div></form></div>';
|
330 |
+
}
|
331 |
+
|
332 |
+
/**
|
333 |
+
* Taxonomy Checklist.
|
334 |
+
*
|
335 |
+
* @access private
|
336 |
+
*/
|
337 |
+
function taxonomy_image_plugin_control_taxonomies() {
|
338 |
+
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
339 |
+
$taxonomies = get_taxonomies( array(), 'objects' );
|
340 |
+
foreach ( (array) $taxonomies as $taxonomy ) {
|
341 |
+
if ( ! isset( $taxonomy->name ) ) {
|
342 |
+
continue;
|
343 |
+
}
|
344 |
+
|
345 |
+
if ( ! isset( $taxonomy->label ) ) {
|
346 |
+
continue;
|
347 |
+
}
|
348 |
+
|
349 |
+
if ( ! isset( $taxonomy->show_ui ) || empty( $taxonomy->show_ui ) ) {
|
350 |
+
continue;
|
351 |
+
}
|
352 |
+
|
353 |
+
$id = 'taxonomy-images-' . $taxonomy->name;
|
354 |
+
|
355 |
+
$checked = '';
|
356 |
+
if ( isset( $settings['taxonomies'] ) && in_array( $taxonomy->name, (array) $settings['taxonomies'] ) ) {
|
357 |
+
$checked = ' checked="checked"';
|
358 |
+
}
|
359 |
+
|
360 |
+
print "\n" . '<p><label for="' . esc_attr( $id ) . '">';
|
361 |
+
print '<input' . $checked . ' id="' . esc_attr( $id ) . '" type="checkbox" name="taxonomy_image_plugin_settings[taxonomies][]" value="' . esc_attr( $taxonomy->name ) . '" />';
|
362 |
+
print ' ' . esc_html( $taxonomy->label ) . '</label></p>';
|
363 |
+
}
|
364 |
+
}
|
365 |
+
|
366 |
+
/**
|
367 |
+
* JSON Respose.
|
368 |
+
* Terminates script execution.
|
369 |
+
*
|
370 |
+
* @param array Associative array of values to be encoded in JSON.
|
371 |
+
*
|
372 |
+
* @access private
|
373 |
+
*/
|
374 |
+
function taxonomy_image_plugin_json_response( $args ) {
|
375 |
+
/* translators: An ajax request has failed for an unknown reason. */
|
376 |
+
$response = wp_parse_args( $args, array(
|
377 |
+
'status' => 'bad',
|
378 |
+
'why' => esc_html__( 'Unknown error encountered', 'taxonomy-images' )
|
379 |
+
) );
|
380 |
+
|
381 |
+
wp_send_json( $response );
|
382 |
+
|
383 |
+
}
|
384 |
+
|
385 |
+
/**
|
386 |
+
* Create an association.
|
387 |
+
*
|
388 |
+
* Callback for the wp_ajax_{$_GET['action']} hook.
|
389 |
+
*
|
390 |
+
* @access private
|
391 |
+
*/
|
392 |
+
function taxonomy_image_plugin_create_association() {
|
393 |
+
if ( ! isset( $_POST['tt_id'] ) ) {
|
394 |
+
taxonomy_image_plugin_json_response( array(
|
395 |
+
'status' => 'bad',
|
396 |
+
'why' => esc_html__( 'tt_id not sent', 'taxonomy-images' ),
|
397 |
+
) );
|
398 |
+
}
|
399 |
+
|
400 |
+
$tt_id = absint( $_POST['tt_id'] );
|
401 |
+
if ( empty( $tt_id ) ) {
|
402 |
+
taxonomy_image_plugin_json_response( array(
|
403 |
+
'status' => 'bad',
|
404 |
+
'why' => esc_html__( 'tt_id is empty', 'taxonomy-images' ),
|
405 |
+
) );
|
406 |
+
}
|
407 |
+
|
408 |
+
if ( ! isset( $_POST['wp_nonce'] ) ) {
|
409 |
+
taxonomy_image_plugin_json_response( array(
|
410 |
+
'status' => 'bad',
|
411 |
+
'why' => esc_html__( 'No nonce included.', 'taxonomy-images' ),
|
412 |
+
) );
|
413 |
+
}
|
414 |
+
|
415 |
+
if ( ! wp_verify_nonce( $_POST['wp_nonce'], 'taxonomy-image-plugin-create-association' ) ) {
|
416 |
+
taxonomy_image_plugin_json_response( array(
|
417 |
+
'status' => 'bad',
|
418 |
+
'why' => esc_html__( 'Nonce did not match', 'taxonomy-images' ),
|
419 |
+
) );
|
420 |
+
}
|
421 |
+
|
422 |
+
if ( ! isset( $_POST['attachment_id'] ) ) {
|
423 |
+
taxonomy_image_plugin_json_response( array(
|
424 |
+
'status' => 'bad',
|
425 |
+
'why' => esc_html__( 'Image id not sent', 'taxonomy-images' )
|
426 |
+
) );
|
427 |
+
}
|
428 |
+
|
429 |
+
$image_id = absint( $_POST['attachment_id'] );
|
430 |
+
if ( empty( $image_id ) ) {
|
431 |
+
taxonomy_image_plugin_json_response( array(
|
432 |
+
'status' => 'bad',
|
433 |
+
'why' => esc_html__( 'Image id is not a positive integer', 'taxonomy-images' )
|
434 |
+
) );
|
435 |
+
}
|
436 |
+
|
437 |
+
$t = new Taxonomy_Images_Term( $tt_id, true );
|
438 |
+
|
439 |
+
if ( ! $t->current_user_can_edit() ) {
|
440 |
+
taxonomy_image_plugin_json_response( array(
|
441 |
+
'status' => 'bad',
|
442 |
+
'why' => esc_html__( 'You do not have the correct capability to manage this term', 'taxonomy-images' ),
|
443 |
+
) );
|
444 |
+
}
|
445 |
+
|
446 |
+
if ( $t->update_image_id( $image_id ) ) {
|
447 |
+
taxonomy_image_plugin_json_response( array(
|
448 |
+
'status' => 'good',
|
449 |
+
'why' => esc_html__( 'Image successfully associated', 'taxonomy-images' ),
|
450 |
+
'attachment_thumb_src' => taxonomy_image_plugin_get_image_src( $image_id )
|
451 |
+
) );
|
452 |
+
} else {
|
453 |
+
taxonomy_image_plugin_json_response( array(
|
454 |
+
'status' => 'bad',
|
455 |
+
'why' => esc_html__( 'Association could not be created', 'taxonomy-images' )
|
456 |
+
) );
|
457 |
+
}
|
458 |
+
|
459 |
+
/* Don't know why, but something didn't work. */
|
460 |
+
taxonomy_image_plugin_json_response();
|
461 |
+
}
|
462 |
+
|
463 |
+
/**
|
464 |
+
* Remove an association.
|
465 |
+
*
|
466 |
+
* Removes an association from the setting stored in the database.
|
467 |
+
* Print json encoded message and terminates script execution.
|
468 |
+
*
|
469 |
+
* @access private
|
470 |
+
*/
|
471 |
+
function taxonomy_image_plugin_remove_association() {
|
472 |
+
if ( ! isset( $_POST['tt_id'] ) ) {
|
473 |
+
taxonomy_image_plugin_json_response( array(
|
474 |
+
'status' => 'bad',
|
475 |
+
'why' => esc_html__( 'tt_id not sent', 'taxonomy-images' ),
|
476 |
+
) );
|
477 |
+
}
|
478 |
+
|
479 |
+
$tt_id = absint( $_POST['tt_id'] );
|
480 |
+
if ( empty( $tt_id ) ) {
|
481 |
+
taxonomy_image_plugin_json_response( array(
|
482 |
+
'status' => 'bad',
|
483 |
+
'why' => esc_html__( 'tt_id is empty', 'taxonomy-images' ),
|
484 |
+
) );
|
485 |
+
}
|
486 |
+
|
487 |
+
if ( ! isset( $_POST['wp_nonce'] ) ) {
|
488 |
+
taxonomy_image_plugin_json_response( array(
|
489 |
+
'status' => 'bad',
|
490 |
+
'why' => esc_html__( 'No nonce included', 'taxonomy-images' ),
|
491 |
+
) );
|
492 |
+
}
|
493 |
+
|
494 |
+
if ( ! wp_verify_nonce( $_POST['wp_nonce'], 'taxonomy-image-plugin-remove-association') ) {
|
495 |
+
taxonomy_image_plugin_json_response( array(
|
496 |
+
'status' => 'bad',
|
497 |
+
'why' => esc_html__( 'Nonce did not match', 'taxonomy-images' ),
|
498 |
+
) );
|
499 |
+
}
|
500 |
+
|
501 |
+
$t = new Taxonomy_Images_Term( $tt_id, true );
|
502 |
+
|
503 |
+
if ( ! $t->current_user_can_edit() ) {
|
504 |
+
taxonomy_image_plugin_json_response( array(
|
505 |
+
'status' => 'bad',
|
506 |
+
'why' => esc_html__( 'You do not have the correct capability to manage this term', 'taxonomy-images' ),
|
507 |
+
) );
|
508 |
+
}
|
509 |
+
|
510 |
+
$img = $t->get_image_id();
|
511 |
+
|
512 |
+
if ( ! $img ) {
|
513 |
+
taxonomy_image_plugin_json_response( array(
|
514 |
+
'status' => 'good',
|
515 |
+
'why' => esc_html__( 'Nothing to remove', 'taxonomy-images' )
|
516 |
+
) );
|
517 |
+
}
|
518 |
+
|
519 |
+
if ( $t->delete_image_id() ) {
|
520 |
+
taxonomy_image_plugin_json_response( array(
|
521 |
+
'status' => 'good',
|
522 |
+
'why' => esc_html__( 'Association successfully removed', 'taxonomy-images' )
|
523 |
+
) );
|
524 |
+
} else {
|
525 |
+
taxonomy_image_plugin_json_response( array(
|
526 |
+
'status' => 'bad',
|
527 |
+
'why' => esc_html__( 'Association could not be removed', 'taxonomy-images' )
|
528 |
+
) );
|
529 |
+
}
|
530 |
+
|
531 |
+
/* Don't know why, but something didn't work. */
|
532 |
+
taxonomy_image_plugin_json_response();
|
533 |
+
}
|
534 |
+
|
535 |
+
/**
|
536 |
+
* Get a list of user-defined associations.
|
537 |
+
* Associations are stored in the WordPress options table.
|
538 |
+
*
|
539 |
+
* @param bool Should WordPress query the database for the results
|
540 |
+
* @return array List of associations. Key => taxonomy_term_id; Value => image_id
|
541 |
+
*
|
542 |
+
* @access private
|
543 |
+
*/
|
544 |
+
function taxonomy_image_plugin_get_associations( $refresh = false ) {
|
545 |
+
static $associations = array();
|
546 |
+
if ( empty( $associations ) || $refresh ) {
|
547 |
+
$associations = taxonomy_image_plugin_sanitize_associations( get_option( 'taxonomy_image_plugin' ) );
|
548 |
+
}
|
549 |
+
|
550 |
+
return $associations;
|
551 |
+
}
|
552 |
+
|
553 |
+
/**
|
554 |
+
* Dynamically create hooks for each taxonomy.
|
555 |
+
*
|
556 |
+
* Adds hooks for each taxonomy that the user has given
|
557 |
+
* an image interface to via settings page. These hooks
|
558 |
+
* enable the image interface on wp-admin/edit-tags.php.
|
559 |
+
*
|
560 |
+
* @access private
|
561 |
+
* @since 0.4.3
|
562 |
+
* @alter 0.7
|
563 |
+
*/
|
564 |
+
function taxonomy_image_plugin_add_dynamic_hooks() {
|
565 |
+
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
566 |
+
if ( ! isset( $settings['taxonomies'] ) ) {
|
567 |
+
return;
|
568 |
+
}
|
569 |
+
|
570 |
+
foreach ( $settings['taxonomies'] as $taxonomy ) {
|
571 |
+
add_filter( 'manage_' . $taxonomy . '_custom_column', 'taxonomy_image_plugin_taxonomy_rows', 15, 3 );
|
572 |
+
add_filter( 'manage_edit-' . $taxonomy . '_columns', 'taxonomy_image_plugin_taxonomy_columns' );
|
573 |
+
add_action( $taxonomy . '_edit_form_fields', 'taxonomy_image_plugin_edit_tag_form', 10, 2 );
|
574 |
+
}
|
575 |
+
}
|
576 |
+
|
577 |
+
/**
|
578 |
+
* Edit Term Columns.
|
579 |
+
*
|
580 |
+
* Insert a new column on wp-admin/edit-tags.php.
|
581 |
+
*
|
582 |
+
* @see taxonomy_image_plugin_add_dynamic_hooks()
|
583 |
+
*
|
584 |
+
* @param array A list of columns.
|
585 |
+
* @return array List of columns with "Images" inserted after the checkbox.
|
586 |
+
*
|
587 |
+
* @access private
|
588 |
+
* @since 0.4.3
|
589 |
+
*/
|
590 |
+
function taxonomy_image_plugin_taxonomy_columns( $original_columns ) {
|
591 |
+
$new_columns = $original_columns;
|
592 |
+
array_splice( $new_columns, 1 );
|
593 |
+
$new_columns['taxonomy_image_plugin'] = esc_html__( 'Image', 'taxonomy-images' );
|
594 |
+
return array_merge( $new_columns, $original_columns );
|
595 |
+
}
|
596 |
+
|
597 |
+
/**
|
598 |
+
* Edit Term Rows.
|
599 |
+
*
|
600 |
+
* Create image control for each term row of wp-admin/edit-tags.php.
|
601 |
+
*
|
602 |
+
* @see taxonomy_image_plugin_add_dynamic_hooks()
|
603 |
+
*
|
604 |
+
* @param string Row.
|
605 |
+
* @param string Name of the current column.
|
606 |
+
* @param int Term ID.
|
607 |
+
* @return string @see taxonomy_image_plugin_control_image()
|
608 |
+
*
|
609 |
+
* @access private
|
610 |
+
* @since 2010-11-08
|
611 |
+
*/
|
612 |
+
function taxonomy_image_plugin_taxonomy_rows( $row, $column_name, $term_id ) {
|
613 |
+
if ( 'taxonomy_image_plugin' === $column_name ) {
|
614 |
+
global $taxonomy;
|
615 |
+
return $row . taxonomy_image_plugin_control_image( $term_id, $taxonomy );
|
616 |
+
}
|
617 |
+
return $row;
|
618 |
+
}
|
619 |
+
|
620 |
+
/**
|
621 |
+
* Edit Term Control.
|
622 |
+
*
|
623 |
+
* Create image control for wp-admin/edit-tag-form.php.
|
624 |
+
* Hooked into the '{$taxonomy}_edit_form_fields' action.
|
625 |
+
*
|
626 |
+
* @param stdClass Term object.
|
627 |
+
* @param string Taxonomy slug.
|
628 |
+
*
|
629 |
+
* @access private
|
630 |
+
* @since 2010-11-08
|
631 |
+
*/
|
632 |
+
function taxonomy_image_plugin_edit_tag_form( $term, $taxonomy ) {
|
633 |
+
$taxonomy = get_taxonomy( $taxonomy );
|
634 |
+
$name = __( 'term', 'taxonomy-images' );
|
635 |
+
if ( isset( $taxonomy->labels->singular_name ) )
|
636 |
+
$name = strtolower( $taxonomy->labels->singular_name );
|
637 |
+
?>
|
638 |
+
<tr class="form-field hide-if-no-js">
|
639 |
+
<th scope="row" valign="top"><label for="description"><?php print esc_html__( 'Featured Image', 'taxonomy-images' ) ?></label></th>
|
640 |
+
<td>
|
641 |
+
<?php print taxonomy_image_plugin_control_image( $term->term_id, $taxonomy->name ); ?>
|
642 |
+
<div class="clear"></div>
|
643 |
+
<span class="description"><?php printf( esc_html__( 'Associate an image from your media library to this %1$s.', 'taxonomy-images' ), esc_html( $name ) ); ?></span>
|
644 |
+
</td>
|
645 |
+
</tr>
|
646 |
+
<?php
|
647 |
+
}
|
648 |
+
|
649 |
+
/**
|
650 |
+
* Image Control.
|
651 |
+
*
|
652 |
+
* Creates all image controls on edit-tags.php.
|
653 |
+
*
|
654 |
+
* @todo Remove rel tag from link... will need to adjust js to accomodate.
|
655 |
+
* @since 0.7
|
656 |
+
* @access private
|
657 |
+
*/
|
658 |
+
function taxonomy_image_plugin_control_image( $term_id, $taxonomy ) {
|
659 |
+
|
660 |
+
$t = new Taxonomy_Images_Term( $term_id, $taxonomy );
|
661 |
+
|
662 |
+
$term = $t->get_term();
|
663 |
+
$tt_id = $t->get_tt_id();
|
664 |
+
|
665 |
+
$taxonomy = get_taxonomy( $t->get_taxonomy() );
|
666 |
+
|
667 |
+
$name = esc_html__( 'term', 'taxonomy-images' );
|
668 |
+
if ( isset( $taxonomy->labels->singular_name ) ) {
|
669 |
+
$name = strtolower( $taxonomy->labels->singular_name );
|
670 |
+
}
|
671 |
+
|
672 |
+
$attachment_id = $t->get_image_id();
|
673 |
+
$hide = $attachment_id ? '' : ' hide';
|
674 |
+
|
675 |
+
$img = taxonomy_image_plugin_get_image_src( $attachment_id );
|
676 |
+
|
677 |
+
$nonce = wp_create_nonce( 'taxonomy-image-plugin-create-association' );
|
678 |
+
$nonce_remove = wp_create_nonce( 'taxonomy-image-plugin-remove-association' );
|
679 |
+
|
680 |
+
$thickbox_class = Taxonomy_Images_Config::supports( 'media_modal' ) ? '' : 'thickbox';
|
681 |
+
|
682 |
+
$o = "\n" . '<div id="' . esc_attr( 'taxonomy-image-control-' . $tt_id ) . '" class="taxonomy-image-control hide-if-no-js">';
|
683 |
+
$o .= "\n" . '<a class="' . $thickbox_class . ' taxonomy-image-thumbnail" data-tt-id="' . $tt_id . '" data-attachment-id="' . $attachment_id . '" data-nonce="' . $nonce . '" 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>';
|
684 |
+
$o .= "\n" . '<a class="control upload ' . $thickbox_class . '" data-tt-id="' . $tt_id . '" data-attachment-id="' . $attachment_id . '" data-nonce="' . $nonce . '" 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>';
|
685 |
+
$o .= "\n" . '<a class="control remove' . $hide . '" data-tt-id="' . $tt_id . '" data-nonce="' . $nonce_remove . '" 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>';
|
686 |
+
$o .= "\n" . '<input type="hidden" class="tt_id" name="' . esc_attr( 'tt_id-' . $tt_id ) . '" value="' . esc_attr( $tt_id ) . '" />';
|
687 |
+
$o .= "\n" . '<input type="hidden" class="image_id" name="' . esc_attr( 'image_id-' . $tt_id ) . '" value="' . esc_attr( $attachment_id ) . '" />';
|
688 |
+
|
689 |
+
if ( isset( $term->name ) && isset( $term->slug ) ) {
|
690 |
+
$o .= "\n" . '<input type="hidden" class="term_name" name="' . esc_attr( 'term_name-' . $term->slug ) . '" value="' . esc_attr( $term->name ) . '" />';
|
691 |
+
}
|
692 |
+
|
693 |
+
$o .= "\n" . '</div>';
|
694 |
+
return $o;
|
695 |
+
}
|
696 |
+
|
697 |
+
/**
|
698 |
+
* Custom javascript for modal media box.
|
699 |
+
*
|
700 |
+
* This script need to be added to all instance of the media upload box.
|
701 |
+
*
|
702 |
+
* @access private
|
703 |
+
*/
|
704 |
+
function taxonomy_image_plugin_media_upload_popup_js() {
|
705 |
+
|
706 |
+
if ( Taxonomy_Images_Config::supports( 'media_modal' ) ) {
|
707 |
+
return;
|
708 |
+
}
|
709 |
+
|
710 |
+
wp_enqueue_script(
|
711 |
+
'taxonomy-images-media-upload-popup',
|
712 |
+
Taxonomy_Images_Config::url( 'js/media-upload-popup.js' ),
|
713 |
+
array( 'jquery' ),
|
714 |
+
Taxonomy_Images_Config::get_version()
|
715 |
+
);
|
716 |
+
wp_localize_script( 'taxonomy-images-media-upload-popup', 'TaxonomyImagesModal', array(
|
717 |
+
'termBefore' => esc_html__( '“', 'taxonomy-images' ),
|
718 |
+
'termAfter' => esc_html__( '”', 'taxonomy-images' ),
|
719 |
+
'associating' => esc_html__( 'Associating …', 'taxonomy-images' ),
|
720 |
+
'success' => esc_html__( 'Successfully Associated', 'taxonomy-images' ),
|
721 |
+
'removing' => esc_html__( 'Removing …', 'taxonomy-images' ),
|
722 |
+
'removed' => esc_html__( 'Successfully Removed', 'taxonomy-images' )
|
723 |
+
) );
|
724 |
+
}
|
725 |
+
|
726 |
+
/**
|
727 |
+
* Custom javascript for wp-admin/edit-tags.php.
|
728 |
+
*
|
729 |
+
* @access private
|
730 |
+
*/
|
731 |
+
function taxonomy_image_plugin_edit_tags_js() {
|
732 |
+
if ( false == taxonomy_image_plugin_is_screen_active() ) {
|
733 |
+
return;
|
734 |
+
}
|
735 |
+
|
736 |
+
if ( Taxonomy_Images_Config::supports( 'media_modal' ) ) {
|
737 |
+
return;
|
738 |
+
}
|
739 |
+
|
740 |
+
wp_enqueue_script(
|
741 |
+
'taxonomy-image-plugin-edit-tags',
|
742 |
+
Taxonomy_Images_Config::url( 'js/edit-tags.js' ),
|
743 |
+
array( 'jquery', 'thickbox' ),
|
744 |
+
Taxonomy_Images_Config::get_version()
|
745 |
+
);
|
746 |
+
wp_localize_script( 'taxonomy-image-plugin-edit-tags', 'taxonomyImagesPlugin', array(
|
747 |
+
'nonce' => wp_create_nonce( 'taxonomy-image-plugin-remove-association' ),
|
748 |
+
'img_src' => Taxonomy_Images_Config::url( 'images/default.png' ),
|
749 |
+
'tt_id' => 0,
|
750 |
+
'image_id' => 0,
|
751 |
+
) );
|
752 |
+
}
|
753 |
+
|
754 |
+
/**
|
755 |
+
* Custom styles.
|
756 |
+
*
|
757 |
+
* @since 0.7
|
758 |
+
* @access private
|
759 |
+
*/
|
760 |
+
function taxonomy_image_plugin_css_admin() {
|
761 |
+
if ( false == taxonomy_image_plugin_is_screen_active() && current_filter() != 'admin_print_styles-media-upload-popup' ) {
|
762 |
+
return;
|
763 |
+
}
|
764 |
+
|
765 |
+
wp_enqueue_style(
|
766 |
+
'taxonomy-image-plugin-edit-tags',
|
767 |
+
Taxonomy_Images_Config::url( 'css/admin.css' ),
|
768 |
+
array(),
|
769 |
+
Taxonomy_Images_Config::get_version(),
|
770 |
+
'screen'
|
771 |
+
);
|
772 |
+
}
|
773 |
+
|
774 |
+
/**
|
775 |
+
* Thickbox styles.
|
776 |
+
*
|
777 |
+
* @since 0.7
|
778 |
+
* @access private
|
779 |
+
*/
|
780 |
+
function taxonomy_image_plugin_css_thickbox() {
|
781 |
+
if ( false == taxonomy_image_plugin_is_screen_active() ) {
|
782 |
+
return;
|
783 |
+
}
|
784 |
+
|
785 |
+
wp_enqueue_style( 'thickbox' );
|
786 |
+
}
|
787 |
+
|
788 |
+
/**
|
789 |
+
* Public Styles.
|
790 |
+
*
|
791 |
+
* Prints custom css to all public pages. If you do not
|
792 |
+
* wish to have these styles included for you, please
|
793 |
+
* insert the following code into your theme's functions.php
|
794 |
+
* file:
|
795 |
+
*
|
796 |
+
* add_filter( 'taxonomy-images-disable-public-css', '__return_true' );
|
797 |
+
*
|
798 |
+
* @since 0.7
|
799 |
+
* @access private
|
800 |
+
*/
|
801 |
+
function taxonomy_image_plugin_css_public() {
|
802 |
+
if ( apply_filters( 'taxonomy-images-disable-public-css', false ) ) {
|
803 |
+
return;
|
804 |
+
}
|
805 |
+
|
806 |
+
wp_enqueue_style(
|
807 |
+
'taxonomy-image-plugin-public',
|
808 |
+
Taxonomy_Images_Config::url( 'css/style.css' ),
|
809 |
+
array(),
|
810 |
+
Taxonomy_Images_Config::get_version(),
|
811 |
+
'screen'
|
812 |
+
);
|
813 |
+
}
|
814 |
+
|
815 |
+
/**
|
816 |
+
* Activation.
|
817 |
+
*
|
818 |
+
* Two entries in the options table will created when this
|
819 |
+
* plugin is activated in the event that they do not exist.
|
820 |
+
*
|
821 |
+
* 'taxonomy_image_plugin' (array) A flat list of all assocaitions
|
822 |
+
* made by this plugin. Keys are integers representing the
|
823 |
+
* term_taxonomy_id of terms. Values are integers representing the
|
824 |
+
* ID property of an image attachment.
|
825 |
+
*
|
826 |
+
* 'taxonomy_image_plugin_settings' (array) A multi-dimensional array
|
827 |
+
* of user-defined settings. As of version 0.7, only one key is used:
|
828 |
+
* 'taxonomies' which is a whitelist of registered taxonomies having ui
|
829 |
+
* that support the custom image ui provided by this plugin.
|
830 |
+
*
|
831 |
+
* @access private
|
832 |
+
* @alter 0.7
|
833 |
+
*/
|
834 |
+
function taxonomy_image_plugin_activate() {
|
835 |
+
$associations = get_option( 'taxonomy_image_plugin' );
|
836 |
+
if ( false === $associations ) {
|
837 |
+
add_option( 'taxonomy_image_plugin', array() );
|
838 |
+
}
|
839 |
+
|
840 |
+
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
841 |
+
if ( false === $settings ) {
|
842 |
+
add_option( 'taxonomy_image_plugin_settings', array(
|
843 |
+
'taxonomies' => array()
|
844 |
+
) );
|
845 |
+
}
|
846 |
+
}
|
847 |
+
|
848 |
+
/**
|
849 |
+
* Is Screen Active?
|
850 |
+
*
|
851 |
+
* @return bool
|
852 |
+
*
|
853 |
+
* @access private
|
854 |
+
* @since 0.7
|
855 |
+
*/
|
856 |
+
function taxonomy_image_plugin_is_screen_active() {
|
857 |
+
$screen = get_current_screen();
|
858 |
+
if ( ! isset( $screen->taxonomy ) ) {
|
859 |
+
return false;
|
860 |
+
}
|
861 |
+
|
862 |
+
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
863 |
+
if ( ! isset( $settings['taxonomies'] ) ) {
|
864 |
+
return false;
|
865 |
+
}
|
866 |
+
|
867 |
+
if ( in_array( $screen->taxonomy, $settings['taxonomies'] ) ) {
|
868 |
+
return true;
|
869 |
+
}
|
870 |
+
|
871 |
+
return false;
|
872 |
+
}
|
873 |
+
|
874 |
+
/**
|
875 |
+
* Cache Images
|
876 |
+
*
|
877 |
+
* Sets the WordPress object cache for all term images
|
878 |
+
* associated to the posts in the provided array. This
|
879 |
+
* function has been created to minimize queries when
|
880 |
+
* using this plugins get_the_terms() style function.
|
881 |
+
*
|
882 |
+
* @param array Post objects.
|
883 |
+
*
|
884 |
+
* @access private
|
885 |
+
* @since 1.1
|
886 |
+
*/
|
887 |
+
function taxonomy_image_plugin_cache_images( $posts ) {
|
888 |
+
|
889 |
+
$assoc = taxonomy_image_plugin_get_associations();
|
890 |
+
if ( empty( $assoc ) ) {
|
891 |
+
return;
|
892 |
+
}
|
893 |
+
|
894 |
+
$image_ids = array();
|
895 |
+
|
896 |
+
foreach ( (array) $posts as $post ) {
|
897 |
+
if ( ! isset( $post->ID ) || ! isset( $post->post_type ) ) {
|
898 |
+
continue;
|
899 |
+
}
|
900 |
+
|
901 |
+
$taxonomies = get_object_taxonomies( $post->post_type );
|
902 |
+
if ( empty( $taxonomies ) ) {
|
903 |
+
continue;
|
904 |
+
}
|
905 |
+
|
906 |
+
foreach ( $taxonomies as $taxonomy ) {
|
907 |
+
$the_terms = get_the_terms( $post->ID, $taxonomy );
|
908 |
+
foreach ( (array) $the_terms as $term ) {
|
909 |
+
|
910 |
+
$t = new Taxonomy_Images_Term( $term );
|
911 |
+
$img = $t->get_image_id();
|
912 |
+
|
913 |
+
if ( $img ) {
|
914 |
+
$image_ids[] = $img;
|
915 |
+
}
|
916 |
+
|
917 |
+
}
|
918 |
+
}
|
919 |
+
}
|
920 |
+
|
921 |
+
$image_ids = array_filter( array_unique( $image_ids ) );
|
922 |
+
|
923 |
+
if ( empty( $image_ids ) ) {
|
924 |
+
return;
|
925 |
+
}
|
926 |
+
|
927 |
+
$images = get_posts( array(
|
928 |
+
'include' => $image_ids,
|
929 |
+
'post_type' => 'attachment'
|
930 |
+
) );
|
931 |
+
|
932 |
+
}
|
933 |
+
|
934 |
+
/**
|
935 |
+
* Cache Images
|
936 |
+
*
|
937 |
+
* Cache all term images associated with posts in
|
938 |
+
* the main WordPress query.
|
939 |
+
*
|
940 |
+
* @param array Post objects.
|
941 |
+
*
|
942 |
+
* @access private
|
943 |
+
* @since 0.7
|
944 |
+
*/
|
945 |
+
function taxonomy_image_plugin_cache_queried_images() {
|
946 |
+
global $posts;
|
947 |
+
taxonomy_image_plugin_cache_images( $posts );
|
948 |
+
}
|
949 |
+
|
950 |
+
/**
|
951 |
+
* Check Taxonomy
|
952 |
+
*
|
953 |
+
* Wrapper for WordPress core functions taxonomy_exists().
|
954 |
+
* In the event that an unregistered taxonomy is passed a
|
955 |
+
* E_USER_NOTICE will be generated.
|
956 |
+
*
|
957 |
+
* @param string Taxonomy name as registered with WordPress.
|
958 |
+
* @param string Name of the current function or filter.
|
959 |
+
* @return bool True if taxonomy exists, False if not.
|
960 |
+
*
|
961 |
+
* @access private
|
962 |
+
* @since 0.7
|
963 |
+
*/
|
964 |
+
function taxonomy_image_plugin_check_taxonomy( $taxonomy, $filter ) {
|
965 |
+
if ( ! taxonomy_exists( $taxonomy ) ) {
|
966 |
+
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' ),
|
967 |
+
'<var>' . esc_html__( 'taxonomy', 'taxonomy-images' ) . '</var>',
|
968 |
+
'<code>' . esc_html( $filter ) . '</code>',
|
969 |
+
'<strong>' . esc_html( $taxonomy ) . '</strong>'
|
970 |
+
) );
|
971 |
+
return false;
|
972 |
+
}
|
973 |
+
|
974 |
+
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
975 |
+
|
976 |
+
if ( ! isset( $settings['taxonomies'] ) ) {
|
977 |
+
trigger_error( sprintf( esc_html__( 'No taxonomies have image support. %1$s', 'taxonomy-images' ), taxonomy_images_plugin_settings_page_link() ) );
|
978 |
+
return false;
|
979 |
+
}
|
980 |
+
|
981 |
+
if ( ! in_array( $taxonomy, (array) $settings['taxonomies'] ) ) {
|
982 |
+
trigger_error( sprintf( esc_html__( 'The %1$s taxonomy does not have image support. %2$s', 'taxonomy-images' ),
|
983 |
+
'<strong>' . esc_html( $taxonomy ) . '</strong>',
|
984 |
+
taxonomy_images_plugin_settings_page_link()
|
985 |
+
) );
|
986 |
+
return false;
|
987 |
+
}
|
988 |
+
|
989 |
+
return true;
|
990 |
+
}
|
991 |
+
|
992 |
+
/**
|
993 |
+
* Plugin Meta Links.
|
994 |
+
*
|
995 |
+
* Add a link to this plugin's setting page when it
|
996 |
+
* displays in the table on wp-admin/plugins.php.
|
997 |
+
*
|
998 |
+
* @param array List of links.
|
999 |
+
* @param string Current plugin being displayed in plugins.php.
|
1000 |
+
* @return array Potentially modified list of links.
|
1001 |
+
*
|
1002 |
+
* @access private
|
1003 |
+
* @since 0.7
|
1004 |
+
*/
|
1005 |
+
function taxonomy_images_plugin_row_meta( $links, $file ) {
|
1006 |
+
|
1007 |
+
$plugin_name = Taxonomy_Images_Config::basename();
|
1008 |
+
|
1009 |
+
if ( $plugin_name != $file ) {
|
1010 |
+
return $links;
|
1011 |
+
}
|
1012 |
+
|
1013 |
+
$link = taxonomy_images_plugin_settings_page_link( esc_html__( 'Settings', 'taxonomy-images' ) );
|
1014 |
+
if ( ! empty( $link ) ) {
|
1015 |
+
$links[] = $link;
|
1016 |
+
}
|
1017 |
+
|
1018 |
+
$links[] = '<a href="http://wordpress.mfields.org/donate/">' . esc_html__( 'Donate', 'taxonomy-images' ) . '</a>';
|
1019 |
+
|
1020 |
+
return $links;
|
1021 |
+
}
|
1022 |
+
|
1023 |
+
/**
|
1024 |
+
* Settings Page Link.
|
1025 |
+
*
|
1026 |
+
* @param array Localized link text.
|
1027 |
+
* @return string HTML link to settings page.
|
1028 |
+
*
|
1029 |
+
* @access private
|
1030 |
+
* @since 0.7
|
1031 |
+
*/
|
1032 |
+
function taxonomy_images_plugin_settings_page_link( $link_text = '' ) {
|
1033 |
+
if ( empty( $link_text ) ) {
|
1034 |
+
$link_text = __( 'Manage Settings', 'taxonomy-images' );
|
1035 |
+
}
|
1036 |
+
|
1037 |
+
$link = '';
|
1038 |
+
if ( current_user_can( 'manage_options' ) ) {
|
1039 |
+
$link = '<a href="' . esc_url( add_query_arg( array( 'page' => 'taxonomy_image_plugin_settings' ), admin_url( 'options-general.php' ) ) ) . '">' . esc_html( $link_text ) . '</a>';
|
1040 |
+
}
|
1041 |
+
|
1042 |
+
return $link;
|
1043 |
+
}
|
1044 |
+
|
1045 |
+
/**
|
1046 |
+
* Enqueue Admin Scripts
|
1047 |
+
*
|
1048 |
+
* @since 0.9
|
1049 |
+
*/
|
1050 |
+
function taxonomy_images_admin_enqueue_scripts() {
|
1051 |
+
|
1052 |
+
if ( false == taxonomy_image_plugin_is_screen_active() ) {
|
1053 |
+
return;
|
1054 |
+
}
|
1055 |
+
|
1056 |
+
if ( ! Taxonomy_Images_Config::supports( 'media_modal' ) ) {
|
1057 |
+
return;
|
1058 |
+
}
|
1059 |
+
|
1060 |
+
wp_enqueue_media();
|
1061 |
+
|
1062 |
+
wp_enqueue_script(
|
1063 |
+
'taxonomy-images-media-modal',
|
1064 |
+
Taxonomy_Images_Config::url( 'js/media-modal.js' ),
|
1065 |
+
array( 'jquery' ),
|
1066 |
+
Taxonomy_Images_Config::get_version()
|
1067 |
+
);
|
1068 |
+
|
1069 |
+
wp_localize_script( 'taxonomy-images-media-modal', 'TaxonomyImagesMediaModal', array(
|
1070 |
+
'wp_media_post_id' => 0,
|
1071 |
+
'attachment_id' => 0,
|
1072 |
+
'uploader_title' => __( 'Featured image', 'taxonomy-images' ),
|
1073 |
+
'uploader_button_text' => __( 'Set featured image', 'taxonomy-images' ),
|
1074 |
+
'default_img_src' => Taxonomy_Images_Config::url( 'images/default.png' )
|
1075 |
+
) );
|
1076 |
+
|
1077 |
+
}
|
public-filters.php → legacy/includes/public-filters.php
RENAMED
@@ -68,10 +68,10 @@ add_filter( 'taxonomy-images-queried-term-image-url', 'taxonomy_images_plugin
|
|
68 |
* @since 0.7
|
69 |
*/
|
70 |
function taxonomy_images_plugin_get_terms( $default, $args = array() ) {
|
|
|
71 |
$filter = 'taxonomy-images-get-terms';
|
72 |
-
|
73 |
-
|
74 |
-
}
|
75 |
|
76 |
$args = wp_parse_args( $args, array(
|
77 |
'cache_images' => true,
|
@@ -103,13 +103,18 @@ function taxonomy_images_plugin_get_terms( $default, $args = array() ) {
|
|
103 |
$terms_with_images = array();
|
104 |
foreach ( (array) $terms as $key => $term ) {
|
105 |
$terms[ $key ]->image_id = 0;
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
109 |
if ( ! empty( $args['having_images'] ) ) {
|
110 |
$terms_with_images[] = $terms[ $key ];
|
111 |
}
|
112 |
}
|
|
|
113 |
}
|
114 |
$image_ids = array_unique( $image_ids );
|
115 |
|
@@ -160,10 +165,10 @@ function taxonomy_images_plugin_get_terms( $default, $args = array() ) {
|
|
160 |
* @since 0.7
|
161 |
*/
|
162 |
function taxonomy_images_plugin_get_the_terms( $default, $args = array() ) {
|
|
|
163 |
$filter = 'taxonomy-images-get-the-terms';
|
164 |
-
|
165 |
-
|
166 |
-
}
|
167 |
|
168 |
$args = wp_parse_args( $args, array(
|
169 |
'having_images' => true,
|
@@ -194,8 +199,12 @@ function taxonomy_images_plugin_get_the_terms( $default, $args = array() ) {
|
|
194 |
$terms_with_images = array();
|
195 |
foreach ( (array) $terms as $key => $term ) {
|
196 |
$terms[ $key ]->image_id = 0;
|
197 |
-
|
198 |
-
|
|
|
|
|
|
|
|
|
199 |
if ( ! empty( $args['having_images'] ) ) {
|
200 |
$terms_with_images[] = $terms[ $key ];
|
201 |
}
|
@@ -250,10 +259,10 @@ function taxonomy_images_plugin_get_the_terms( $default, $args = array() ) {
|
|
250 |
* @since 0.7
|
251 |
*/
|
252 |
function taxonomy_images_plugin_list_the_terms( $default, $args = array() ) {
|
|
|
253 |
$filter = 'taxonomy-images-list-the-terms';
|
254 |
-
|
255 |
-
|
256 |
-
}
|
257 |
|
258 |
$args = wp_parse_args( $args, array(
|
259 |
'after' => '</ul>',
|
@@ -324,10 +333,10 @@ function taxonomy_images_plugin_list_the_terms( $default, $args = array() ) {
|
|
324 |
* @since 0.7
|
325 |
*/
|
326 |
function taxonomy_images_plugin_get_queried_term_image( $default, $args = array() ) {
|
|
|
327 |
$filter = 'taxonomy-images-queried-term-image';
|
328 |
-
|
329 |
-
|
330 |
-
}
|
331 |
|
332 |
$args = wp_parse_args( $args, array(
|
333 |
'after' => '',
|
@@ -374,10 +383,10 @@ function taxonomy_images_plugin_get_queried_term_image( $default, $args = array(
|
|
374 |
* @since 0.7
|
375 |
*/
|
376 |
function taxonomy_images_plugin_get_queried_term_image_id( $default ) {
|
|
|
377 |
$filter = 'taxonomy-images-queried-term-image-id';
|
378 |
-
|
379 |
-
|
380 |
-
}
|
381 |
|
382 |
$obj = get_queried_object();
|
383 |
|
@@ -395,15 +404,10 @@ function taxonomy_images_plugin_get_queried_term_image_id( $default ) {
|
|
395 |
return 0;
|
396 |
}
|
397 |
|
398 |
-
$
|
399 |
-
$tt_id = absint( $obj->term_taxonomy_id );
|
400 |
|
401 |
-
$
|
402 |
-
if ( array_key_exists( $tt_id, $associations ) ) {
|
403 |
-
$ID = absint( $associations[$tt_id] );
|
404 |
-
}
|
405 |
|
406 |
-
return $ID;
|
407 |
}
|
408 |
|
409 |
|
@@ -429,10 +433,10 @@ function taxonomy_images_plugin_get_queried_term_image_id( $default ) {
|
|
429 |
* @since 0.7
|
430 |
*/
|
431 |
function taxonomy_images_plugin_get_queried_term_image_object( $default ) {
|
|
|
432 |
$filter = 'taxonomy-images-queried-term-image-object';
|
433 |
-
|
434 |
-
|
435 |
-
}
|
436 |
|
437 |
$ID = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
|
438 |
|
@@ -469,10 +473,10 @@ function taxonomy_images_plugin_get_queried_term_image_object( $default ) {
|
|
469 |
* @since 0.7
|
470 |
*/
|
471 |
function taxonomy_images_plugin_get_queried_term_image_url( $default, $args = array() ) {
|
|
|
472 |
$filter = 'taxonomy-images-queried-term-image-url';
|
473 |
-
|
474 |
-
|
475 |
-
}
|
476 |
|
477 |
$args = wp_parse_args( $args, array(
|
478 |
'image_size' => 'thumbnail',
|
@@ -515,10 +519,10 @@ function taxonomy_images_plugin_get_queried_term_image_url( $default, $args = ar
|
|
515 |
* @alter 0.7.2
|
516 |
*/
|
517 |
function taxonomy_images_plugin_get_queried_term_image_data( $default, $args = array() ) {
|
|
|
518 |
$filter = 'taxonomy-images-queried-term-image-data';
|
519 |
-
|
520 |
-
|
521 |
-
}
|
522 |
|
523 |
$args = wp_parse_args( $args, array(
|
524 |
'image_size' => 'thumbnail',
|
@@ -530,11 +534,12 @@ function taxonomy_images_plugin_get_queried_term_image_data( $default, $args = a
|
|
530 |
return array();
|
531 |
}
|
532 |
|
533 |
-
$data =
|
534 |
|
535 |
-
if (
|
|
|
536 |
$src = wp_get_attachment_image_src( $ID, 'full' );
|
537 |
-
|
538 |
if ( isset( $src[0] ) ) {
|
539 |
$data['url'] = $src[0];
|
540 |
}
|
@@ -544,8 +549,6 @@ function taxonomy_images_plugin_get_queried_term_image_data( $default, $args = a
|
|
544 |
if ( isset( $src[2] ) ) {
|
545 |
$data['height'] = $src[2];
|
546 |
}
|
547 |
-
} else {
|
548 |
-
$data = image_get_intermediate_size( $ID, $args['image_size'] );
|
549 |
}
|
550 |
|
551 |
if ( ! empty( $data ) ) {
|
@@ -554,3 +557,47 @@ function taxonomy_images_plugin_get_queried_term_image_data( $default, $args = a
|
|
554 |
|
555 |
return array();
|
556 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
* @since 0.7
|
69 |
*/
|
70 |
function taxonomy_images_plugin_get_terms( $default, $args = array() ) {
|
71 |
+
|
72 |
$filter = 'taxonomy-images-get-terms';
|
73 |
+
|
74 |
+
Taxonomy_Images_Public_Filters::check_current_filter( __FUNCTION__, $filter );
|
|
|
75 |
|
76 |
$args = wp_parse_args( $args, array(
|
77 |
'cache_images' => true,
|
103 |
$terms_with_images = array();
|
104 |
foreach ( (array) $terms as $key => $term ) {
|
105 |
$terms[ $key ]->image_id = 0;
|
106 |
+
|
107 |
+
$t = new Taxonomy_Images_Term( $term );
|
108 |
+
$img = $t->get_image_id();
|
109 |
+
|
110 |
+
if ( $img ) {
|
111 |
+
$terms[ $key ]->image_id = $img;
|
112 |
+
$image_ids[] = $img;
|
113 |
if ( ! empty( $args['having_images'] ) ) {
|
114 |
$terms_with_images[] = $terms[ $key ];
|
115 |
}
|
116 |
}
|
117 |
+
|
118 |
}
|
119 |
$image_ids = array_unique( $image_ids );
|
120 |
|
165 |
* @since 0.7
|
166 |
*/
|
167 |
function taxonomy_images_plugin_get_the_terms( $default, $args = array() ) {
|
168 |
+
|
169 |
$filter = 'taxonomy-images-get-the-terms';
|
170 |
+
|
171 |
+
Taxonomy_Images_Public_Filters::check_current_filter( __FUNCTION__, $filter );
|
|
|
172 |
|
173 |
$args = wp_parse_args( $args, array(
|
174 |
'having_images' => true,
|
199 |
$terms_with_images = array();
|
200 |
foreach ( (array) $terms as $key => $term ) {
|
201 |
$terms[ $key ]->image_id = 0;
|
202 |
+
|
203 |
+
$t = new Taxonomy_Images_Term( $term );
|
204 |
+
$img = $t->get_image_id();
|
205 |
+
|
206 |
+
if ( $img ) {
|
207 |
+
$terms[ $key ]->image_id = $img;
|
208 |
if ( ! empty( $args['having_images'] ) ) {
|
209 |
$terms_with_images[] = $terms[ $key ];
|
210 |
}
|
259 |
* @since 0.7
|
260 |
*/
|
261 |
function taxonomy_images_plugin_list_the_terms( $default, $args = array() ) {
|
262 |
+
|
263 |
$filter = 'taxonomy-images-list-the-terms';
|
264 |
+
|
265 |
+
Taxonomy_Images_Public_Filters::check_current_filter( __FUNCTION__, $filter );
|
|
|
266 |
|
267 |
$args = wp_parse_args( $args, array(
|
268 |
'after' => '</ul>',
|
333 |
* @since 0.7
|
334 |
*/
|
335 |
function taxonomy_images_plugin_get_queried_term_image( $default, $args = array() ) {
|
336 |
+
|
337 |
$filter = 'taxonomy-images-queried-term-image';
|
338 |
+
|
339 |
+
Taxonomy_Images_Public_Filters::check_current_filter( __FUNCTION__, $filter );
|
|
|
340 |
|
341 |
$args = wp_parse_args( $args, array(
|
342 |
'after' => '',
|
383 |
* @since 0.7
|
384 |
*/
|
385 |
function taxonomy_images_plugin_get_queried_term_image_id( $default ) {
|
386 |
+
|
387 |
$filter = 'taxonomy-images-queried-term-image-id';
|
388 |
+
|
389 |
+
Taxonomy_Images_Public_Filters::check_current_filter( __FUNCTION__, $filter );
|
|
|
390 |
|
391 |
$obj = get_queried_object();
|
392 |
|
404 |
return 0;
|
405 |
}
|
406 |
|
407 |
+
$t = new Taxonomy_Images_Term( $obj );
|
|
|
408 |
|
409 |
+
return $img = $t->get_image_id();
|
|
|
|
|
|
|
410 |
|
|
|
411 |
}
|
412 |
|
413 |
|
433 |
* @since 0.7
|
434 |
*/
|
435 |
function taxonomy_images_plugin_get_queried_term_image_object( $default ) {
|
436 |
+
|
437 |
$filter = 'taxonomy-images-queried-term-image-object';
|
438 |
+
|
439 |
+
Taxonomy_Images_Public_Filters::check_current_filter( __FUNCTION__, $filter );
|
|
|
440 |
|
441 |
$ID = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
|
442 |
|
473 |
* @since 0.7
|
474 |
*/
|
475 |
function taxonomy_images_plugin_get_queried_term_image_url( $default, $args = array() ) {
|
476 |
+
|
477 |
$filter = 'taxonomy-images-queried-term-image-url';
|
478 |
+
|
479 |
+
Taxonomy_Images_Public_Filters::check_current_filter( __FUNCTION__, $filter );
|
|
|
480 |
|
481 |
$args = wp_parse_args( $args, array(
|
482 |
'image_size' => 'thumbnail',
|
519 |
* @alter 0.7.2
|
520 |
*/
|
521 |
function taxonomy_images_plugin_get_queried_term_image_data( $default, $args = array() ) {
|
522 |
+
|
523 |
$filter = 'taxonomy-images-queried-term-image-data';
|
524 |
+
|
525 |
+
Taxonomy_Images_Public_Filters::check_current_filter( __FUNCTION__, $filter );
|
|
|
526 |
|
527 |
$args = wp_parse_args( $args, array(
|
528 |
'image_size' => 'thumbnail',
|
534 |
return array();
|
535 |
}
|
536 |
|
537 |
+
$data = image_get_intermediate_size( $ID, $args['image_size'] );
|
538 |
|
539 |
+
if ( empty( $data ) ) {
|
540 |
+
|
541 |
$src = wp_get_attachment_image_src( $ID, 'full' );
|
542 |
+
|
543 |
if ( isset( $src[0] ) ) {
|
544 |
$data['url'] = $src[0];
|
545 |
}
|
549 |
if ( isset( $src[2] ) ) {
|
550 |
$data['height'] = $src[2];
|
551 |
}
|
|
|
|
|
552 |
}
|
553 |
|
554 |
if ( ! empty( $data ) ) {
|
557 |
|
558 |
return array();
|
559 |
}
|
560 |
+
|
561 |
+
/**
|
562 |
+
* Public Filters Class
|
563 |
+
*/
|
564 |
+
class Taxonomy_Images_Public_Filters {
|
565 |
+
|
566 |
+
/**
|
567 |
+
* Check Current Filter
|
568 |
+
*
|
569 |
+
* Check that the user is not directly calling a function instead
|
570 |
+
* of using supported filters.
|
571 |
+
*
|
572 |
+
* @internal Private. Use of this method is unsupported. Do not call this method directly.
|
573 |
+
*
|
574 |
+
* @param string $function Name of function called.
|
575 |
+
* @param string $filter Name of filter to use instead.
|
576 |
+
*/
|
577 |
+
public static function check_current_filter( $function, $filter ) {
|
578 |
+
|
579 |
+
if ( current_filter() !== $filter ) {
|
580 |
+
self::please_use_filter( $function, $filter );
|
581 |
+
}
|
582 |
+
|
583 |
+
}
|
584 |
+
|
585 |
+
/**
|
586 |
+
* Please Use Filter
|
587 |
+
*
|
588 |
+
* Report to user that they are directly calling a function instead
|
589 |
+
* of using supported filters. A E_USER_NOTICE will be generated.
|
590 |
+
*
|
591 |
+
* @param string $function Name of function called.
|
592 |
+
* @param string $filter Name of filter to use instead.
|
593 |
+
*/
|
594 |
+
private static function please_use_filter( $function, $filter ) {
|
595 |
+
|
596 |
+
trigger_error( sprintf( esc_html__( 'The %1$s has been called directly. Please use the %2$s filter instead.', 'taxonomy-images' ),
|
597 |
+
'<code>' . esc_html( $function . '()' ) . '</code>',
|
598 |
+
'<code>' . esc_html( $filter ) . '</code>'
|
599 |
+
) );
|
600 |
+
|
601 |
+
}
|
602 |
+
|
603 |
+
}
|
legacy/includes/term.php
ADDED
@@ -0,0 +1,284 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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interface for term taxonomy image data.
|
7 |
+
*
|
8 |
+
* @internal Do not use this class directly. It is intended for internal use
|
9 |
+
* only and external use is unsupported. Methods may be subject to
|
10 |
+
* change without backward compatibility. Instead use the public
|
11 |
+
* filters that can be found in `public-filters.php`.
|
12 |
+
*/
|
13 |
+
class Taxonomy_Images_Term {
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Term
|
17 |
+
*
|
18 |
+
* @var null|WP_Term
|
19 |
+
*/
|
20 |
+
private $term = null;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Term ID
|
24 |
+
*
|
25 |
+
* @var null|int
|
26 |
+
*/
|
27 |
+
private $term_id = null;
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Taxonomy
|
31 |
+
*
|
32 |
+
* @var null|string
|
33 |
+
*/
|
34 |
+
private $taxonomy = null;
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Term Taxonomy ID
|
38 |
+
*
|
39 |
+
* Used for backwards-compatibility with
|
40 |
+
* options data storage.
|
41 |
+
*
|
42 |
+
* @var null|int
|
43 |
+
*/
|
44 |
+
private $tt_id = null;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Cache of terms indexed by tt_id
|
48 |
+
*
|
49 |
+
* @var array
|
50 |
+
*/
|
51 |
+
private static $cache = array();
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Construct Term Instance
|
55 |
+
*
|
56 |
+
* Store term identifiers. If only limited identifiers are set
|
57 |
+
* i.e. only term taxonomy ID - then gaps will be filled as requested
|
58 |
+
* by class methods to help with caching.
|
59 |
+
*
|
60 |
+
* @param int|WP_Term $term Term object, term ID, or term taxonomy ID if $taxonomy is true.
|
61 |
+
* @param boolean|string $taxonomy Optional. Taxonomy of true if first $term parameter is a tt_id.
|
62 |
+
*/
|
63 |
+
public function __construct( $term, $taxonomy = false ) {
|
64 |
+
|
65 |
+
if ( $this->is_term_object( $term ) ) {
|
66 |
+
|
67 |
+
// Set term object vars
|
68 |
+
$this->term = $term;
|
69 |
+
$this->term_id = $term->term_id;
|
70 |
+
$this->taxonomy = $term->taxonomy;
|
71 |
+
$this->tt_id = $term->term_taxonomy_id;
|
72 |
+
|
73 |
+
} elseif ( is_numeric( $term ) ) {
|
74 |
+
|
75 |
+
$term = absint( $term );
|
76 |
+
|
77 |
+
if ( true === $taxonomy ) {
|
78 |
+
|
79 |
+
// Set term taxonomy ID
|
80 |
+
$this->tt_id = $term;
|
81 |
+
|
82 |
+
} else {
|
83 |
+
|
84 |
+
// Set term ID and taxonomy
|
85 |
+
$this->term_id = $term;
|
86 |
+
$this->taxonomy = ! empty( $taxonomy ) ? $taxonomy : '';
|
87 |
+
|
88 |
+
}
|
89 |
+
|
90 |
+
}
|
91 |
+
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Is term object
|
96 |
+
*
|
97 |
+
* @param mixed $term Data to check if term object.
|
98 |
+
* @return boolean
|
99 |
+
*/
|
100 |
+
private function is_term_object( $term ) {
|
101 |
+
|
102 |
+
// WP_Term
|
103 |
+
if ( is_a( $term, 'WP_Term' ) ) {
|
104 |
+
return true;
|
105 |
+
}
|
106 |
+
|
107 |
+
// Legacy term object
|
108 |
+
if ( is_object( $term ) && isset( $term->term_id ) && isset( $term->taxonomy ) && isset( $term->term_taxonomy_id ) ) {
|
109 |
+
return true;
|
110 |
+
}
|
111 |
+
|
112 |
+
return false;
|
113 |
+
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Get Taxonomy
|
118 |
+
*
|
119 |
+
* If taxonomy is not stored it will be fetched
|
120 |
+
* via the get_terms() method.
|
121 |
+
*
|
122 |
+
* @return string Taxonomy
|
123 |
+
*/
|
124 |
+
public function get_taxonomy() {
|
125 |
+
|
126 |
+
if ( ! is_null( $this->taxonomy ) ) {
|
127 |
+
return $this->taxonomy;
|
128 |
+
}
|
129 |
+
|
130 |
+
$term = $this->get_term();
|
131 |
+
|
132 |
+
return $this->taxonomy;
|
133 |
+
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Get Term Taxonomy ID
|
138 |
+
*
|
139 |
+
* If term taxonomy ID is not stored it will
|
140 |
+
* be fetched via the get_terms() method.
|
141 |
+
*
|
142 |
+
* @return int Term Taxonomy ID.
|
143 |
+
*/
|
144 |
+
public function get_tt_id() {
|
145 |
+
|
146 |
+
if ( is_null( $this->tt_id ) ) {
|
147 |
+
$term = $this->get_term();
|
148 |
+
}
|
149 |
+
|
150 |
+
return is_null( $this->tt_id ) ? 0 : $this->tt_id;
|
151 |
+
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Get Term
|
156 |
+
*
|
157 |
+
* If term object is not stored it will be fetched via
|
158 |
+
* the term ID if available, otherwise falling back to fetching
|
159 |
+
* manually from the database via the term taxonomy ID.
|
160 |
+
*
|
161 |
+
* @return WP_Term Term object.
|
162 |
+
*/
|
163 |
+
public function get_term() {
|
164 |
+
|
165 |
+
global $wpdb;
|
166 |
+
|
167 |
+
// Get term
|
168 |
+
if ( ! is_null( $this->term ) ) {
|
169 |
+
return $this->term;
|
170 |
+
}
|
171 |
+
|
172 |
+
// Get term via term ID
|
173 |
+
if ( ! is_null( $this->term_id ) ) {
|
174 |
+
$this->term = get_term( $this->term_id, $this->taxonomy );
|
175 |
+
$this->tt_id = $this->term->term_taxonomy_id;
|
176 |
+
return $this->term;
|
177 |
+
}
|
178 |
+
|
179 |
+
// Get term via term taxonomy ID
|
180 |
+
if ( ! is_null( $this->tt_id ) ) {
|
181 |
+
|
182 |
+
if ( isset( self::$cache[ $this->tt_id ] ) ) {
|
183 |
+
return self::$cache[ $this->tt_id ];
|
184 |
+
}
|
185 |
+
|
186 |
+
$data = current( $wpdb->get_results( $wpdb->prepare( "SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d LIMIT 1", $this->tt_id ) ) );
|
187 |
+
|
188 |
+
if ( $data ) {
|
189 |
+
$this->term_id = $data->term_id;
|
190 |
+
$this->taxonomy = $data->taxonomy;
|
191 |
+
$this->term = get_term( $this->term_id, $this->taxonomy );
|
192 |
+
|
193 |
+
self::$cache[ $this->tt_id ] = $this->term;
|
194 |
+
|
195 |
+
}
|
196 |
+
|
197 |
+
}
|
198 |
+
|
199 |
+
return null;
|
200 |
+
|
201 |
+
}
|
202 |
+
|
203 |
+
/**
|
204 |
+
* Get Image ID
|
205 |
+
*
|
206 |
+
* @return integer Image ID.
|
207 |
+
*/
|
208 |
+
public function get_image_id() {
|
209 |
+
|
210 |
+
$assoc = taxonomy_image_plugin_get_associations();
|
211 |
+
|
212 |
+
if ( isset( $assoc[ $this->get_tt_id() ] ) ) {
|
213 |
+
return $assoc[ $this->get_tt_id() ];
|
214 |
+
}
|
215 |
+
|
216 |
+
return 0;
|
217 |
+
|
218 |
+
}
|
219 |
+
|
220 |
+
/**
|
221 |
+
* Add Image ID
|
222 |
+
*
|
223 |
+
* @param integer $id Image ID.
|
224 |
+
* @return boolean
|
225 |
+
*/
|
226 |
+
public function add_image_id( $id ) {
|
227 |
+
|
228 |
+
}
|
229 |
+
|
230 |
+
/**
|
231 |
+
* Current User Can Edit
|
232 |
+
*
|
233 |
+
* @return boolean
|
234 |
+
*/
|
235 |
+
public function current_user_can_edit() {
|
236 |
+
|
237 |
+
$tax = $this->get_taxonomy();
|
238 |
+
|
239 |
+
if ( empty( $tax ) ) {
|
240 |
+
return false;
|
241 |
+
}
|
242 |
+
|
243 |
+
$taxonomy = get_taxonomy( $tax );
|
244 |
+
if ( ! isset( $taxonomy->cap->edit_terms ) ) {
|
245 |
+
return false;
|
246 |
+
}
|
247 |
+
|
248 |
+
return current_user_can( $taxonomy->cap->edit_terms );
|
249 |
+
|
250 |
+
}
|
251 |
+
|
252 |
+
/**
|
253 |
+
* Update Image ID
|
254 |
+
*
|
255 |
+
* @param integer $id Image ID.
|
256 |
+
* @return boolean
|
257 |
+
*/
|
258 |
+
public function update_image_id( $id ) {
|
259 |
+
|
260 |
+
$assoc = taxonomy_image_plugin_get_associations();
|
261 |
+
$assoc[ $this->get_tt_id() ] = $id;
|
262 |
+
|
263 |
+
return update_option( 'taxonomy_image_plugin', taxonomy_image_plugin_sanitize_associations( $assoc ) );
|
264 |
+
|
265 |
+
}
|
266 |
+
|
267 |
+
/**
|
268 |
+
* Delete Image ID
|
269 |
+
*
|
270 |
+
* @return boolean
|
271 |
+
*/
|
272 |
+
public function delete_image_id() {
|
273 |
+
|
274 |
+
$assoc = taxonomy_image_plugin_get_associations();
|
275 |
+
|
276 |
+
if ( isset( $assoc[ $this->get_tt_id() ] ) ) {
|
277 |
+
unset( $assoc[ $this->get_tt_id() ] );
|
278 |
+
}
|
279 |
+
|
280 |
+
return update_option( 'taxonomy_image_plugin', $assoc );
|
281 |
+
|
282 |
+
}
|
283 |
+
|
284 |
+
}
|
legacy/plugin.php
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @package Taxononomy Images
|
5 |
+
* @subpackage Plugin
|
6 |
+
*/
|
7 |
+
|
8 |
+
if ( ! function_exists( 'add_filter' ) ) {
|
9 |
+
header( 'Status: 403 Forbidden' );
|
10 |
+
header( 'HTTP/1.1 403 Forbidden' );
|
11 |
+
exit();
|
12 |
+
}
|
13 |
+
|
14 |
+
require_once( trailingslashit( dirname( TAXONOMY_IMAGES_FILE ) ) . 'legacy/includes/config.php' );
|
15 |
+
|
16 |
+
Taxonomy_Images_Config::set_version( '0.9.6' );
|
17 |
+
Taxonomy_Images_Config::set_plugin_file( TAXONOMY_IMAGES_FILE );
|
18 |
+
|
19 |
+
require_once( trailingslashit( dirname( TAXONOMY_IMAGES_FILE ) ) . 'legacy/includes/term.php' );
|
20 |
+
require_once( trailingslashit( dirname( TAXONOMY_IMAGES_FILE ) ) . 'legacy/includes/public-filters.php' );
|
21 |
+
require_once( trailingslashit( dirname( TAXONOMY_IMAGES_FILE ) ) . 'legacy/includes/functions.php' );
|
22 |
+
require_once( trailingslashit( dirname( TAXONOMY_IMAGES_FILE ) ) . 'legacy/includes/deprecated.php' );
|
23 |
+
|
24 |
+
// Register custom image size with WordPress.
|
25 |
+
add_action( 'init', 'taxonomy_image_plugin_add_image_size' );
|
26 |
+
|
27 |
+
// Load Plugin Text Domain.
|
28 |
+
add_action( 'init', 'taxonomy_image_plugin_text_domain' );
|
29 |
+
|
30 |
+
// Modal Button.
|
31 |
+
add_filter( 'attachment_fields_to_edit', 'taxonomy_image_plugin_modal_button', 20, 2 );
|
32 |
+
|
33 |
+
// Register settings with WordPress.
|
34 |
+
add_action( 'admin_init', 'taxonomy_image_plugin_register_settings' );
|
35 |
+
|
36 |
+
// Admin Menu.
|
37 |
+
add_action( 'admin_menu', 'taxonomy_images_settings_menu' );
|
38 |
+
|
39 |
+
// Create an association.
|
40 |
+
add_action( 'wp_ajax_taxonomy_image_create_association', 'taxonomy_image_plugin_create_association' );
|
41 |
+
|
42 |
+
// Remove an association.
|
43 |
+
add_action( 'wp_ajax_taxonomy_image_plugin_remove_association', 'taxonomy_image_plugin_remove_association' );
|
44 |
+
|
45 |
+
// Get a list of user-defined associations.
|
46 |
+
add_action( 'init', 'taxonomy_image_plugin_get_associations' );
|
47 |
+
|
48 |
+
// Dynamically create hooks for each taxonomy.
|
49 |
+
add_action( 'admin_init', 'taxonomy_image_plugin_add_dynamic_hooks' );
|
50 |
+
|
51 |
+
// Custom javascript for modal media box.
|
52 |
+
add_action( 'admin_print_scripts-media-upload-popup', 'taxonomy_image_plugin_media_upload_popup_js' );
|
53 |
+
|
54 |
+
// Custom javascript for wp-admin/edit-tags.php.
|
55 |
+
add_action( 'admin_print_scripts-edit-tags.php', 'taxonomy_image_plugin_edit_tags_js' );
|
56 |
+
|
57 |
+
// Custom styles.
|
58 |
+
add_action( 'admin_print_styles-edit-tags.php', 'taxonomy_image_plugin_css_admin' ); // Pre WordPress 4.5
|
59 |
+
add_action( 'admin_print_styles-term.php', 'taxonomy_image_plugin_css_admin' ); // WordPress 4.5+
|
60 |
+
add_action( 'admin_print_styles-media-upload-popup', 'taxonomy_image_plugin_css_admin' );
|
61 |
+
|
62 |
+
// Thickbox styles.
|
63 |
+
add_action( 'admin_print_styles-edit-tags.php', 'taxonomy_image_plugin_css_thickbox' );
|
64 |
+
|
65 |
+
// Public Styles.
|
66 |
+
add_action( 'wp_enqueue_scripts', 'taxonomy_image_plugin_css_public' );
|
67 |
+
|
68 |
+
// Activation.
|
69 |
+
register_activation_hook( __FILE__, 'taxonomy_image_plugin_activate' );
|
70 |
+
|
71 |
+
// Cache Images.
|
72 |
+
add_action( 'template_redirect', 'taxonomy_image_plugin_cache_queried_images' );
|
73 |
+
|
74 |
+
// Plugin Meta Links.
|
75 |
+
add_filter( 'plugin_row_meta', 'taxonomy_images_plugin_row_meta', 10, 2 );
|
76 |
+
|
77 |
+
// Enqueue Admin Scripts.
|
78 |
+
add_action( 'admin_enqueue_scripts', 'taxonomy_images_admin_enqueue_scripts' );
|
plugin/assets/css/admin.css
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
.taxonomy-image-thumbnail {
|
3 |
+
display: block;
|
4 |
+
margin-bottom: 3px;
|
5 |
+
overflow: hidden;
|
6 |
+
text-align: center;
|
7 |
+
width: 75px;
|
8 |
+
height: 75px;
|
9 |
+
}
|
10 |
+
|
11 |
+
.taxonomy-image-thumbnail img {
|
12 |
+
width: 75px;
|
13 |
+
height: 75px;
|
14 |
+
}
|
15 |
+
|
16 |
+
.taxonomy-image-thumbnail-large {
|
17 |
+
width: 120px;
|
18 |
+
height: 120px;
|
19 |
+
}
|
20 |
+
|
21 |
+
.taxonomy-image-thumbnail-large img {
|
22 |
+
width: 120px;
|
23 |
+
height: 120px;
|
24 |
+
}
|
25 |
+
|
26 |
+
.taxonomy-image-control .control {
|
27 |
+
background-color: #b3b9bf;
|
28 |
+
border-radius: 50%;
|
29 |
+
cursor: pointer;
|
30 |
+
display: block;
|
31 |
+
float: left;
|
32 |
+
margin: 0 3px 3px 0;
|
33 |
+
overflow: hidden;
|
34 |
+
position: relative;
|
35 |
+
text-indent: -9999em;
|
36 |
+
width: 12px;
|
37 |
+
height: 12px;
|
38 |
+
}
|
39 |
+
|
40 |
+
.taxonomy-image-control .upload:hover {
|
41 |
+
background-color: #00a2d7;
|
42 |
+
}
|
43 |
+
|
44 |
+
.taxonomy-image-control .remove:hover {
|
45 |
+
background-color: #d00;
|
46 |
+
}
|
47 |
+
|
48 |
+
.taxonomy-image-control .upload::before,
|
49 |
+
.taxonomy-image-control .remove::before,
|
50 |
+
.taxonomy-image-control .upload::after {
|
51 |
+
display: block;
|
52 |
+
content: ' ';
|
53 |
+
position: absolute;
|
54 |
+
}
|
55 |
+
|
56 |
+
.taxonomy-image-control .upload::before,
|
57 |
+
.taxonomy-image-control .remove::before {
|
58 |
+
border-top: 2px solid #fff;
|
59 |
+
width: 8px;
|
60 |
+
top: 5px;
|
61 |
+
left: 2px;
|
62 |
+
}
|
63 |
+
|
64 |
+
.taxonomy-image-control .upload::after {
|
65 |
+
border-left: 2px solid #fff;
|
66 |
+
height: 8px;
|
67 |
+
top: 2px;
|
68 |
+
left: 5px;
|
69 |
+
}
|
70 |
+
|
71 |
+
.taxonomy-image-control .hide {
|
72 |
+
visibility: hidden;
|
73 |
+
}
|
74 |
+
|
75 |
+
.taxonomy-image-control .show {
|
76 |
+
visibility: visible;
|
77 |
+
}
|
plugin/assets/css/theme.css
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
.taxonomy-images-the-terms {
|
3 |
+
margin: 10px 0;
|
4 |
+
padding: 0;
|
5 |
+
zoom: 1;
|
6 |
+
}
|
7 |
+
|
8 |
+
.taxonomy-images-the-terms:before,
|
9 |
+
.taxonomy-images-the-terms:after {
|
10 |
+
clear: both;
|
11 |
+
content: "\0020";
|
12 |
+
display: block;
|
13 |
+
height: 0;
|
14 |
+
visibility: hidden;
|
15 |
+
}
|
16 |
+
|
17 |
+
.taxonomy-images-the-terms li,
|
18 |
+
.taxonomy-images-the-terms a,
|
19 |
+
.taxonomy-images-the-terms img {
|
20 |
+
float: left;
|
21 |
+
margin: 0;
|
22 |
+
padding: 0;
|
23 |
+
}
|
24 |
+
|
25 |
+
.taxonomy-images-the-terms li {
|
26 |
+
list-style-type: none;
|
27 |
+
margin: 0 10px 10px 0;
|
28 |
+
}
|
plugin/assets/images/blank.png
ADDED
Binary file
|
plugin/assets/images/default.png
ADDED
Binary file
|
plugin/assets/js/media-modal.js
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
// Media Modal Frame
|
3 |
+
var taxonomy_images_file_frame;
|
4 |
+
|
5 |
+
( function( $ ) {
|
6 |
+
|
7 |
+
$( document ).ready( function() {
|
8 |
+
|
9 |
+
// Store the old id (not sure if this is application when editing a term)
|
10 |
+
TaxonomyImagesMediaModal.termID = 0;
|
11 |
+
TaxonomyImagesMediaModal.imageType = '';
|
12 |
+
|
13 |
+
// When the remove icon is clicked...
|
14 |
+
$( '.wp-list-table, .form-table' ).on( 'click', '.taxonomy-image-control a.remove', function( event ) {
|
15 |
+
|
16 |
+
event.preventDefault();
|
17 |
+
|
18 |
+
var term_id = $( this ).data( 'term-id' );
|
19 |
+
var image_type = $( this ).data( 'image-type' );
|
20 |
+
|
21 |
+
$.ajax( {
|
22 |
+
url : ajaxurl,
|
23 |
+
type : 'POST',
|
24 |
+
dataType : 'json',
|
25 |
+
data : {
|
26 |
+
'action' : 'taxonomy_images_delete_term_image',
|
27 |
+
'wp_nonce' : $( this ).data( 'nonce' ),
|
28 |
+
'term_id' : $( this ).data( 'term-id' ),
|
29 |
+
'image_type' : $( this ).data( 'image-type' )
|
30 |
+
},
|
31 |
+
cache : false,
|
32 |
+
success : function ( response ) {
|
33 |
+
if ( 'good' === response.status ) {
|
34 |
+
|
35 |
+
selector = $( '#taxonomy-image-control-' + image_type + '-' + term_id );
|
36 |
+
|
37 |
+
/* Update the image on the screen below */
|
38 |
+
selector.find( '.taxonomy-image-thumbnail img' ).attr( 'src', TaxonomyImagesMediaModal.default_img_src );
|
39 |
+
|
40 |
+
selector.find( 'a.taxonomy-image-thumbnail' ).data( 'attachment-id', 0 );
|
41 |
+
selector.find( 'a.upload' ).data( 'attachment-id', 0 );
|
42 |
+
|
43 |
+
/* Show delete control on the screen below */
|
44 |
+
selector.find( '.remove' ).addClass( 'hide' );
|
45 |
+
|
46 |
+
}
|
47 |
+
else if ( 'bad' === response.status ) {
|
48 |
+
alert( response.why );
|
49 |
+
}
|
50 |
+
}
|
51 |
+
} );
|
52 |
+
|
53 |
+
} );
|
54 |
+
|
55 |
+
// When image or upload icon clicked...
|
56 |
+
$( '.wp-list-table, .form-table' ).on( 'click', '.taxonomy-image-control a.upload, .taxonomy-image-control a.taxonomy-image-thumbnail', function( event ) {
|
57 |
+
|
58 |
+
event.preventDefault();
|
59 |
+
|
60 |
+
button = $( this );
|
61 |
+
|
62 |
+
TaxonomyImagesMediaModal.termID = $( this ).data( 'term-id' );
|
63 |
+
TaxonomyImagesMediaModal.imageType = $( this ).data( 'image-type' );
|
64 |
+
TaxonomyImagesMediaModal.attachment_id = $( this ).data( 'attachment-id' );
|
65 |
+
TaxonomyImagesMediaModal.nonce = $( this ).data( 'nonce' );
|
66 |
+
|
67 |
+
// If the media frame already exists, reopen it.
|
68 |
+
if ( taxonomy_images_file_frame ) {
|
69 |
+
|
70 |
+
// Set the post ID to the term being edited and open
|
71 |
+
taxonomy_images_file_frame.open();
|
72 |
+
return;
|
73 |
+
|
74 |
+
} else {
|
75 |
+
|
76 |
+
// Set the wp.media post id so the uploader grabs the term ID being edited
|
77 |
+
TaxonomyImagesMediaModal.termID = $( this ).data( 'term-id' );
|
78 |
+
TaxonomyImagesMediaModal.imageType = $( this ).data( 'image-type' );
|
79 |
+
|
80 |
+
}
|
81 |
+
|
82 |
+
// Create the media frame.
|
83 |
+
taxonomy_images_file_frame = wp.media.frames.taxonomy_images_file_frame = wp.media( {
|
84 |
+
title : TaxonomyImagesMediaModal.uploader_title,
|
85 |
+
button : { text : TaxonomyImagesMediaModal.uploader_button_text },
|
86 |
+
library : { type: 'image' },
|
87 |
+
multiple : false
|
88 |
+
} );
|
89 |
+
|
90 |
+
// Pre-select selected attachment
|
91 |
+
wp.media.frames.taxonomy_images_file_frame.on( 'open', function() {
|
92 |
+
var selection = wp.media.frames.taxonomy_images_file_frame.state().get( 'selection' );
|
93 |
+
var selected_id = TaxonomyImagesMediaModal.attachment_id;
|
94 |
+
if ( selected_id > 0 ) {
|
95 |
+
attachment = wp.media.attachment( selected_id );
|
96 |
+
attachment.fetch();
|
97 |
+
selection.add( attachment ? [ attachment ] : [] );
|
98 |
+
}
|
99 |
+
} );
|
100 |
+
|
101 |
+
// When an image is selected, run a callback.
|
102 |
+
taxonomy_images_file_frame.on( 'select', function() {
|
103 |
+
|
104 |
+
// We set multiple to false so only get one image from the uploader
|
105 |
+
attachment = taxonomy_images_file_frame.state().get( 'selection' ).first().toJSON();
|
106 |
+
|
107 |
+
var term_id = TaxonomyImagesMediaModal.termID;
|
108 |
+
var image_type = TaxonomyImagesMediaModal.imageType;
|
109 |
+
var attachment_id = attachment.id;
|
110 |
+
|
111 |
+
// Do something with attachment.id and/or attachment.url here
|
112 |
+
$.ajax( {
|
113 |
+
url : ajaxurl,
|
114 |
+
type : 'POST',
|
115 |
+
dataType : 'json',
|
116 |
+
data : {
|
117 |
+
'action' : 'taxonomy_images_update_term_image',
|
118 |
+
'wp_nonce' : TaxonomyImagesMediaModal.nonce,
|
119 |
+
'attachment_id' : attachment.id,
|
120 |
+
'term_id' : parseInt( TaxonomyImagesMediaModal.termID ),
|
121 |
+
'image_type' : TaxonomyImagesMediaModal.imageType
|
122 |
+
},
|
123 |
+
success : function ( response ) {
|
124 |
+
if ( 'good' === response.status ) {
|
125 |
+
var parent_id = button.parent().attr( 'id' );
|
126 |
+
|
127 |
+
/* Set state of all other buttons. */
|
128 |
+
$( '.taxonomy-image-modal-control' ).each( function( i, e ) {
|
129 |
+
if ( parent_id == $( e ).attr( 'id' ) ) {
|
130 |
+
return true;
|
131 |
+
}
|
132 |
+
$( e ).find( '.create-association' ).show();
|
133 |
+
$( e ).find( '.remove-association' ).hide();
|
134 |
+
} );
|
135 |
+
|
136 |
+
selector = $( '#taxonomy-image-control-' + image_type + '-' + term_id );
|
137 |
+
|
138 |
+
/* Update the image on the screen below */
|
139 |
+
selector.find( '.taxonomy-image-thumbnail img' ).attr( 'src', response.attachment_thumb_src );
|
140 |
+
|
141 |
+
selector.find( 'a.taxonomy-image-thumbnail' ).data( 'attachment-id', attachment_id );
|
142 |
+
selector.find( 'a.upload' ).data( 'attachment-id', attachment_id );
|
143 |
+
|
144 |
+
/* Show delete control on the screen below */
|
145 |
+
$( selector ).find( '.remove' ).each( function ( i, e ) {
|
146 |
+
$( e ).removeClass( 'hide' );
|
147 |
+
} );
|
148 |
+
|
149 |
+
}
|
150 |
+
else if ( 'bad' === response.status ) {
|
151 |
+
alert( response.why );
|
152 |
+
}
|
153 |
+
}
|
154 |
+
} );
|
155 |
+
|
156 |
+
} );
|
157 |
+
|
158 |
+
// Finally, open the modal
|
159 |
+
taxonomy_images_file_frame.open();
|
160 |
+
|
161 |
+
} );
|
162 |
+
|
163 |
+
} );
|
164 |
+
|
165 |
+
} )( jQuery );
|
plugin/includes/cache-class.php
ADDED
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @package Taxonomy Images
|
5 |
+
* @subpackage Cache
|
6 |
+
*/
|
7 |
+
|
8 |
+
namespace Plugins\Taxonomy_Images;
|
9 |
+
|
10 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
11 |
+
|
12 |
+
class Cache {
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Cache Queried Images
|
16 |
+
*
|
17 |
+
* Cache all term images associated with posts in
|
18 |
+
* the main WordPress query.
|
19 |
+
*
|
20 |
+
* @param array Post objects.
|
21 |
+
*
|
22 |
+
* @internal Private. Called via the `template_redirect` action.
|
23 |
+
*/
|
24 |
+
public function cache_queried_images() {
|
25 |
+
|
26 |
+
global $posts;
|
27 |
+
|
28 |
+
$this->cache_post_term_images( $posts );
|
29 |
+
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Cache Post Term Images
|
34 |
+
*
|
35 |
+
* Sets the WordPress object cache for all term images
|
36 |
+
* associated to the posts in the provided array. This
|
37 |
+
* function has been created to minimize queries when
|
38 |
+
* using this plugins get_the_terms() style function.
|
39 |
+
*
|
40 |
+
* @param array Post objects.
|
41 |
+
*/
|
42 |
+
private function cache_post_term_images( $posts ) {
|
43 |
+
|
44 |
+
$term_ids = $this->get_post_term_ids( $posts );
|
45 |
+
$image_ids = $this->get_term_image_ids( $term_ids );
|
46 |
+
|
47 |
+
if ( empty( $image_ids ) ) {
|
48 |
+
return;
|
49 |
+
}
|
50 |
+
|
51 |
+
// Get images so they are cached
|
52 |
+
$images = get_posts( array(
|
53 |
+
'include' => $image_ids,
|
54 |
+
'post_type' => 'attachment'
|
55 |
+
) );
|
56 |
+
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Get Post Term IDs
|
61 |
+
*
|
62 |
+
* Get all term_ids for posts that may have assocaited images.
|
63 |
+
*
|
64 |
+
* @param array $posts Post ojects.
|
65 |
+
* @return array Term IDs.
|
66 |
+
*/
|
67 |
+
private function get_post_term_ids( $posts ) {
|
68 |
+
|
69 |
+
$term_ids = array();
|
70 |
+
|
71 |
+
foreach ( (array) $posts as $post ) {
|
72 |
+
|
73 |
+
if ( ! isset( $post->ID ) || ! isset( $post->post_type ) ) {
|
74 |
+
continue;
|
75 |
+
}
|
76 |
+
|
77 |
+
$taxonomies = $this->get_post_type_taxonomies( $post->post_type );
|
78 |
+
|
79 |
+
if ( empty( $taxonomies ) ) {
|
80 |
+
continue;
|
81 |
+
}
|
82 |
+
|
83 |
+
foreach ( $taxonomies as $taxonomy ) {
|
84 |
+
|
85 |
+
$the_terms = get_the_terms( $post->ID, $taxonomy );
|
86 |
+
|
87 |
+
foreach ( (array) $the_terms as $term ) {
|
88 |
+
if ( ! isset( $term->term_id ) ) {
|
89 |
+
continue;
|
90 |
+
}
|
91 |
+
$term_ids[] = $term->term_id;
|
92 |
+
}
|
93 |
+
|
94 |
+
}
|
95 |
+
|
96 |
+
}
|
97 |
+
|
98 |
+
return array_filter( array_unique( $term_ids ) );
|
99 |
+
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Get Post Type Taxonomies
|
104 |
+
*
|
105 |
+
* @todo Only get taxonomies for which Taxonomy Images are enabled in settings.
|
106 |
+
*
|
107 |
+
* @param string $post_type Post type.
|
108 |
+
* @return array Taxonomies.
|
109 |
+
*/
|
110 |
+
private function get_post_type_taxonomies( $post_type ) {
|
111 |
+
|
112 |
+
return get_object_taxonomies( $post->post_type );
|
113 |
+
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Get Term Image IDs
|
118 |
+
*
|
119 |
+
* Get all image IDs for supplied terms.
|
120 |
+
*
|
121 |
+
* @param array $term_ids Term IDs.
|
122 |
+
* @return array Image attachment IDs.
|
123 |
+
*/
|
124 |
+
private function get_term_image_ids( $term_ids ) {
|
125 |
+
|
126 |
+
$image_ids = array();
|
127 |
+
|
128 |
+
foreach ( $term_ids as $term_id ) {
|
129 |
+
|
130 |
+
$t = new Term_Image( $term_id );
|
131 |
+
$image_id = $t->get_image_id();
|
132 |
+
|
133 |
+
if ( empty( $image_id ) ) {
|
134 |
+
continue;
|
135 |
+
}
|
136 |
+
|
137 |
+
$image_ids[] = $image_id;
|
138 |
+
|
139 |
+
}
|
140 |
+
|
141 |
+
return $image_ids;
|
142 |
+
|
143 |
+
}
|
144 |
+
|
145 |
+
}
|
plugin/includes/image-admin-ajax-class.php
ADDED
@@ -0,0 +1,266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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' ) ) exit; // Exit if accessed directly
|
11 |
+
|
12 |
+
class Image_Admin_AJAX {
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Update Term Image
|
16 |
+
*
|
17 |
+
* Handles the AJAX action to update a term image.
|
18 |
+
*
|
19 |
+
* @internal Private. Called via the `wp_ajax_taxonomy_image_create_association` action.
|
20 |
+
*/
|
21 |
+
public function update_term_image() {
|
22 |
+
|
23 |
+
$this->verify_nonce( 'taxonomy-image-plugin-create-association' );
|
24 |
+
|
25 |
+
$term_id = $this->get_posted_term_id();
|
26 |
+
$image_type = $this->get_posted_image_type();
|
27 |
+
$image_id = $this->get_posted_attachment_id();
|
28 |
+
|
29 |
+
// Save as term meta
|
30 |
+
$t = new Term_Image( $term_id, $image_type );
|
31 |
+
$updated = $t->update_image_id( $image_id );
|
32 |
+
|
33 |
+
if ( $updated && ! is_wp_error( $updated ) ) {
|
34 |
+
|
35 |
+
$img_admin = new Term_Image_Admin_Control( $term_id, $image_type );
|
36 |
+
|
37 |
+
$this->json_response( array(
|
38 |
+
'status' => 'good',
|
39 |
+
'why' => esc_html__( 'Image successfully associated', 'taxonomy-images' ),
|
40 |
+
'attachment_thumb_src' => $img_admin->get_image_url()
|
41 |
+
) );
|
42 |
+
|
43 |
+
} else {
|
44 |
+
|
45 |
+
$this->json_response( array(
|
46 |
+
'status' => 'bad',
|
47 |
+
'why' => esc_html__( 'Association could not be created', 'taxonomy-images' )
|
48 |
+
) );
|
49 |
+
|
50 |
+
}
|
51 |
+
|
52 |
+
// Don't know why, but something didn't work.
|
53 |
+
$this->json_response();
|
54 |
+
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Delete Term Image
|
59 |
+
*
|
60 |
+
* Handles the AJAX action to remove a term image.
|
61 |
+
*
|
62 |
+
* @internal Private. Called via the `wp_ajax_taxonomy_image_plugin_remove_association` action.
|
63 |
+
*/
|
64 |
+
public function delete_term_image() {
|
65 |
+
|
66 |
+
$this->verify_nonce( 'taxonomy-image-plugin-remove-association' );
|
67 |
+
|
68 |
+
$term_id = $this->get_posted_term_id();
|
69 |
+
$image_type = $this->get_posted_image_type();
|
70 |
+
|
71 |
+
// Delete term meta
|
72 |
+
$t = new Term_Image( $term_id, $image_type );
|
73 |
+
$deleted = $t->delete_image();
|
74 |
+
|
75 |
+
if ( $deleted ) {
|
76 |
+
|
77 |
+
$this->json_response( array(
|
78 |
+
'status' => 'good',
|
79 |
+
'why' => esc_html__( 'Association successfully removed', 'taxonomy-images' )
|
80 |
+
) );
|
81 |
+
|
82 |
+
} else {
|
83 |
+
|
84 |
+
$this->json_response( array(
|
85 |
+
'status' => 'bad',
|
86 |
+
'why' => esc_html__( 'Association could not be removed', 'taxonomy-images' )
|
87 |
+
) );
|
88 |
+
|
89 |
+
}
|
90 |
+
|
91 |
+
// Don't know why, but something didn't work.
|
92 |
+
$this->json_response();
|
93 |
+
|
94 |
+
}
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Get Posted Term ID
|
98 |
+
*
|
99 |
+
* Exit if term ID not set or if no permission to edit.
|
100 |
+
*
|
101 |
+
* @return integer Term ID.
|
102 |
+
*/
|
103 |
+
private function get_posted_term_id() {
|
104 |
+
|
105 |
+
if ( ! isset( $_POST['term_id'] ) ) {
|
106 |
+
|
107 |
+
$this->json_response( array(
|
108 |
+
'status' => 'bad',
|
109 |
+
'why' => esc_html__( 'term_id not set', 'taxonomy-images' ),
|
110 |
+
) );
|
111 |
+
|
112 |
+
}
|
113 |
+
|
114 |
+
$term_id = absint( $_POST['term_id'] );
|
115 |
+
|
116 |
+
// Empty?
|
117 |
+
if ( empty( $term_id ) ) {
|
118 |
+
|
119 |
+
$this->json_response( array(
|
120 |
+
'status' => 'bad',
|
121 |
+
'why' => esc_html__( 'term_id is empty', 'taxonomy-images' ),
|
122 |
+
) );
|
123 |
+
|
124 |
+
}
|
125 |
+
|
126 |
+
// Permission?
|
127 |
+
if ( ! $this->check_permissions( $term_id ) ) {
|
128 |
+
|
129 |
+
$this->json_response( array(
|
130 |
+
'status' => 'bad',
|
131 |
+
'why' => esc_html__( 'You do not have the correct capability to manage this term', 'taxonomy-images' ),
|
132 |
+
) );
|
133 |
+
|
134 |
+
}
|
135 |
+
|
136 |
+
return $term_id;
|
137 |
+
|
138 |
+
}
|
139 |
+
|
140 |
+
/**
|
141 |
+
* Get Posted Image Type
|
142 |
+
*
|
143 |
+
* @return string Image type.
|
144 |
+
*/
|
145 |
+
private function get_posted_image_type() {
|
146 |
+
|
147 |
+
if ( ! isset( $_POST['image_type'] ) ) {
|
148 |
+
|
149 |
+
$this->json_response( array(
|
150 |
+
'status' => 'bad',
|
151 |
+
'why' => esc_html__( 'image_type not set', 'taxonomy-images' ),
|
152 |
+
) );
|
153 |
+
|
154 |
+
}
|
155 |
+
|
156 |
+
return sanitize_key( $_POST['image_type'] );
|
157 |
+
|
158 |
+
}
|
159 |
+
|
160 |
+
/**
|
161 |
+
* Get Posted Attachment ID
|
162 |
+
*
|
163 |
+
* @return integer Attachment ID.
|
164 |
+
*/
|
165 |
+
private function get_posted_attachment_id() {
|
166 |
+
|
167 |
+
if ( ! isset( $_POST['attachment_id'] ) ) {
|
168 |
+
|
169 |
+
$this->json_response( array(
|
170 |
+
'status' => 'bad',
|
171 |
+
'why' => esc_html__( 'Image ID not sent', 'taxonomy-images' )
|
172 |
+
) );
|
173 |
+
|
174 |
+
}
|
175 |
+
|
176 |
+
$attachment_id = absint( $_POST['attachment_id'] );
|
177 |
+
|
178 |
+
if ( empty( $attachment_id ) ) {
|
179 |
+
|
180 |
+
$this->json_response( array(
|
181 |
+
'status' => 'bad',
|
182 |
+
'why' => esc_html__( 'Image ID is not a positive integer', 'taxonomy-images' )
|
183 |
+
) );
|
184 |
+
|
185 |
+
}
|
186 |
+
|
187 |
+
return $attachment_id;
|
188 |
+
|
189 |
+
}
|
190 |
+
|
191 |
+
/**
|
192 |
+
* Verify Nonce
|
193 |
+
*
|
194 |
+
* @param string $nonce Nonce name.
|
195 |
+
*/
|
196 |
+
private function verify_nonce( $nonce ) {
|
197 |
+
|
198 |
+
if ( ! isset( $_POST['wp_nonce'] ) ) {
|
199 |
+
|
200 |
+
$this->json_response( array(
|
201 |
+
'status' => 'bad',
|
202 |
+
'why' => esc_html__( 'No nonce included', 'taxonomy-images' ),
|
203 |
+
) );
|
204 |
+
|
205 |
+
}
|
206 |
+
|
207 |
+
if ( ! wp_verify_nonce( $_POST['wp_nonce'], $nonce ) ) {
|
208 |
+
|
209 |
+
$this->json_response( array(
|
210 |
+
'status' => 'bad',
|
211 |
+
'why' => esc_html__( 'Nonce did not match', 'taxonomy-images' ),
|
212 |
+
) );
|
213 |
+
|
214 |
+
}
|
215 |
+
|
216 |
+
}
|
217 |
+
|
218 |
+
/**
|
219 |
+
* JSON Response
|
220 |
+
*
|
221 |
+
* Terminates script execution and provides a JSON response.
|
222 |
+
*
|
223 |
+
* @param array Associative array of values to be encoded in JSON.
|
224 |
+
*/
|
225 |
+
private function json_response( $args ) {
|
226 |
+
|
227 |
+
/* translators: An ajax request has failed for an unknown reason. */
|
228 |
+
$response = wp_parse_args( $args, array(
|
229 |
+
'status' => 'bad',
|
230 |
+
'why' => esc_html__( 'Unknown error encountered', 'taxonomy-images' ),
|
231 |
+
'attachment_thumb_src' => ''
|
232 |
+
) );
|
233 |
+
|
234 |
+
header( 'Content-type: application/jsonrequest' );
|
235 |
+
echo json_encode( $response );
|
236 |
+
exit;
|
237 |
+
|
238 |
+
}
|
239 |
+
|
240 |
+
/**
|
241 |
+
* Check Taxonomy Permissions
|
242 |
+
*
|
243 |
+
* Check edit permissions based on a term_id.
|
244 |
+
*
|
245 |
+
* @param integer term_id Term ID.
|
246 |
+
* @return boolean True if user can edit terms, False if not.
|
247 |
+
*/
|
248 |
+
private function check_permissions( $term_id ) {
|
249 |
+
|
250 |
+
$term = get_term( $term_id );
|
251 |
+
|
252 |
+
if ( $term && ! is_wp_error( $term ) ) {
|
253 |
+
|
254 |
+
$taxonomy = get_taxonomy( $term->taxonomy );
|
255 |
+
|
256 |
+
if ( isset( $taxonomy->cap->edit_terms ) ) {
|
257 |
+
return current_user_can( $taxonomy->cap->edit_terms );
|
258 |
+
}
|
259 |
+
|
260 |
+
}
|
261 |
+
|
262 |
+
return false;
|
263 |
+
|
264 |
+
}
|
265 |
+
|
266 |
+
}
|
plugin/includes/image-type-class.php
ADDED
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @package Taxonomy Images
|
5 |
+
* @subpackage Image Type
|
6 |
+
*/
|
7 |
+
|
8 |
+
namespace Plugins\Taxonomy_Images;
|
9 |
+
|
10 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
11 |
+
|
12 |
+
class Image_Type {
|
13 |
+
|
14 |
+
/**
|
15 |
+
* ID
|
16 |
+
*
|
17 |
+
* @var string
|
18 |
+
*/
|
19 |
+
private $id = '';
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Label
|
23 |
+
*
|
24 |
+
* @var string
|
25 |
+
*/
|
26 |
+
private $label = '';
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Taxonomies
|
30 |
+
*
|
31 |
+
* @var array
|
32 |
+
*/
|
33 |
+
private $taxonomies = array();
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Constructor
|
37 |
+
*
|
38 |
+
* @param string $id Type ID.
|
39 |
+
* @param string $label Admin Label.
|
40 |
+
* @param array $taxonomies Supported taxonomies.
|
41 |
+
*/
|
42 |
+
public function __construct( $id, $label, $taxonomies = '' ) {
|
43 |
+
|
44 |
+
$this->id = sanitize_key( $id );
|
45 |
+
$this->label = sanitize_text_field( $label );
|
46 |
+
|
47 |
+
$taxonomies = $this->filter_taxonomies( $taxonomies );
|
48 |
+
$this->taxonomies = $this->validate_taxonomies( $taxonomies );
|
49 |
+
|
50 |
+
}
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Get ID
|
54 |
+
*
|
55 |
+
* @return string Image type ID.
|
56 |
+
*/
|
57 |
+
public function get_id() {
|
58 |
+
|
59 |
+
return $this->id;
|
60 |
+
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Get Label
|
65 |
+
*
|
66 |
+
* @return string
|
67 |
+
*/
|
68 |
+
public function get_label() {
|
69 |
+
|
70 |
+
return $this->label;
|
71 |
+
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Supports Taxonomy?
|
76 |
+
*
|
77 |
+
* @param string $taxonomy Taxonomy.
|
78 |
+
* @return boolean
|
79 |
+
*/
|
80 |
+
public function supports_taxonomy( $taxonomy ) {
|
81 |
+
|
82 |
+
return empty( $this->taxonomies ) || in_array( $taxonomy, $this->taxonomies );
|
83 |
+
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Filter Taxonomies
|
88 |
+
*
|
89 |
+
* Allow image type taxonomies to be filtered via
|
90 |
+
* the `taxonomy_images_type_taxonomies` filter.
|
91 |
+
*
|
92 |
+
* @param array|string $taxonomies Taxonomies.
|
93 |
+
* @return array Filtered taxonomies.
|
94 |
+
*/
|
95 |
+
private function filter_taxonomies( $taxonomies ) {
|
96 |
+
|
97 |
+
if ( ! is_array( $taxonomies ) ) {
|
98 |
+
|
99 |
+
if ( empty( $taxonomies ) ) {
|
100 |
+
$taxonomies = array();
|
101 |
+
} else {
|
102 |
+
$taxonomies = array( $taxonomies );
|
103 |
+
}
|
104 |
+
|
105 |
+
}
|
106 |
+
|
107 |
+
return apply_filters( 'taxonomy_images_type_taxonomies', $taxonomies, $this );
|
108 |
+
|
109 |
+
}
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Validate Taxonomies
|
113 |
+
*
|
114 |
+
* @param array|string $taxonomies Taxonomies.
|
115 |
+
* @return array Valid taxonomies.
|
116 |
+
*/
|
117 |
+
private function validate_taxonomies( $taxonomies ) {
|
118 |
+
|
119 |
+
if ( empty( $taxonomies ) ) {
|
120 |
+
|
121 |
+
return array();
|
122 |
+
|
123 |
+
} elseif ( is_array( $taxonomies ) ) {
|
124 |
+
|
125 |
+
return array_map( 'sanitize_key', $taxonomies );
|
126 |
+
|
127 |
+
}
|
128 |
+
|
129 |
+
return array( sanitize_key( $taxonomies ) );
|
130 |
+
|
131 |
+
}
|
132 |
+
|
133 |
+
}
|
plugin/includes/image-types-class.php
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @package Taxonomy Images
|
5 |
+
* @subpackage Image Types
|
6 |
+
*/
|
7 |
+
|
8 |
+
namespace Plugins\Taxonomy_Images;
|
9 |
+
|
10 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
11 |
+
|
12 |
+
class Image_Types {
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Image Types
|
16 |
+
*
|
17 |
+
* @var array
|
18 |
+
*/
|
19 |
+
private $types = array();
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Register Image Types
|
23 |
+
*
|
24 |
+
* @internal Private. Called via the `init` action.
|
25 |
+
*/
|
26 |
+
public function register_image_types() {
|
27 |
+
|
28 |
+
// Add "Featured" type by default
|
29 |
+
$this->types[] = new Image_Type( '', _x( 'Featured', 'taxonomy image type', 'taxonomy-images' ) );
|
30 |
+
|
31 |
+
$this->add_image_types();
|
32 |
+
$this->validate_image_types();
|
33 |
+
$this->dedupe_image_types();
|
34 |
+
|
35 |
+
}
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Get Image Types for a Taxonomy
|
39 |
+
*
|
40 |
+
* @param string $taxonomy Taxonomy.
|
41 |
+
* @return array Image types.
|
42 |
+
*
|
43 |
+
* @internal Private. Do not call externally.
|
44 |
+
*/
|
45 |
+
public function get_image_types( $taxonomy ) {
|
46 |
+
|
47 |
+
$taxonomy_image_types = array();
|
48 |
+
|
49 |
+
foreach ( $this->types as $type ) {
|
50 |
+
|
51 |
+
if ( $type->supports_taxonomy( $taxonomy ) ) {
|
52 |
+
$taxonomy_image_types[] = $type;
|
53 |
+
}
|
54 |
+
|
55 |
+
}
|
56 |
+
|
57 |
+
return $taxonomy_image_types;
|
58 |
+
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Add Image Types
|
63 |
+
*
|
64 |
+
* New image types can be added via the `taxononomy_images_types` filter.
|
65 |
+
* Example:
|
66 |
+
*
|
67 |
+
* function my_taxononomy_images_types( $types ) {
|
68 |
+
*
|
69 |
+
* $types[] = new TaxonomyImages\Image_Type( 'background', __( 'Background' ), array( 'category' ) );
|
70 |
+
* $types[] = new TaxonomyImages\Image_Type( 'preview', __( 'Preview' ), array( 'category', 'post_tag' ) );
|
71 |
+
*
|
72 |
+
* return $types;
|
73 |
+
*
|
74 |
+
* }
|
75 |
+
* add_filter( 'taxononomy_images_types', 'my_taxononomy_images_types' );
|
76 |
+
*/
|
77 |
+
private function add_image_types() {
|
78 |
+
|
79 |
+
$this->types = apply_filters( 'taxononomy_images_types', $this->types );
|
80 |
+
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Validate Image Types
|
85 |
+
*/
|
86 |
+
private function validate_image_types() {
|
87 |
+
|
88 |
+
foreach ( $this->types as $key => $image_type ) {
|
89 |
+
|
90 |
+
if ( ! is_a( $image_type, __NAMESPACE__ . '\Image_Type' ) ) {
|
91 |
+
unset( $this->types[ $key ] );
|
92 |
+
}
|
93 |
+
|
94 |
+
}
|
95 |
+
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* De-duplicate Image Types
|
100 |
+
*
|
101 |
+
* Check and remove image types with duplicate IDs.
|
102 |
+
*/
|
103 |
+
private function dedupe_image_types() {
|
104 |
+
|
105 |
+
$image_type_ids = array();
|
106 |
+
|
107 |
+
foreach ( $this->types as $key => $image_type ) {
|
108 |
+
|
109 |
+
$type_id = $image_type->get_id();
|
110 |
+
|
111 |
+
if ( in_array( $type_id, $image_type_ids ) ) {
|
112 |
+
unset( $this->types[ $key ] );
|
113 |
+
} else {
|
114 |
+
$image_type_ids[] = $type_id;
|
115 |
+
}
|
116 |
+
|
117 |
+
}
|
118 |
+
|
119 |
+
}
|
120 |
+
|
121 |
+
}
|
plugin/includes/legacy-class.php
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @package Taxonomy Images
|
5 |
+
* @subpackage Legacy
|
6 |
+
*
|
7 |
+
* This class handles migration and backwards compatibility
|
8 |
+
* for old versions of the Taxonomy Images plugin, prior
|
9 |
+
* to storing images as taxonomy meta.
|
10 |
+
*/
|
11 |
+
|
12 |
+
namespace Plugins\Taxonomy_Images;
|
13 |
+
|
14 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
15 |
+
|
16 |
+
class Legacy {
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Constructor
|
20 |
+
*/
|
21 |
+
public function __construct() {
|
22 |
+
|
23 |
+
}
|
24 |
+
|
25 |
+
}
|
plugin/includes/legacy-hooks.php
ADDED
@@ -0,0 +1,608 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
4 |
+
* @package Taxonomy Images
|
5 |
+
* @subpackage Legacy Hooks
|
6 |
+
*
|
7 |
+
* All functions defined in this plugin should be considered
|
8 |
+
* private meaning that they are not to be used in any other
|
9 |
+
* WordPress extension including plugins and themes.
|
10 |
+
*
|
11 |
+
* This file contains custom filters for the legacy version
|
12 |
+
* of this plugin..
|
13 |
+
*/
|
14 |
+
|
15 |
+
namespace Plugins\Taxonomy_Images;
|
16 |
+
|
17 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
18 |
+
|
19 |
+
class Legacy_Hooks {
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Constructor
|
23 |
+
*/
|
24 |
+
public function __construct() {
|
25 |
+
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Setup Hooks
|
30 |
+
*/
|
31 |
+
public function setup_hooks() {
|
32 |
+
|
33 |
+
add_filter( 'taxonomy-images-get-terms', array( $this, 'get_terms' ), 10, 2 );
|
34 |
+
add_filter( 'taxonomy-images-get-the-terms', array( $this, 'get_the_terms' ), 10, 2 );
|
35 |
+
add_filter( 'taxonomy-images-list-the-terms', array( $this, 'list_the_terms' ), 10, 2 );
|
36 |
+
|
37 |
+
add_filter( 'taxonomy-images-queried-term-image', array( $this, 'queried_term_image' ), 10, 2 );
|
38 |
+
add_filter( 'taxonomy-images-queried-term-image-data', array( $this, 'queried_term_image_data' ), 10, 2 );
|
39 |
+
add_filter( 'taxonomy-images-queried-term-image-id', array( $this, 'queried_term_image_id' ) );
|
40 |
+
add_filter( 'taxonomy-images-queried-term-image-object', array( $this, 'queried_term_image_object' ) );
|
41 |
+
add_filter( 'taxonomy-images-queried-term-image-url', array( $this, 'queried_term_image_url' ), 10, 2 );
|
42 |
+
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Get Terms
|
47 |
+
*
|
48 |
+
* This function adds a custom property (image_id) to each
|
49 |
+
* object returned by WordPress core function get_terms().
|
50 |
+
* This property will be set for all term objects. In cases
|
51 |
+
* where a term has an associated image, "image_id" will
|
52 |
+
* contain the value of the image object's ID property. If
|
53 |
+
* no image has been associated, this property will contain
|
54 |
+
* integer with the value of zero.
|
55 |
+
*
|
56 |
+
* @see http://codex.wordpress.org/Function_Reference/get_terms
|
57 |
+
*
|
58 |
+
* Recognized Arguments:
|
59 |
+
*
|
60 |
+
* cache_images (bool) If true, all images will be added to
|
61 |
+
* WordPress object cache. If false, caching will not occur.
|
62 |
+
* Defaults to true. Optional.
|
63 |
+
*
|
64 |
+
* having_images (bool) If true, the returned array will contain
|
65 |
+
* only terms that have associated images. If false, all terms
|
66 |
+
* of the taxonomy will be returned. Defaults to true. Optional.
|
67 |
+
*
|
68 |
+
* taxonomy (string) Name of a registered taxonomy to
|
69 |
+
* return terms from. Defaults to "category". Optional.
|
70 |
+
*
|
71 |
+
* term_args (array) Arguments to pass as the second
|
72 |
+
* parameter of get_terms(). Defaults to an empty array.
|
73 |
+
* Optional.
|
74 |
+
*
|
75 |
+
* @param mixed Default value for apply_filters() to return. Unused.
|
76 |
+
* @param array Named arguments. Please see above for explantion.
|
77 |
+
* @return array List of term objects.
|
78 |
+
*
|
79 |
+
* @access private Use the 'taxonomy-images-get-terms' filter.
|
80 |
+
* @since 0.7
|
81 |
+
*/
|
82 |
+
public function get_terms( $default, $args = array() ) {
|
83 |
+
|
84 |
+
$filter = 'taxonomy-images-get-terms';
|
85 |
+
|
86 |
+
$this->check_current_filter( __FUNCTION__, $filter );
|
87 |
+
|
88 |
+
$args = wp_parse_args( $args, array(
|
89 |
+
'cache_images' => true,
|
90 |
+
'having_images' => true,
|
91 |
+
'taxonomy' => 'category',
|
92 |
+
'term_args' => array(),
|
93 |
+
) );
|
94 |
+
|
95 |
+
$args['taxonomy'] = explode( ',', $args['taxonomy'] );
|
96 |
+
$args['taxonomy'] = array_map( 'trim', $args['taxonomy'] );
|
97 |
+
|
98 |
+
// @todo Check if taxonomy supported in settings
|
99 |
+
|
100 |
+
$terms = get_terms( $args['taxonomy'], $args['term_args'] );
|
101 |
+
|
102 |
+
if ( is_wp_error( $terms ) ) {
|
103 |
+
return array();
|
104 |
+
}
|
105 |
+
|
106 |
+
$image_ids = array();
|
107 |
+
$terms_with_images = array();
|
108 |
+
|
109 |
+
foreach ( (array) $terms as $key => $term ) {
|
110 |
+
$terms[ $key ]->image_id = 0;
|
111 |
+
|
112 |
+
$t = new Term_Image( $term->term_id );
|
113 |
+
$img = $t->get_image_id();
|
114 |
+
|
115 |
+
if ( $img ) {
|
116 |
+
$terms[ $key ]->image_id = $img;
|
117 |
+
$image_ids[] = $img;
|
118 |
+
if ( ! empty( $args['having_images'] ) ) {
|
119 |
+
$terms_with_images[] = $terms[ $key ];
|
120 |
+
}
|
121 |
+
}
|
122 |
+
|
123 |
+
}
|
124 |
+
|
125 |
+
$image_ids = array_unique( $image_ids );
|
126 |
+
|
127 |
+
if ( ! empty( $args['cache_images'] ) ) {
|
128 |
+
$images = array();
|
129 |
+
if ( ! empty( $image_ids ) ) {
|
130 |
+
$images = get_children( array( 'include' => implode( ',', $image_ids ) ) );
|
131 |
+
}
|
132 |
+
}
|
133 |
+
|
134 |
+
if ( ! empty( $terms_with_images ) ) {
|
135 |
+
return $terms_with_images;
|
136 |
+
}
|
137 |
+
|
138 |
+
return $terms;
|
139 |
+
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Get the Terms
|
144 |
+
*
|
145 |
+
* This function adds a custom property (image_id) to each
|
146 |
+
* object returned by WordPress core function get_the_terms().
|
147 |
+
* This property will be set for all term objects. In cases
|
148 |
+
* where a term has an associated image, "image_id" will
|
149 |
+
* contain the value of the image object's ID property. If
|
150 |
+
* no image has been associated, this property will contain
|
151 |
+
* integer with the value of zero.
|
152 |
+
*
|
153 |
+
* @see http://codex.wordpress.org/Function_Reference/get_the_terms
|
154 |
+
*
|
155 |
+
* Recognized Arguments:
|
156 |
+
*
|
157 |
+
* having_images (bool) If true, the returned array will contain
|
158 |
+
* only terms that have associated images. If false, all terms
|
159 |
+
* of the taxonomy will be returned. Defaults to true. Optional.
|
160 |
+
*
|
161 |
+
* post_id (int) The post to retrieve terms from. Defaults
|
162 |
+
* to the ID property of the global $post object. Optional.
|
163 |
+
*
|
164 |
+
* taxonomy (string) Name of a registered taxonomy to
|
165 |
+
* return terms from. Defaults to "category". Optional.
|
166 |
+
*
|
167 |
+
* @param mixed Default value for apply_filters() to return. Unused.
|
168 |
+
* @param array Named arguments. Please see above for explantion.
|
169 |
+
* @return array List of term objects. Empty array if none were found.
|
170 |
+
*
|
171 |
+
* @access private Use the 'taxonomy-images-get-the-terms' filter.
|
172 |
+
* @since 0.7
|
173 |
+
*/
|
174 |
+
public function get_the_terms( $default, $args = array() ) {
|
175 |
+
|
176 |
+
$filter = 'taxonomy-images-get-the-terms';
|
177 |
+
|
178 |
+
$this->check_current_filter( __FUNCTION__, $filter );
|
179 |
+
|
180 |
+
$args = wp_parse_args( $args, array(
|
181 |
+
'having_images' => true,
|
182 |
+
'post_id' => 0,
|
183 |
+
'taxonomy' => 'category',
|
184 |
+
) );
|
185 |
+
|
186 |
+
// @todo Check if taxonomy supported in settings
|
187 |
+
|
188 |
+
if ( empty( $args['post_id'] ) ) {
|
189 |
+
$args['post_id'] = get_the_ID();
|
190 |
+
}
|
191 |
+
|
192 |
+
$terms = get_the_terms( $args['post_id'], $args['taxonomy'] );
|
193 |
+
|
194 |
+
if ( is_wp_error( $terms ) ) {
|
195 |
+
return array();
|
196 |
+
}
|
197 |
+
|
198 |
+
if ( empty( $terms ) ) {
|
199 |
+
return array();
|
200 |
+
}
|
201 |
+
|
202 |
+
$terms_with_images = array();
|
203 |
+
|
204 |
+
foreach ( (array) $terms as $key => $term ) {
|
205 |
+
$terms[ $key ]->image_id = 0;
|
206 |
+
|
207 |
+
$t = new Term_Image( $term->term_id );
|
208 |
+
$img = $t->get_image_id();
|
209 |
+
|
210 |
+
if ( $img ) {
|
211 |
+
$terms[ $key ]->image_id = $img;
|
212 |
+
if ( ! empty( $args['having_images'] ) ) {
|
213 |
+
$terms_with_images[] = $terms[ $key ];
|
214 |
+
}
|
215 |
+
}
|
216 |
+
|
217 |
+
}
|
218 |
+
|
219 |
+
if ( ! empty( $terms_with_images ) ) {
|
220 |
+
return $terms_with_images;
|
221 |
+
}
|
222 |
+
|
223 |
+
return $terms;
|
224 |
+
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* List the Terms
|
229 |
+
*
|
230 |
+
* Lists all terms associated with a given post that
|
231 |
+
* have associated images. Terms without images will
|
232 |
+
* not be included.
|
233 |
+
*
|
234 |
+
* Recognized Arguments:
|
235 |
+
*
|
236 |
+
* after (string) Text to append to the output.
|
237 |
+
* Defaults to: '</ul>'. Optional.
|
238 |
+
*
|
239 |
+
* after_image (string) Text to append to each image in the
|
240 |
+
* list. Defaults to: '</li>'. Optional.
|
241 |
+
*
|
242 |
+
* before (string) Text to preppend to the output.
|
243 |
+
* Defaults to: '<ul class="taxonomy-images-the-terms">'.
|
244 |
+
* Optional.
|
245 |
+
*
|
246 |
+
* before_image (string) Text to prepend to each image in the
|
247 |
+
* list. Defaults to: '<li>'. Optional.
|
248 |
+
*
|
249 |
+
* image_size (string) Any registered image size. Values will
|
250 |
+
* vary from installation to installation. Image sizes defined
|
251 |
+
* in core include: "thumbnail", "medium" and "large". "fullsize"
|
252 |
+
* may also be used to get the unmodified image that was uploaded.
|
253 |
+
* Optional. Defaults to "thumbnail".
|
254 |
+
*
|
255 |
+
* post_id (int) The post to retrieve terms from. Defaults
|
256 |
+
* to the ID property of the global $post object. Optional.
|
257 |
+
*
|
258 |
+
* taxonomy (string) Name of a registered taxonomy to
|
259 |
+
* return terms from. Defaults to "category". Optional.
|
260 |
+
*
|
261 |
+
* @param mixed Default value for apply_filters() to return. Unused.
|
262 |
+
* @param array Named arguments. Please see above for explantion.
|
263 |
+
* @return string HTML markup.
|
264 |
+
*
|
265 |
+
* @access private Use the 'taxonomy-images-list-the-terms' filter.
|
266 |
+
* @since 0.7
|
267 |
+
*/
|
268 |
+
public function list_the_terms( $default, $args = array() ) {
|
269 |
+
|
270 |
+
$filter = 'taxonomy-images-list-the-terms';
|
271 |
+
|
272 |
+
$this->check_current_filter( __FUNCTION__, $filter );
|
273 |
+
|
274 |
+
$args = wp_parse_args( $args, array(
|
275 |
+
'after' => '</ul>',
|
276 |
+
'after_image' => '</li>',
|
277 |
+
'before' => '<ul class="taxonomy-images-the-terms">',
|
278 |
+
'before_image' => '<li>',
|
279 |
+
'image_size' => 'thumbnail',
|
280 |
+
'post_id' => 0,
|
281 |
+
'taxonomy' => 'category',
|
282 |
+
) );
|
283 |
+
|
284 |
+
$args['having_images'] = true;
|
285 |
+
|
286 |
+
// @todo Check if taxonomy supported in settings
|
287 |
+
|
288 |
+
$terms = apply_filters( 'taxonomy-images-get-the-terms', '', $args );
|
289 |
+
|
290 |
+
if ( empty( $terms ) ) {
|
291 |
+
return '';
|
292 |
+
}
|
293 |
+
|
294 |
+
$output = '';
|
295 |
+
|
296 |
+
foreach( $terms as $term ) {
|
297 |
+
|
298 |
+
if ( ! isset( $term->image_id ) ) {
|
299 |
+
continue;
|
300 |
+
}
|
301 |
+
|
302 |
+
$image = wp_get_attachment_image( $term->image_id, $args['image_size'] );
|
303 |
+
|
304 |
+
if ( ! empty( $image ) ) {
|
305 |
+
$output .= $args['before_image'] . '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . $image .'</a>' . $args['after_image'];
|
306 |
+
}
|
307 |
+
|
308 |
+
}
|
309 |
+
|
310 |
+
if ( ! empty( $output ) ) {
|
311 |
+
return $args['before'] . $output . $args['after'];
|
312 |
+
}
|
313 |
+
|
314 |
+
return '';
|
315 |
+
|
316 |
+
}
|
317 |
+
|
318 |
+
/**
|
319 |
+
* Queried Term Image
|
320 |
+
*
|
321 |
+
* Prints html markup for the image associated with
|
322 |
+
* the current queried term.
|
323 |
+
*
|
324 |
+
* Recognized Arguments:
|
325 |
+
*
|
326 |
+
* after (string) - Text to append to the image's HTML.
|
327 |
+
*
|
328 |
+
* before (string) - Text to prepend to the image's HTML.
|
329 |
+
*
|
330 |
+
* image_size (string) - May be any image size registered with
|
331 |
+
* WordPress. If no image size is specified, 'thumbnail' will be
|
332 |
+
* used as a default value. In the event that an unregistered size
|
333 |
+
* is specified, this function will return an empty string.
|
334 |
+
*
|
335 |
+
* Designed to be used in archive templates including
|
336 |
+
* (but not limited to) archive.php, category.php, tag.php,
|
337 |
+
* taxonomy.php as well as derivatives of these templates.
|
338 |
+
*
|
339 |
+
* @param mixed Default value for apply_filters() to return. Unused.
|
340 |
+
* @param array Named array of arguments.
|
341 |
+
* @return string HTML markup for the associated image.
|
342 |
+
*
|
343 |
+
* @access private Use the 'taxonomy-images-queried-term-image' filter.
|
344 |
+
* @since 0.7
|
345 |
+
*/
|
346 |
+
public function queried_term_image( $default = '', $args = array() ) {
|
347 |
+
|
348 |
+
$filter = 'taxonomy-images-queried-term-image';
|
349 |
+
|
350 |
+
$this->check_current_filter( __FUNCTION__, $filter );
|
351 |
+
|
352 |
+
$args = wp_parse_args( $args, array(
|
353 |
+
'after' => '',
|
354 |
+
'attr' => array(),
|
355 |
+
'before' => '',
|
356 |
+
'image_size' => 'thumbnail',
|
357 |
+
) );
|
358 |
+
|
359 |
+
$image_id = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
|
360 |
+
|
361 |
+
if ( ! empty( $image_id ) ) {
|
362 |
+
|
363 |
+
$html = wp_get_attachment_image( $image_id, $args['image_size'], false, $args['attr'] );
|
364 |
+
|
365 |
+
if ( ! empty( $html ) ) {
|
366 |
+
return $args['before'] . $html . $args['after'];
|
367 |
+
}
|
368 |
+
|
369 |
+
}
|
370 |
+
|
371 |
+
return '';
|
372 |
+
|
373 |
+
}
|
374 |
+
|
375 |
+
/**
|
376 |
+
* Queried Term Image Data
|
377 |
+
*
|
378 |
+
* Returns a url to the image associated with the current queried
|
379 |
+
* term. In the event that no image is found an empty string will
|
380 |
+
* be returned.
|
381 |
+
*
|
382 |
+
* Designed to be used in archive templates including
|
383 |
+
* (but not limited to) archive.php, category.php, tag.php,
|
384 |
+
* taxonomy.php as well as derivatives of these templates.
|
385 |
+
*
|
386 |
+
* Recognized Arguments
|
387 |
+
*
|
388 |
+
* image_size (string) - May be any image size registered with
|
389 |
+
* WordPress. If no image size is specified, 'thumbnail' will be
|
390 |
+
* used as a default value. In the event that an unregistered size
|
391 |
+
* is specified, this function will return an empty array.
|
392 |
+
*
|
393 |
+
* @param mixed Default value for apply_filters() to return. Unused.
|
394 |
+
* @param array Named Arguments.
|
395 |
+
* @return array Image data: url, width and height.
|
396 |
+
*
|
397 |
+
* @access private Use the 'taxonomy-images-queried-term-image-data' filter.
|
398 |
+
* @since 0.7
|
399 |
+
* @alter 0.7.2
|
400 |
+
*/
|
401 |
+
public function queried_term_image_data( $default, $args = array() ) {
|
402 |
+
|
403 |
+
$filter = 'taxonomy-images-queried-term-image-data';
|
404 |
+
|
405 |
+
$this->check_current_filter( __FUNCTION__, $filter );
|
406 |
+
|
407 |
+
$args = wp_parse_args( $args, array(
|
408 |
+
'image_size' => 'thumbnail',
|
409 |
+
) );
|
410 |
+
|
411 |
+
$image_id = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
|
412 |
+
|
413 |
+
if ( empty( $image_id ) ) {
|
414 |
+
return array();
|
415 |
+
}
|
416 |
+
|
417 |
+
$data = image_get_intermediate_size( $image_id, $args['image_size'] );
|
418 |
+
|
419 |
+
if ( empty( $data ) ) {
|
420 |
+
|
421 |
+
$src = wp_get_attachment_image_src( $image_id, 'full' );
|
422 |
+
|
423 |
+
if ( isset( $src[0] ) ) {
|
424 |
+
$data['url'] = $src[0];
|
425 |
+
}
|
426 |
+
|
427 |
+
if ( isset( $src[1] ) ) {
|
428 |
+
$data['width'] = $src[1];
|
429 |
+
}
|
430 |
+
|
431 |
+
if ( isset( $src[2] ) ) {
|
432 |
+
$data['height'] = $src[2];
|
433 |
+
}
|
434 |
+
|
435 |
+
}
|
436 |
+
|
437 |
+
if ( ! empty( $data ) ) {
|
438 |
+
return $data;
|
439 |
+
}
|
440 |
+
|
441 |
+
return array();
|
442 |
+
|
443 |
+
}
|
444 |
+
|
445 |
+
/**
|
446 |
+
* Queried Term Image ID
|
447 |
+
*
|
448 |
+
* Designed to be used in archive templates including
|
449 |
+
* (but not limited to) archive.php, category.php, tag.php,
|
450 |
+
* taxonomy.php as well as derivatives of these templates.
|
451 |
+
*
|
452 |
+
* Returns an integer representing the image attachment's ID.
|
453 |
+
* In the event that an image has been associated zero will
|
454 |
+
* be returned.
|
455 |
+
*
|
456 |
+
* This function should never be called directly in any file
|
457 |
+
* however it may be access in any template file via the
|
458 |
+
* 'taxonomy-images-queried-term-image-id' filter.
|
459 |
+
*
|
460 |
+
* @param mixed Default value for apply_filters() to return. Unused.
|
461 |
+
* @return int Image attachment's ID.
|
462 |
+
*
|
463 |
+
* @access private Use the 'taxonomy-images-queried-term-image-id' filter.
|
464 |
+
* @since 0.7
|
465 |
+
*/
|
466 |
+
public function queried_term_image_id( $default = 0 ) {
|
467 |
+
|
468 |
+
$filter = 'taxonomy-images-queried-term-image-id';
|
469 |
+
|
470 |
+
$this->check_current_filter( __FUNCTION__, $filter );
|
471 |
+
|
472 |
+
$obj = get_queried_object();
|
473 |
+
|
474 |
+
if ( is_a( $obj, 'WP_Term' ) ) {
|
475 |
+
|
476 |
+
// @todo Check if taxonomy supported in settings
|
477 |
+
|
478 |
+
$t = new Term_Image( $obj->term_id );
|
479 |
+
return absint( $t->get_image_id() );
|
480 |
+
|
481 |
+
}
|
482 |
+
|
483 |
+
return 0;
|
484 |
+
|
485 |
+
}
|
486 |
+
|
487 |
+
/**
|
488 |
+
* Queried Term Image Object
|
489 |
+
*
|
490 |
+
* Returns all data stored in the WordPress posts table for
|
491 |
+
* the image associated with the term in object form. In the
|
492 |
+
* event that no image is found an empty object will be returned.
|
493 |
+
*
|
494 |
+
* Designed to be used in archive templates including
|
495 |
+
* (but not limited to) archive.php, category.php, tag.php,
|
496 |
+
* taxonomy.php as well as derivatives of these templates.
|
497 |
+
*
|
498 |
+
* This function should never be called directly in any file
|
499 |
+
* however it may be access in any template file via the
|
500 |
+
* 'taxonomy-images-queried-term-image' filter.
|
501 |
+
*
|
502 |
+
* @param mixed Default value for apply_filters() to return. Unused.
|
503 |
+
* @return stdClass WordPress Post object.
|
504 |
+
*
|
505 |
+
* @access private Use the 'taxonomy-images-queried-term-image-object' filter.
|
506 |
+
* @since 0.7
|
507 |
+
*/
|
508 |
+
public function queried_term_image_object( $default ) {
|
509 |
+
|
510 |
+
$filter = 'taxonomy-images-queried-term-image-object';
|
511 |
+
|
512 |
+
$this->check_current_filter( __FUNCTION__, $filter );
|
513 |
+
|
514 |
+
$image_id = apply_filters( 'taxonomy-images-queried-term-image-id', 0 );
|
515 |
+
|
516 |
+
$image = new \stdClass;
|
517 |
+
|
518 |
+
if ( ! empty( $image_id ) ) {
|
519 |
+
$image = get_post( $image_id );
|
520 |
+
}
|
521 |
+
|
522 |
+
return $image;
|
523 |
+
|
524 |
+
}
|
525 |
+
|
526 |
+
/**
|
527 |
+
* Queried Term Image URL
|
528 |
+
*
|
529 |
+
* Returns a url to the image associated with the current queried
|
530 |
+
* term. In the event that no image is found an empty string will
|
531 |
+
* be returned.
|
532 |
+
*
|
533 |
+
* Designed to be used in archive templates including
|
534 |
+
* (but not limited to) archive.php, category.php, tag.php,
|
535 |
+
* taxonomy.php as well as derivatives of these templates.
|
536 |
+
*
|
537 |
+
* Recognized Arguments
|
538 |
+
*
|
539 |
+
* image_size (string) - May be any image size registered with
|
540 |
+
* WordPress. If no image size is specified, 'thumbnail' will be
|
541 |
+
* used as a default value. In the event that an unregistered size
|
542 |
+
* is specified, this function will return an empty string.
|
543 |
+
*
|
544 |
+
* @param mixed Default value for apply_filters() to return. Unused.
|
545 |
+
* @param array Named Arguments.
|
546 |
+
* @return string Image URL.
|
547 |
+
*
|
548 |
+
* @access private Use the 'taxonomy-images-queried-term-image-url' filter.
|
549 |
+
* @since 0.7
|
550 |
+
*/
|
551 |
+
public function queried_term_image_url( $default = '', $args = array() ) {
|
552 |
+
|
553 |
+
$filter = 'taxonomy-images-queried-term-image-url';
|
554 |
+
|
555 |
+
$this->check_current_filter( __FUNCTION__, $filter );
|
556 |
+
|
557 |
+
$args = wp_parse_args( $args, array(
|
558 |
+
'image_size' => 'thumbnail',
|
559 |
+
) );
|
560 |
+
|
561 |
+
$data = apply_filters( 'taxonomy-images-queried-term-image-data', array(), $args );
|
562 |
+
|
563 |
+
if ( isset( $data['url'] ) ) {
|
564 |
+
return $data['url'];
|
565 |
+
}
|
566 |
+
|
567 |
+
return '';
|
568 |
+
|
569 |
+
}
|
570 |
+
|
571 |
+
/**
|
572 |
+
* Check Current Filter
|
573 |
+
*
|
574 |
+
* Check that the user is not directly calling a function instead
|
575 |
+
* of using supported filters.
|
576 |
+
*
|
577 |
+
* @param string $function Name of function called.
|
578 |
+
* @param string $filter Name of filter to use instead.
|
579 |
+
*/
|
580 |
+
private function check_current_filter( $function, $filter ) {
|
581 |
+
|
582 |
+
if ( current_filter() !== $filter ) {
|
583 |
+
$this->please_use_filter( $function, $filter );
|
584 |
+
}
|
585 |
+
|
586 |
+
}
|
587 |
+
|
588 |
+
/**
|
589 |
+
* Please Use Filter
|
590 |
+
*
|
591 |
+
* Report to user that they are directly calling a function instead
|
592 |
+
* of using supported filters.
|
593 |
+
*
|
594 |
+
* @todo Log PHP error.
|
595 |
+
*
|
596 |
+
* @param string $function Name of function called.
|
597 |
+
* @param string $filter Name of filter to use instead.
|
598 |
+
*/
|
599 |
+
private function please_use_filter( $function, $filter ) {
|
600 |
+
|
601 |
+
$error = sprintf( esc_html__( 'The %1$s has been called directly. Please use the %2$s filter instead.', 'taxonomy-images' ),
|
602 |
+
'<code>' . esc_html( $function . '()' ) . '</code>',
|
603 |
+
'<code>' . esc_html( $filter ) . '</code>'
|
604 |
+
);
|
605 |
+
|
606 |
+
}
|
607 |
+
|
608 |
+
}
|
plugin/includes/settings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namespace Plugins\Taxonomy_Images;
|
9 |
+
|
10 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
11 |
+
|
12 |
+
class Settings_Admin {
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Admin Menu
|
16 |
+
*
|
17 |
+
* Create the admin menu link for the settings page.
|
18 |
+
*
|
19 |
+
* @internal Private. Called via the `admin_menu` action.
|
20 |
+
*/
|
21 |
+
public function settings_menu() {
|
22 |
+
|
23 |
+
add_options_page(
|
24 |
+
esc_html_x( 'Taxonomy Images', 'page title tag', 'taxonomy-images' ), // HTML <title> tag.
|
25 |
+
esc_html_x( 'Taxonomy Images', 'menu name', 'taxonomy-images' ), // Link text in admin menu.
|
26 |
+
'manage_options',
|
27 |
+
'taxonomy_image_plugin_settings',
|
28 |
+
array( $this, 'settings_page' )
|
29 |
+
);
|
30 |
+
|
31 |
+
}
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Settings Page
|
35 |
+
*
|
36 |
+
* This function in conjunction with others use the WordPress
|
37 |
+
* Settings API to create a settings page where users can adjust
|
38 |
+
* the behaviour of this plugin. Please see the following functions
|
39 |
+
* for more insight on the output generated by this function:
|
40 |
+
*
|
41 |
+
* taxonomy_image_plugin_control_taxonomies()
|
42 |
+
*
|
43 |
+
* @internal Private. Used by add_options_page().
|
44 |
+
*/
|
45 |
+
public function settings_page() {
|
46 |
+
|
47 |
+
echo '<div class="wrap">';
|
48 |
+
|
49 |
+
// translators: Heading of the custom administration page.
|
50 |
+
echo '<h2>' . esc_html_x( 'Taxonomy Images Plugin Settings', 'page title', 'taxonomy-images' ) . '</h2>';
|
51 |
+
echo '<div id="taxonomy-images">';
|
52 |
+
echo '<form action="options.php" method="post">';
|
53 |
+
|
54 |
+
settings_fields( 'taxonomy_image_plugin_settings' );
|
55 |
+
do_settings_sections( 'taxonomy_image_plugin_settings' );
|
56 |
+
|
57 |
+
// translators: Button on the custom administration page.
|
58 |
+
echo '<div class="button-holder">' . get_submit_button( __( 'Save Changes', 'taxonomy-images' ) ) . '</div>';
|
59 |
+
echo '</div></form></div>';
|
60 |
+
|
61 |
+
}
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Register settings
|
65 |
+
*
|
66 |
+
* This plugin will store to sets of settings in the
|
67 |
+
* options table. The first is named 'taxonomy_image_plugin'
|
68 |
+
* and stores the associations between terms and images. The
|
69 |
+
* keys in this array represent the term_taxonomy_id of the
|
70 |
+
* term while the value represents the ID of the image
|
71 |
+
* attachment.
|
72 |
+
*
|
73 |
+
* The second setting is used to store everything else. As of
|
74 |
+
* version 0.7 it has one key named 'taxonomies' which is a
|
75 |
+
* flat array consisting of taxonomy names representing a
|
76 |
+
* black-list of registered taxonomies. These taxonomies will
|
77 |
+
* NOT be given an image UI.
|
78 |
+
*
|
79 |
+
* @internal Private. Called via the `admin_init` action.
|
80 |
+
*/
|
81 |
+
public function register_settings() {
|
82 |
+
|
83 |
+
register_setting(
|
84 |
+
'taxonomy_image_plugin_settings',
|
85 |
+
'taxonomy_image_plugin_settings',
|
86 |
+
array( $this, 'sanitize_settings' )
|
87 |
+
);
|
88 |
+
|
89 |
+
add_settings_section(
|
90 |
+
'taxonomy_image_plugin_settings',
|
91 |
+
esc_html__( 'Settings', 'taxonomy-images' ),
|
92 |
+
'__return_false',
|
93 |
+
'taxonomy_image_plugin_settings'
|
94 |
+
);
|
95 |
+
|
96 |
+
add_settings_field(
|
97 |
+
'taxonomy-images',
|
98 |
+
esc_html__( 'Taxonomies', 'taxonomy-images' ),
|
99 |
+
array( $this, 'taxonomies_setting_field' ),
|
100 |
+
'taxonomy_image_plugin_settings',
|
101 |
+
'taxonomy_image_plugin_settings'
|
102 |
+
);
|
103 |
+
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Taxonomies Setting Field
|
108 |
+
*
|
109 |
+
* @internal Private. Called by add_settings_field().
|
110 |
+
*/
|
111 |
+
public function taxonomies_setting_field() {
|
112 |
+
|
113 |
+
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
114 |
+
$taxonomies = get_taxonomies( array(
|
115 |
+
'public' => true,
|
116 |
+
'show_ui' => true
|
117 |
+
), 'objects' );
|
118 |
+
|
119 |
+
foreach ( (array) $taxonomies as $taxonomy ) {
|
120 |
+
|
121 |
+
if ( ! isset( $taxonomy->name ) || ! isset( $taxonomy->label ) || ! isset( $taxonomy->show_ui ) || empty( $taxonomy->show_ui ) ) {
|
122 |
+
continue;
|
123 |
+
}
|
124 |
+
|
125 |
+
$id = 'taxonomy-images-' . $taxonomy->name;
|
126 |
+
$checked = checked( isset( $settings['taxonomies'] ) && in_array( $taxonomy->name, (array) $settings['taxonomies'] ), true, false );
|
127 |
+
|
128 |
+
printf( '<p><label for="%1$s"><input%2$s id="%1$s" type="checkbox" name="taxonomy_image_plugin_settings[taxonomies][]" value="%3$s" /> %4$s</label></p>', esc_attr( $id ), $checked, esc_attr( $taxonomy->name ), esc_html( $taxonomy->label ) );
|
129 |
+
|
130 |
+
}
|
131 |
+
|
132 |
+
}
|
133 |
+
|
134 |
+
/**
|
135 |
+
* Sanitize Settings
|
136 |
+
*
|
137 |
+
* This function is responsible for ensuring that
|
138 |
+
* all values within the 'taxonomy_image_plugin_settings'
|
139 |
+
* options are of the appropriate type.
|
140 |
+
*
|
141 |
+
* @param array Unknown.
|
142 |
+
* @return array Multi-dimensional array of sanitized settings.
|
143 |
+
*
|
144 |
+
* @internal Private. Used by register_setting().
|
145 |
+
*/
|
146 |
+
public function sanitize_settings( $dirty ) {
|
147 |
+
|
148 |
+
$clean = array();
|
149 |
+
|
150 |
+
if ( isset( $dirty['taxonomies'] ) ) {
|
151 |
+
|
152 |
+
$taxonomies = get_taxonomies();
|
153 |
+
|
154 |
+
foreach ( (array) $dirty['taxonomies'] as $taxonomy ) {
|
155 |
+
if ( in_array( $taxonomy, $taxonomies ) ) {
|
156 |
+
$clean['taxonomies'][] = $taxonomy;
|
157 |
+
}
|
158 |
+
}
|
159 |
+
|
160 |
+
}
|
161 |
+
|
162 |
+
// translators: Notice displayed on the custom administration page.
|
163 |
+
$message = __( 'Image support for taxonomies successfully updated', 'taxonomy-images' );
|
164 |
+
if ( empty( $clean ) ) {
|
165 |
+
// translators: Notice displayed on the custom administration page.
|
166 |
+
$message = __( 'Image support has been disabled for all taxonomies.', 'taxonomy-images' );
|
167 |
+
}
|
168 |
+
|
169 |
+
add_settings_error( 'taxonomy_image_plugin_settings', 'taxonomies_updated', esc_html( $message ), 'updated' );
|
170 |
+
|
171 |
+
return $clean;
|
172 |
+
|
173 |
+
}
|
174 |
+
|
175 |
+
/**
|
176 |
+
* Get Settings Page Link
|
177 |
+
*
|
178 |
+
* @param array Localized link text.
|
179 |
+
* @return string HTML link to settings page.
|
180 |
+
*/
|
181 |
+
private function get_settings_page_link( $link_text = '' ) {
|
182 |
+
|
183 |
+
if ( empty( $link_text ) ) {
|
184 |
+
$link_text = __( 'Manage Settings', 'taxonomy-images' );
|
185 |
+
}
|
186 |
+
|
187 |
+
if ( current_user_can( 'manage_options' ) ) {
|
188 |
+
return sprintf( '<a href="%s">%s</a>', esc_url( add_query_arg( array( 'page' => 'taxonomy_image_plugin_settings' ), admin_url( 'options-general.php' ) ) ), esc_html( $link_text ) );
|
189 |
+
}
|
190 |
+
|
191 |
+
return '';
|
192 |
+
}
|
193 |
+
|
194 |
+
/**
|
195 |
+
* Plugin Meta Links
|
196 |
+
*
|
197 |
+
* Add a link to this plugin's setting page when it
|
198 |
+
* displays in the table on wp-admin/plugins.php.
|
199 |
+
*
|
200 |
+
* @param array List of links.
|
201 |
+
* @param string Current plugin being displayed in plugins.php.
|
202 |
+
* @return array Potentially modified list of links.
|
203 |
+
*
|
204 |
+
* @internal Private. Called via the `plugin_row_meta` filter.
|
205 |
+
*/
|
206 |
+
public function plugin_row_meta( $links, $file ) {
|
207 |
+
|
208 |
+
$plugin_name = Plugin::basename();
|
209 |
+
|
210 |
+
if ( $plugin_name != $file ) {
|
211 |
+
return $links;
|
212 |
+
}
|
213 |
+
|
214 |
+
$link = $this->get_settings_page_link( esc_html__( 'Settings', 'taxonomy-images' ) );
|
215 |
+
|
216 |
+
if ( ! empty( $link ) ) {
|
217 |
+
$links[] = $link;
|
218 |
+
}
|
219 |
+
|
220 |
+
return $links;
|
221 |
+
|
222 |
+
}
|
223 |
+
|
224 |
+
}
|
plugin/includes/supported-class.php
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @package Taxonomy Images
|
5 |
+
* @subpackage Supported
|
6 |
+
*
|
7 |
+
* This class is not namespaced as it needs to be
|
8 |
+
* backwards-compatible with earlier versions of PHP.
|
9 |
+
*/
|
10 |
+
|
11 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
12 |
+
|
13 |
+
class Taxonomy_Images_Supported {
|
14 |
+
|
15 |
+
/**
|
16 |
+
* Plugin Supported?
|
17 |
+
*
|
18 |
+
* @return boolean
|
19 |
+
*/
|
20 |
+
public static function plugin_supported() {
|
21 |
+
|
22 |
+
return self::php_version_supported() && self::wp_version_supported() && self::is_supported_by_default();
|
23 |
+
|
24 |
+
}
|
25 |
+
|
26 |
+
/**
|
27 |
+
* PHP Version Supported?
|
28 |
+
*
|
29 |
+
* 5.3+ required for namespace support.
|
30 |
+
*
|
31 |
+
* @return boolean
|
32 |
+
*/
|
33 |
+
public static function php_version_supported() {
|
34 |
+
|
35 |
+
return version_compare( PHP_VERSION, '5.3.0', '>' );
|
36 |
+
|
37 |
+
}
|
38 |
+
|
39 |
+
/**
|
40 |
+
* WP Version Supported?
|
41 |
+
*
|
42 |
+
* WordPress 4.4 required for term meta support.
|
43 |
+
*
|
44 |
+
* @return boolean
|
45 |
+
*/
|
46 |
+
public static function wp_version_supported() {
|
47 |
+
|
48 |
+
global $wp_version;
|
49 |
+
|
50 |
+
return version_compare( $wp_version, '4.4', '>=' );
|
51 |
+
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Is Supported By Default?
|
56 |
+
*
|
57 |
+
* Used to disable term meta by default until production-ready.
|
58 |
+
* Can use filter in the meantime to add support.
|
59 |
+
*
|
60 |
+
* @return boolean
|
61 |
+
*/
|
62 |
+
public static function is_supported_by_default() {
|
63 |
+
|
64 |
+
return apply_filters( 'taxonomy_images/use_term_meta', false );
|
65 |
+
|
66 |
+
}
|
67 |
+
|
68 |
+
}
|
plugin/includes/term-image-admin-control-class.php
ADDED
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @package Taxonomy Images
|
5 |
+
* @subpackage Term Image Admin Control
|
6 |
+
*/
|
7 |
+
|
8 |
+
namespace Plugins\Taxonomy_Images;
|
9 |
+
|
10 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
11 |
+
|
12 |
+
class Term_Image_Admin_Control extends Term_Image {
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Get Rendered Control
|
16 |
+
*
|
17 |
+
* @param string $size Pass `large` for larger image control size.
|
18 |
+
* @return string HTML output.
|
19 |
+
*/
|
20 |
+
public function get_rendered( $size = '' ) {
|
21 |
+
|
22 |
+
$term = $this->get_term();
|
23 |
+
|
24 |
+
// Return if term not valid...
|
25 |
+
if ( ! $term ) {
|
26 |
+
return '';
|
27 |
+
}
|
28 |
+
|
29 |
+
$term_id = $this->get_term_id();
|
30 |
+
|
31 |
+
// Control Attributes
|
32 |
+
$edit_attributes = $this->get_control_edit_attributes( $size );
|
33 |
+
$add_attributes = $this->get_control_add_attributes();
|
34 |
+
$remove_attributes = $this->get_control_remove_attributes();
|
35 |
+
|
36 |
+
// Control
|
37 |
+
$control = '<div id="' . esc_attr( 'taxonomy-image-control-' . $this->get_type() . '-' . $term_id ) . '" class="taxonomy-image-control hide-if-no-js">';
|
38 |
+
$control .= $this->get_rendered_control_link( $edit_attributes, '<img id="' . esc_attr( 'taxonomy_image_plugin_' . $term_id ) . '" src="' . esc_url( $this->get_image_url() ) . '" alt="" />' );
|
39 |
+
$control .= $this->get_rendered_control_link( $add_attributes, esc_html_x( 'Add', 'taxonomy image', 'taxonomy-images' ) );
|
40 |
+
$control .= $this->get_rendered_control_link( $remove_attributes, esc_html_x( 'Remove', 'taxonomy image', 'taxonomy-images' ) );
|
41 |
+
$control .= '</div>';
|
42 |
+
|
43 |
+
return $control;
|
44 |
+
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Get Rendered Control Link
|
49 |
+
*
|
50 |
+
* @param array $attributes HTML link attributes.
|
51 |
+
* @param string $content HTML link content.
|
52 |
+
* @return string HTML link.
|
53 |
+
*/
|
54 |
+
private function get_rendered_control_link( $attributes, $content ) {
|
55 |
+
|
56 |
+
return '<a ' . $this->get_rendered_attributes( $attributes ) . '>' . $content . '</a>';
|
57 |
+
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Get Rendered Attributes
|
62 |
+
*
|
63 |
+
* @param array $attributes Attributes.
|
64 |
+
* @return string HTML formatted attributes.
|
65 |
+
*/
|
66 |
+
private function get_rendered_attributes( $attributes ) {
|
67 |
+
|
68 |
+
$html_attributes = array();
|
69 |
+
|
70 |
+
foreach ( $attributes as $key => $attribute ) {
|
71 |
+
$html_attributes[] = $key . '="' . $attribute . '"';
|
72 |
+
}
|
73 |
+
|
74 |
+
return implode( ' ', $html_attributes );
|
75 |
+
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Get Control Remove Attributes
|
80 |
+
*
|
81 |
+
* Attributes for HTML remove image control.
|
82 |
+
*
|
83 |
+
* @return array HTML attributes.
|
84 |
+
*/
|
85 |
+
private function get_control_remove_attributes() {
|
86 |
+
|
87 |
+
$hide = $this->get_image_id() ? '' : ' hide';
|
88 |
+
$name = strtolower( $this->get_taxonomy_singular_name() );
|
89 |
+
$term = $this->get_term();
|
90 |
+
|
91 |
+
return wp_parse_args( $this->get_control_attributes(), array(
|
92 |
+
'data-nonce' => wp_create_nonce( 'taxonomy-image-plugin-remove-association' ),
|
93 |
+
'class' => 'control remove' . $hide,
|
94 |
+
'href' => '#',
|
95 |
+
'title' => esc_attr( sprintf( _x( 'Remove featured image from the “%1$s” %2$s.', 'term name and taxonomy', 'taxonomy-images' ), $term->name, $name ) ),
|
96 |
+
'id' => esc_attr( 'remove-' . $this->get_term_id() )
|
97 |
+
) );
|
98 |
+
|
99 |
+
}
|
100 |
+
|
101 |
+
/**
|
102 |
+
* Get Control Add Attributes
|
103 |
+
*
|
104 |
+
* Attributes for HTML add image control.
|
105 |
+
*
|
106 |
+
* @return array HTML attributes.
|
107 |
+
*/
|
108 |
+
private function get_control_add_attributes() {
|
109 |
+
|
110 |
+
return wp_parse_args( $this->get_control_update_attributes(), array(
|
111 |
+
'class' => 'control upload'
|
112 |
+
) );
|
113 |
+
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Get Control Edit Attributes
|
118 |
+
*
|
119 |
+
* Attributes for HTML edit image control.
|
120 |
+
*
|
121 |
+
* @return array HTML attributes.
|
122 |
+
*/
|
123 |
+
private function get_control_edit_attributes( $size ) {
|
124 |
+
|
125 |
+
$size_class = 'large' == $size ? ' taxonomy-image-thumbnail-large' : '';
|
126 |
+
|
127 |
+
return wp_parse_args( $this->get_control_update_attributes(), array(
|
128 |
+
'class' => 'taxonomy-image-thumbnail' . $size_class
|
129 |
+
) );
|
130 |
+
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Get Control Update Attributes
|
135 |
+
*
|
136 |
+
* Attributes common to HTML controls that add/update images.
|
137 |
+
*
|
138 |
+
* @return array HTML attributes.
|
139 |
+
*/
|
140 |
+
private function get_control_update_attributes() {
|
141 |
+
|
142 |
+
$name = strtolower( $this->get_taxonomy_singular_name() );
|
143 |
+
$term = $this->get_term();
|
144 |
+
|
145 |
+
return wp_parse_args( $this->get_control_attributes(), array(
|
146 |
+
'data-nonce' => wp_create_nonce( 'taxonomy-image-plugin-create-association' ),
|
147 |
+
'href' => esc_url( admin_url( 'media-upload.php' ) . '?type=image&tab=library&post_id=0&TB_iframe=true' ),
|
148 |
+
'title' => esc_attr( sprintf( _x( 'Set featured image for the “%1$s” %2$s.', 'term name and taxonomy', 'taxonomy-images' ), $term->name, $name ) )
|
149 |
+
) );
|
150 |
+
|
151 |
+
}
|
152 |
+
|
153 |
+
/**
|
154 |
+
* Get Control Attributes
|
155 |
+
*
|
156 |
+
* Base level attributes common to all HTML controls
|
157 |
+
* for adding/deleting/updating images.
|
158 |
+
*
|
159 |
+
* @return array HTML attributes.
|
160 |
+
*/
|
161 |
+
private function get_control_attributes() {
|
162 |
+
|
163 |
+
return array(
|
164 |
+
'data-term-id' => $this->get_term_id(),
|
165 |
+
'data-image-type' => $this->get_type(),
|
166 |
+
'data-attachment-id' => $this->get_image_id()
|
167 |
+
);
|
168 |
+
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Get Image URL
|
173 |
+
*
|
174 |
+
* Return a URI to a custom preview image size for display in admin.
|
175 |
+
* The output of this function should be escaped before printing to the browser.
|
176 |
+
*
|
177 |
+
* @return string URI of custom image on success. Otherwise empty string.
|
178 |
+
*
|
179 |
+
* @internal Private. Also used for rendering admin control in AJAX.
|
180 |
+
*/
|
181 |
+
public function get_image_url() {
|
182 |
+
|
183 |
+
/**
|
184 |
+
* Get the admin preview sized image URL
|
185 |
+
* The core Media Library list gets 60 x 60px images, but we try for slightly higher res.
|
186 |
+
*/
|
187 |
+
$thumb = wp_get_attachment_image_src( $this->get_image_id(), array( 75, 75 ) );
|
188 |
+
|
189 |
+
if ( $thumb ) {
|
190 |
+
return $thumb[0];
|
191 |
+
}
|
192 |
+
|
193 |
+
/**
|
194 |
+
* No image can be found.
|
195 |
+
* This is most likely caused by a user deleting an attachment before deleting it's association with a taxonomy.
|
196 |
+
* If we are in the admin delete the association and return URL to default image.
|
197 |
+
*/
|
198 |
+
if ( is_admin() ) {
|
199 |
+
$this->delete_image();
|
200 |
+
}
|
201 |
+
|
202 |
+
// Otherwise return path to placeholder image.
|
203 |
+
return $this->get_placeholder_url();
|
204 |
+
|
205 |
+
}
|
206 |
+
|
207 |
+
/**
|
208 |
+
* Get Placeholder URL
|
209 |
+
*
|
210 |
+
* Overrides placeholder URL with admin placeholder image.
|
211 |
+
*
|
212 |
+
* @return string Placeholder image URL.
|
213 |
+
*/
|
214 |
+
protected function get_placeholder_url() {
|
215 |
+
|
216 |
+
return Plugin::plugin_url( 'plugin/assets/images/default.png' );
|
217 |
+
|
218 |
+
}
|
219 |
+
|
220 |
+
}
|
plugin/includes/term-image-class.php
ADDED
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @package Taxonomy Images
|
5 |
+
* @subpackage Term Image
|
6 |
+
*/
|
7 |
+
|
8 |
+
namespace Plugins\Taxonomy_Images;
|
9 |
+
|
10 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
11 |
+
|
12 |
+
class Term_Image {
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Term ID
|
16 |
+
*
|
17 |
+
* @var integer
|
18 |
+
*/
|
19 |
+
private $term_id = 0;
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Term
|
23 |
+
*
|
24 |
+
* @var WP_Term|false|null Null if not fetched, false if not avilable, otherwise term object.
|
25 |
+
*/
|
26 |
+
private $term = null;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Type
|
30 |
+
*
|
31 |
+
* @var string
|
32 |
+
*/
|
33 |
+
private $type = '';
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Constructor
|
37 |
+
*
|
38 |
+
* @param integer $term_id Term ID.
|
39 |
+
* @param string $type Image type.
|
40 |
+
*/
|
41 |
+
public function __construct( $term_id, $type = '' ) {
|
42 |
+
|
43 |
+
$this->term_id = absint( $term_id );
|
44 |
+
$this->type = sanitize_key( $type );
|
45 |
+
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Get Term ID
|
50 |
+
*
|
51 |
+
* @return integer
|
52 |
+
*/
|
53 |
+
public function get_term_id() {
|
54 |
+
|
55 |
+
return $this->term_id;
|
56 |
+
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Get Term
|
61 |
+
*
|
62 |
+
* @return WP_Term Term object
|
63 |
+
*/
|
64 |
+
public function get_term() {
|
65 |
+
|
66 |
+
if ( is_null( $this->term ) && $this->get_term_id() ) {
|
67 |
+
|
68 |
+
$term = get_term( $this->get_term_id() );
|
69 |
+
|
70 |
+
if ( $term && ! is_wp_error( $term ) ) {
|
71 |
+
$this->term = $term;
|
72 |
+
} else {
|
73 |
+
$this->term = false;
|
74 |
+
}
|
75 |
+
|
76 |
+
}
|
77 |
+
|
78 |
+
return $this->term;
|
79 |
+
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Get Taxonomy
|
84 |
+
*
|
85 |
+
* @return string
|
86 |
+
*/
|
87 |
+
public function get_taxonomy() {
|
88 |
+
|
89 |
+
$term = $this->get_term();
|
90 |
+
|
91 |
+
if ( $term ) {
|
92 |
+
return $term->taxonomy;
|
93 |
+
}
|
94 |
+
|
95 |
+
return '';
|
96 |
+
|
97 |
+
}
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Get Taxonomy Singular Name
|
101 |
+
*
|
102 |
+
* @return string
|
103 |
+
*/
|
104 |
+
protected function get_taxonomy_singular_name() {
|
105 |
+
|
106 |
+
$tax = $this->get_taxonomy();
|
107 |
+
|
108 |
+
if ( ! empty( $tax ) ) {
|
109 |
+
|
110 |
+
$taxonomy = get_taxonomy( $tax );
|
111 |
+
|
112 |
+
if ( isset( $taxonomy->labels->singular_name ) ) {
|
113 |
+
return $taxonomy->labels->singular_name;
|
114 |
+
}
|
115 |
+
|
116 |
+
}
|
117 |
+
|
118 |
+
return _x( 'Term', 'taxonomy singular name', 'taxonomy-images' );
|
119 |
+
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Get Type
|
124 |
+
*
|
125 |
+
* @return string
|
126 |
+
*/
|
127 |
+
public function get_type() {
|
128 |
+
|
129 |
+
return $this->type;
|
130 |
+
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Get Image ID
|
135 |
+
*
|
136 |
+
* @return integer Image ID.
|
137 |
+
*/
|
138 |
+
public function get_image_id() {
|
139 |
+
|
140 |
+
return absint( get_term_meta( $this->term_id, $this->get_meta_key(), true ) );
|
141 |
+
|
142 |
+
}
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Update Image ID
|
146 |
+
*
|
147 |
+
* Deletes image ID if not a valid image ID.
|
148 |
+
*
|
149 |
+
* @param integer $image_id Image ID.
|
150 |
+
* @return int|WP_Error|bool Meta ID if added. True if updated. WP_Error when term_id is ambiguous between taxonomies. False on failure.
|
151 |
+
*/
|
152 |
+
public function update_image_id( $image_id ) {
|
153 |
+
|
154 |
+
$image_id = absint( $image_id );
|
155 |
+
|
156 |
+
if ( $image_id == 0 ) {
|
157 |
+
$this->delete_image();
|
158 |
+
}
|
159 |
+
|
160 |
+
return update_term_meta( $this->term_id, $this->get_meta_key(), $image_id );
|
161 |
+
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Delete Image
|
166 |
+
*
|
167 |
+
* @return boolean True on success, false on failure.
|
168 |
+
*/
|
169 |
+
public function delete_image() {
|
170 |
+
|
171 |
+
return delete_term_meta( $this->term_id, $this->get_meta_key() );
|
172 |
+
|
173 |
+
}
|
174 |
+
|
175 |
+
/**
|
176 |
+
* Get Meta Key
|
177 |
+
*
|
178 |
+
* @return string Meta key.
|
179 |
+
*/
|
180 |
+
private function get_meta_key() {
|
181 |
+
|
182 |
+
$type = $this->get_type();
|
183 |
+
|
184 |
+
return empty( $type ) ? 'taxonomy_image_id' : 'taxonomy_image_' . $type . '_id';
|
185 |
+
|
186 |
+
}
|
187 |
+
|
188 |
+
/**
|
189 |
+
* Get (Blank) Placeholder URL
|
190 |
+
*
|
191 |
+
* @return string Placeholder image URL.
|
192 |
+
*/
|
193 |
+
protected function get_placeholder_url() {
|
194 |
+
|
195 |
+
return Plugin::plugin_url( 'plugin/assets/images/blank.png' );
|
196 |
+
|
197 |
+
}
|
198 |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|
7 |
+
|
8 |
+
namespace Plugins\Taxonomy_Images;
|
9 |
+
|
10 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
11 |
+
|
12 |
+
class Terms_Admin {
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Image Types Class
|
16 |
+
*
|
17 |
+
* @var Image_Types|null
|
18 |
+
*/
|
19 |
+
private $image_types = null;
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Constructor
|
23 |
+
*
|
24 |
+
* @param Image_Types $image_types Instance of class.
|
25 |
+
*/
|
26 |
+
public function __construct( $image_types ) {
|
27 |
+
|
28 |
+
$this->image_types = $image_types;
|
29 |
+
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Term Image Column ID
|
34 |
+
*
|
35 |
+
* @var string
|
36 |
+
*/
|
37 |
+
private $term_image_column_id = 'taxonomy_image_plugin';
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Dynamically add admin fields for each taxonomy
|
41 |
+
*
|
42 |
+
* Adds hooks for each taxonomy that the user has given
|
43 |
+
* an image interface to via settings page. These hooks
|
44 |
+
* enable the image interface on wp-admin/edit-tags.php.
|
45 |
+
*
|
46 |
+
* @internal Private. Called via the `admin_init` action.
|
47 |
+
*/
|
48 |
+
public function add_admin_fields() {
|
49 |
+
|
50 |
+
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
51 |
+
|
52 |
+
if ( ! isset( $settings['taxonomies'] ) ) {
|
53 |
+
return;
|
54 |
+
}
|
55 |
+
|
56 |
+
foreach ( $settings['taxonomies'] as $taxonomy ) {
|
57 |
+
add_filter( 'manage_edit-' . $taxonomy . '_columns', array( $this, 'taxonomy_columns' ) );
|
58 |
+
add_filter( 'manage_' . $taxonomy . '_custom_column', array( $this, 'term_row' ), 15, 3 );
|
59 |
+
add_action( $taxonomy . '_edit_form_fields', array( $this, 'edit_form' ), 10, 2 );
|
60 |
+
}
|
61 |
+
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Edit Taxonomy Columns
|
66 |
+
*
|
67 |
+
* Insert a new column on wp-admin/edit-tags.php.
|
68 |
+
*
|
69 |
+
* @param array A list of columns.
|
70 |
+
* @return array List of columns with "Images" inserted after the checkbox.
|
71 |
+
*
|
72 |
+
* @internal Private. Called via the `manage_edit-{$taxonomy}_columns` filter.
|
73 |
+
*/
|
74 |
+
public function taxonomy_columns( $original_columns ) {
|
75 |
+
|
76 |
+
$new_columns = $original_columns;
|
77 |
+
array_splice( $new_columns, 1 );
|
78 |
+
$new_columns[ $this->term_image_column_id ] = esc_html__( 'Image', 'taxonomy-images' );
|
79 |
+
|
80 |
+
return array_merge( $new_columns, $original_columns );
|
81 |
+
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Edit Term Row
|
86 |
+
*
|
87 |
+
* Create image control for each term row of wp-admin/edit-tags.php.
|
88 |
+
*
|
89 |
+
* @param string Row.
|
90 |
+
* @param string Name of the current column.
|
91 |
+
* @param integer Term ID.
|
92 |
+
* @return string HTML image control.
|
93 |
+
*
|
94 |
+
* @internal Private. Called via the `manage_{$taxonomy}_custom_column` filter.
|
95 |
+
*/
|
96 |
+
public function term_row( $row, $column_name, $term_id ) {
|
97 |
+
|
98 |
+
if ( $this->term_image_column_id === $column_name ) {
|
99 |
+
|
100 |
+
$control = new Term_Image_Admin_Control( $term_id );
|
101 |
+
|
102 |
+
return $row . $control->get_rendered();
|
103 |
+
|
104 |
+
}
|
105 |
+
|
106 |
+
return $row;
|
107 |
+
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Edit Term Form
|
112 |
+
*
|
113 |
+
* Create image control for `wp-admin/term.php`.
|
114 |
+
*
|
115 |
+
* @param WP_Term Term object.
|
116 |
+
* @param string Taxonomy slug.
|
117 |
+
*
|
118 |
+
* @internal Private. Called via the `{$taxonomy}_edit_form_fields` action.
|
119 |
+
*/
|
120 |
+
public function edit_form( $term, $taxonomy ) {
|
121 |
+
|
122 |
+
$image_types = $this->image_types->get_image_types( $taxonomy );
|
123 |
+
|
124 |
+
foreach ( $image_types as $image_type ) {
|
125 |
+
|
126 |
+
$control = new Term_Image_Admin_Control( $term->term_id, $image_type->get_id() );
|
127 |
+
|
128 |
+
?>
|
129 |
+
<tr class="form-field hide-if-no-js">
|
130 |
+
<th scope="row" valign="top">
|
131 |
+
<label for="description"><?php printf( esc_html__( '%s Image', 'taxonomy-images' ), esc_html( $image_type->get_label() ) ); ?></label>
|
132 |
+
</th>
|
133 |
+
<td><?php echo $control->get_rendered( 'large' ); ?></td>
|
134 |
+
</tr>
|
135 |
+
<?php
|
136 |
+
|
137 |
+
}
|
138 |
+
|
139 |
+
}
|
140 |
+
|
141 |
+
/**
|
142 |
+
* Enqueue Admin Scripts
|
143 |
+
*
|
144 |
+
* @internal Private. Called via the `admin_enqueue_scripts` action.
|
145 |
+
*/
|
146 |
+
public function enqueue_scripts() {
|
147 |
+
|
148 |
+
if ( ! $this->is_term_admin_screen() ) {
|
149 |
+
return;
|
150 |
+
}
|
151 |
+
|
152 |
+
wp_enqueue_media();
|
153 |
+
|
154 |
+
wp_enqueue_script(
|
155 |
+
'taxonomy-images-media-modal',
|
156 |
+
Plugin::plugin_url( 'plugin/assets/js/media-modal.js' ),
|
157 |
+
array( 'jquery' ),
|
158 |
+
Plugin::VERSION
|
159 |
+
);
|
160 |
+
|
161 |
+
wp_localize_script( 'taxonomy-images-media-modal', 'TaxonomyImagesMediaModal', array(
|
162 |
+
'wp_media_post_id' => 0,
|
163 |
+
'attachment_id' => 0,
|
164 |
+
'uploader_title' => __( 'Featured Image', 'taxonomy-images' ),
|
165 |
+
'uploader_button_text' => __( 'Set featured image', 'taxonomy-images' ),
|
166 |
+
'default_img_src' => Plugin::plugin_url( 'plugin/assets/images/default.png' )
|
167 |
+
) );
|
168 |
+
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Enqueue Admin Styles
|
173 |
+
*
|
174 |
+
* @internal Private. Called via the `admin_print_styles-{$page}` action.
|
175 |
+
*/
|
176 |
+
public function enqueue_styles() {
|
177 |
+
|
178 |
+
if ( ! $this->is_term_admin_screen() ) {
|
179 |
+
return;
|
180 |
+
}
|
181 |
+
|
182 |
+
wp_enqueue_style(
|
183 |
+
'taxonomy-image-plugin-edit-tags',
|
184 |
+
Plugin::plugin_url( 'plugin/assets/css/admin.css' ),
|
185 |
+
array(),
|
186 |
+
Plugin::VERSION,
|
187 |
+
'screen'
|
188 |
+
);
|
189 |
+
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Is Term Admin Screen?
|
194 |
+
*
|
195 |
+
* @return boolean
|
196 |
+
*/
|
197 |
+
private function is_term_admin_screen() {
|
198 |
+
|
199 |
+
if ( ! function_exists( 'get_current_screen' ) ) {
|
200 |
+
return false;
|
201 |
+
}
|
202 |
+
|
203 |
+
$screen = get_current_screen();
|
204 |
+
|
205 |
+
if ( ! isset( $screen->taxonomy ) ) {
|
206 |
+
return false;
|
207 |
+
}
|
208 |
+
|
209 |
+
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
210 |
+
if ( ! isset( $settings['taxonomies'] ) ) {
|
211 |
+
return false;
|
212 |
+
}
|
213 |
+
|
214 |
+
if ( in_array( $screen->taxonomy, $settings['taxonomies'] ) ) {
|
215 |
+
return true;
|
216 |
+
}
|
217 |
+
|
218 |
+
return false;
|
219 |
+
|
220 |
+
}
|
221 |
+
|
222 |
+
}
|
plugin/includes/theme-class.php
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @package Taxonomy Images
|
5 |
+
* @subpackage Theme
|
6 |
+
*
|
7 |
+
* Prints custom css to all public pages. If you do not
|
8 |
+
* wish to have these styles included for you, please
|
9 |
+
* insert the following code into your theme's functions.php
|
10 |
+
* file:
|
11 |
+
*
|
12 |
+
* add_filter( 'taxonomy_images_disable_theme_css', '__return_true' );
|
13 |
+
*/
|
14 |
+
|
15 |
+
namespace Plugins\Taxonomy_Images;
|
16 |
+
|
17 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
18 |
+
|
19 |
+
class Theme {
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Enqueue Styles
|
23 |
+
*
|
24 |
+
* @internal Private. Called via the `wp_enqueue_scripts` action.
|
25 |
+
*/
|
26 |
+
public function enqueue_styles() {
|
27 |
+
|
28 |
+
if ( apply_filters( 'taxonomy_images_disable_theme_css', false ) ) {
|
29 |
+
return;
|
30 |
+
}
|
31 |
+
|
32 |
+
wp_enqueue_style(
|
33 |
+
'taxonomy-image-plugin-public',
|
34 |
+
Plugin::plugin_url( 'plugin/assets/css/theme.css' ),
|
35 |
+
array(),
|
36 |
+
Plugin::VERSION,
|
37 |
+
'screen'
|
38 |
+
);
|
39 |
+
|
40 |
+
}
|
41 |
+
|
42 |
+
}
|
plugin/includes/upgrade-class.php
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @package Taxonomy Images
|
5 |
+
* @subpackage Upgrade
|
6 |
+
*/
|
7 |
+
|
8 |
+
namespace Plugins\Taxonomy_Images;
|
9 |
+
|
10 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
11 |
+
|
12 |
+
class Upgrade {
|
13 |
+
|
14 |
+
/**
|
15 |
+
* Upgrade If Required
|
16 |
+
*
|
17 |
+
* Check if the plugin version has changed and if so
|
18 |
+
* run any upgrade routines.
|
19 |
+
*
|
20 |
+
* @internal Private. Called via the `admin_init` action.
|
21 |
+
*/
|
22 |
+
public function upgrade_if_required() {
|
23 |
+
|
24 |
+
$current_version = get_option( 'taxonomy_images_version' );
|
25 |
+
|
26 |
+
if ( empty( $current_version ) || version_compare( Plugin::VERSION, $current_version, '>' ) ) {
|
27 |
+
$this->upgrade( $current_version, Plugin::VERSION );
|
28 |
+
}
|
29 |
+
|
30 |
+
}
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Upgrade
|
34 |
+
*
|
35 |
+
* @param string $from Upgrade from version.
|
36 |
+
* @param string $to Upgrade to version.
|
37 |
+
*/
|
38 |
+
private function upgrade( $from, $to ) {
|
39 |
+
|
40 |
+
// Clean Install
|
41 |
+
if ( empty( $from ) ) {
|
42 |
+
|
43 |
+
$default_settings = array(
|
44 |
+
'taxonomies' => array()
|
45 |
+
);
|
46 |
+
add_option( 'taxonomy_image_plugin_settings', $default_settings );
|
47 |
+
|
48 |
+
}
|
49 |
+
|
50 |
+
// Update version
|
51 |
+
update_option( 'taxonomy_images_version', $to );
|
52 |
+
|
53 |
+
}
|
54 |
+
|
55 |
+
}
|
plugin/plugin.php
ADDED
@@ -0,0 +1,349 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* @package Taxononomy Images
|
5 |
+
* @subpackage Plugin
|
6 |
+
*
|
7 |
+
* Requires WordPress 4.4+ (for term meta support)
|
8 |
+
* Requires PHP 5.3+ (for namespace support)
|
9 |
+
*/
|
10 |
+
|
11 |
+
namespace Plugins\Taxonomy_Images;
|
12 |
+
|
13 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
14 |
+
|
15 |
+
add_action( 'plugins_loaded', array( __NAMESPACE__ . '\Plugin', 'load' ) );
|
16 |
+
|
17 |
+
class Plugin {
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Plugin Version
|
21 |
+
*
|
22 |
+
* @var string
|
23 |
+
*/
|
24 |
+
const VERSION = '0.9.6';
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Plugin Directory
|
28 |
+
*
|
29 |
+
* Used to cache string or subsequent queries.
|
30 |
+
*
|
31 |
+
* @var string
|
32 |
+
*/
|
33 |
+
private static $plugin_dir = '';
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Basename
|
37 |
+
*
|
38 |
+
* Used to cache string or subsequent queries.
|
39 |
+
*
|
40 |
+
* @var string
|
41 |
+
*/
|
42 |
+
private static $basename = null;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Plugin Directory URL
|
46 |
+
*
|
47 |
+
* Used to cache string or subsequent queries.
|
48 |
+
*
|
49 |
+
* @var string
|
50 |
+
*/
|
51 |
+
private static $plugin_dir_url = '';
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Image Types Class
|
55 |
+
*
|
56 |
+
* @var Image_Types|null
|
57 |
+
*/
|
58 |
+
private static $image_types = null;
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Image Admin AJAX Class
|
62 |
+
*
|
63 |
+
* Manages AJAX saving, updating and deleting of term images.
|
64 |
+
*
|
65 |
+
* @var Image_Admin_AJAX|null
|
66 |
+
*/
|
67 |
+
private static $ajax = null;
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Cache Class
|
71 |
+
*
|
72 |
+
* Manages caching of term image data.
|
73 |
+
*
|
74 |
+
* @var Cache|null
|
75 |
+
*/
|
76 |
+
private static $cache = null;
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Upgrade Class
|
80 |
+
*
|
81 |
+
* @var Upgrade|null
|
82 |
+
*/
|
83 |
+
private static $upgrade = null;
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Settings Admin Class
|
87 |
+
*
|
88 |
+
* @var Settings_Admin|null
|
89 |
+
*/
|
90 |
+
private static $settings_admin = null;
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Terms Admin Class
|
94 |
+
*
|
95 |
+
* @var Terms_Admin|null
|
96 |
+
*/
|
97 |
+
private static $terms_admin = null;
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Theme Class
|
101 |
+
*
|
102 |
+
* @var Theme|null
|
103 |
+
*/
|
104 |
+
private static $theme = null;
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Legacy Class
|
108 |
+
*
|
109 |
+
* @var Legacy|null
|
110 |
+
*/
|
111 |
+
private static $legacy = null;
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Load
|
115 |
+
*
|
116 |
+
* Require plugin files depending on the context: AJAX, Admin, Public.
|
117 |
+
* Set up all API action/filter hooks.
|
118 |
+
*
|
119 |
+
* @internal Private. Called via the `plugins_loaded` action.
|
120 |
+
*/
|
121 |
+
public static function load() {
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Legacy Migration & Compatibility
|
125 |
+
*/
|
126 |
+
|
127 |
+
self::require_plugin_files( array(
|
128 |
+
'plugin/includes/legacy-class.php',
|
129 |
+
'plugin/includes/legacy-hooks.php'
|
130 |
+
) );
|
131 |
+
|
132 |
+
$legacy_hooks = new Legacy_Hooks();
|
133 |
+
$legacy_hooks->setup_hooks();
|
134 |
+
|
135 |
+
self::$legacy = new Legacy();
|
136 |
+
|
137 |
+
/**
|
138 |
+
* AJAX, Admin & Front-end
|
139 |
+
*/
|
140 |
+
|
141 |
+
self::require_plugin_files( array(
|
142 |
+
'plugin/includes/term-image-class.php',
|
143 |
+
'plugin/includes/image-type-class.php',
|
144 |
+
'plugin/includes/image-types-class.php'
|
145 |
+
) );
|
146 |
+
|
147 |
+
add_action( 'init', array( get_class(), 'load_textdomain' ) );
|
148 |
+
|
149 |
+
self::$image_types = new Image_Types();
|
150 |
+
|
151 |
+
add_action( 'init', array( self::$image_types, 'register_image_types' ) );
|
152 |
+
|
153 |
+
if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) {
|
154 |
+
|
155 |
+
/**
|
156 |
+
* AJAX only
|
157 |
+
*/
|
158 |
+
|
159 |
+
self::require_plugin_files( array(
|
160 |
+
'plugin/includes/term-image-admin-control-class.php',
|
161 |
+
'plugin/includes/image-admin-ajax-class.php'
|
162 |
+
) );
|
163 |
+
|
164 |
+
self::$ajax = new Image_Admin_AJAX();
|
165 |
+
|
166 |
+
add_action( 'wp_ajax_taxonomy_images_update_term_image', array( self::$ajax, 'update_term_image' ) );
|
167 |
+
add_action( 'wp_ajax_taxonomy_images_delete_term_image', array( self::$ajax, 'delete_term_image' ) );
|
168 |
+
|
169 |
+
} else {
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Admin & Front-end
|
173 |
+
*/
|
174 |
+
|
175 |
+
self::require_plugin_files( array(
|
176 |
+
'plugin/includes/cache-class.php'
|
177 |
+
) );
|
178 |
+
|
179 |
+
self::$cache = new Cache();
|
180 |
+
|
181 |
+
add_action( 'template_redirect', array( self::$cache, 'cache_queried_images' ) );
|
182 |
+
|
183 |
+
if ( is_admin() ) {
|
184 |
+
|
185 |
+
/**
|
186 |
+
* Admin only
|
187 |
+
*/
|
188 |
+
|
189 |
+
self::require_plugin_files( array(
|
190 |
+
'plugin/includes/upgrade-class.php',
|
191 |
+
'plugin/includes/term-image-admin-control-class.php',
|
192 |
+
'plugin/includes/terms-admin-class.php',
|
193 |
+
'plugin/includes/settings-admin-class.php'
|
194 |
+
) );
|
195 |
+
|
196 |
+
self::$upgrade = new Upgrade();
|
197 |
+
|
198 |
+
add_action( 'admin_init', array( self::$upgrade, 'upgrade_if_required' ) );
|
199 |
+
|
200 |
+
self::$settings_admin = new Settings_Admin();
|
201 |
+
|
202 |
+
add_action( 'admin_menu', array( self::$settings_admin, 'settings_menu' ) );
|
203 |
+
add_action( 'admin_init', array( self::$settings_admin, 'register_settings' ) );
|
204 |
+
add_filter( 'plugin_row_meta', array( self::$settings_admin, 'plugin_row_meta' ), 10, 2 );
|
205 |
+
|
206 |
+
self::$terms_admin = new Terms_Admin( self::$image_types );
|
207 |
+
|
208 |
+
add_action( 'admin_init', array( self::$terms_admin, 'add_admin_fields' ) );
|
209 |
+
add_action( 'admin_enqueue_scripts', array( self::$terms_admin, 'enqueue_scripts' ) );
|
210 |
+
add_action( 'admin_print_styles-edit-tags.php', array( self::$terms_admin, 'enqueue_styles' ) ); // Pre WordPress 4.5
|
211 |
+
add_action( 'admin_print_styles-term.php', array( self::$terms_admin, 'enqueue_styles' ) ); // WordPress 4.5+
|
212 |
+
|
213 |
+
} else {
|
214 |
+
|
215 |
+
/**
|
216 |
+
* Front-end Only
|
217 |
+
*/
|
218 |
+
|
219 |
+
self::require_plugin_file( 'plugin/includes/theme-class.php' );
|
220 |
+
|
221 |
+
self::$theme = new Theme();
|
222 |
+
|
223 |
+
add_action( 'wp_enqueue_scripts', array( self::$theme, 'enqueue_styles' ) );
|
224 |
+
|
225 |
+
}
|
226 |
+
|
227 |
+
}
|
228 |
+
|
229 |
+
}
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Load Plugin Text Domain
|
233 |
+
*
|
234 |
+
* @internal Private. Called via the `init` action.
|
235 |
+
*/
|
236 |
+
public static function load_textdomain() {
|
237 |
+
|
238 |
+
load_plugin_textdomain( 'taxonomy-images', false, dirname( self::basename() ) . '/languages/' );
|
239 |
+
|
240 |
+
}
|
241 |
+
|
242 |
+
/**
|
243 |
+
* Require plugin files
|
244 |
+
*
|
245 |
+
* @param array $files File paths relative to plugin folder.
|
246 |
+
*/
|
247 |
+
private static function require_plugin_files( $files ) {
|
248 |
+
|
249 |
+
foreach ( $files as $file ) {
|
250 |
+
require_once( self::plugin_file( $file ) );
|
251 |
+
}
|
252 |
+
|
253 |
+
}
|
254 |
+
|
255 |
+
/**
|
256 |
+
* Require plugin file
|
257 |
+
*
|
258 |
+
* @param string $file File path relative to plugin folder.
|
259 |
+
*/
|
260 |
+
private static function require_plugin_file( $file ) {
|
261 |
+
|
262 |
+
require_once( self::plugin_file( $file ) );
|
263 |
+
|
264 |
+
}
|
265 |
+
|
266 |
+
/**
|
267 |
+
* Get a path to a file within this plugin folder
|
268 |
+
*
|
269 |
+
* @param string $file File path relative to plugin directory.
|
270 |
+
* @return string Absolute file path.
|
271 |
+
*/
|
272 |
+
private static function plugin_file( $file = '' ) {
|
273 |
+
|
274 |
+
return self::plugin_dir() . $file;
|
275 |
+
|
276 |
+
}
|
277 |
+
|
278 |
+
/**
|
279 |
+
* Get the base URL to this plugin folder
|
280 |
+
*
|
281 |
+
* @return string Absolute path to plugin directory.
|
282 |
+
*/
|
283 |
+
private static function plugin_dir_url() {
|
284 |
+
|
285 |
+
// Get and cache plugin directory URL
|
286 |
+
if ( empty( self::$plugin_dir_url ) ) {
|
287 |
+
self::$plugin_dir_url = trailingslashit( plugin_dir_url( self::file() ) );
|
288 |
+
}
|
289 |
+
|
290 |
+
return self::$plugin_dir_url;
|
291 |
+
|
292 |
+
}
|
293 |
+
|
294 |
+
/**
|
295 |
+
* Get a URL to a file within this plugin folder
|
296 |
+
*
|
297 |
+
* @param string $file File path relative to plugin directory.
|
298 |
+
* @return string URL for file path.
|
299 |
+
*/
|
300 |
+
public static function plugin_url( $file = '' ) {
|
301 |
+
|
302 |
+
return self::plugin_dir_url() . $file;
|
303 |
+
|
304 |
+
}
|
305 |
+
|
306 |
+
/**
|
307 |
+
* Get the base path to this plugin folder
|
308 |
+
*
|
309 |
+
* @return string Plugin directory name.
|
310 |
+
*/
|
311 |
+
private static function plugin_dir() {
|
312 |
+
|
313 |
+
// Get and cache plugin directory
|
314 |
+
if ( empty( self::$plugin_dir ) ) {
|
315 |
+
self::$plugin_dir = trailingslashit( dirname( self::file() ) );
|
316 |
+
}
|
317 |
+
|
318 |
+
return self::$plugin_dir;
|
319 |
+
|
320 |
+
}
|
321 |
+
|
322 |
+
/**
|
323 |
+
* Plugin Basename
|
324 |
+
*
|
325 |
+
* @return string Plugin basename.
|
326 |
+
*/
|
327 |
+
public static function basename() {
|
328 |
+
|
329 |
+
// Get and cache basename
|
330 |
+
if ( is_null( self::$basename ) ) {
|
331 |
+
self::$basename = plugin_basename( self::file() );
|
332 |
+
}
|
333 |
+
|
334 |
+
return self::$basename;
|
335 |
+
|
336 |
+
}
|
337 |
+
|
338 |
+
/**
|
339 |
+
* Plugin File
|
340 |
+
*
|
341 |
+
* @return string Plugin base file.
|
342 |
+
*/
|
343 |
+
public static function file() {
|
344 |
+
|
345 |
+
return TAXONOMY_IMAGES_FILE;
|
346 |
+
|
347 |
+
}
|
348 |
+
|
349 |
+
}
|
readme.txt
CHANGED
@@ -2,9 +2,9 @@
|
|
2 |
Contributors: mfields, husobj, jamiemchale
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QSYTTQZBRKQVE
|
4 |
Tags: taxonomy, tag, category, term, image, upload, media
|
5 |
-
Requires at least: 3.
|
6 |
-
Tested up to:
|
7 |
-
Stable tag: 0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -163,7 +163,7 @@ $terms = apply_filters( 'taxonomy-images-get-terms', '' );
|
|
163 |
if ( ! empty( $terms ) ) {
|
164 |
print '<ul>';
|
165 |
foreach ( (array) $terms as $term ) {
|
166 |
-
print '<li><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'detail' ) . '</li>';
|
167 |
}
|
168 |
print '</ul>';
|
169 |
}
|
@@ -209,6 +209,12 @@ The original author of this plugin, Michael Fields, released a handful of plugin
|
|
209 |
|
210 |
== Upgrade Notice ==
|
211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
= 0.9.6 =
|
213 |
Fixed issue where if no terms have images but 'having_images' is false, nothing would be returned (props Matt).
|
214 |
|
@@ -238,6 +244,17 @@ Complete rewrite. Better everything. Many bug fixes.
|
|
238 |
|
239 |
== Changelog ==
|
240 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
= 0.9.6 =
|
242 |
* __BUGFIX:__ Fix issue where if no terms have images but 'having_images' is false, nothing would be returned (props Matt).
|
243 |
|
2 |
Contributors: mfields, husobj, jamiemchale
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QSYTTQZBRKQVE
|
4 |
Tags: taxonomy, tag, category, term, image, upload, media
|
5 |
+
Requires at least: 3.5
|
6 |
+
Tested up to: 5.2.1
|
7 |
+
Stable tag: 1.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
163 |
if ( ! empty( $terms ) ) {
|
164 |
print '<ul>';
|
165 |
foreach ( (array) $terms as $term ) {
|
166 |
+
print '<li><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'detail' ) . '</a></li>';
|
167 |
}
|
168 |
print '</ul>';
|
169 |
}
|
209 |
|
210 |
== Upgrade Notice ==
|
211 |
|
212 |
+
= 1.0 =
|
213 |
+
Fixed full image size sometimes not being returned. Prepare plugin structure for term meta compatibility.
|
214 |
+
|
215 |
+
= 0.9.7 =
|
216 |
+
Remove use of deprecated `image_resize` function. Bump minimum WordPress version to 3.5.
|
217 |
+
|
218 |
= 0.9.6 =
|
219 |
Fixed issue where if no terms have images but 'having_images' is false, nothing would be returned (props Matt).
|
220 |
|
244 |
|
245 |
== Changelog ==
|
246 |
|
247 |
+
= Unreleased =
|
248 |
+
|
249 |
+
= 1.0 =
|
250 |
+
* __BUGFIX:__ Fixed full image size sometimes not being returned.
|
251 |
+
* __UPDATE:__ Control, blank and default images moves to `images` folder.
|
252 |
+
* __UPDATE:__ Prepare plugin structure for term meta compatibility.
|
253 |
+
|
254 |
+
= 0.9.7 =
|
255 |
+
* __UPDATE:__ Remove use of deprecated `image_resize` function.
|
256 |
+
* __UPDATE:__ Bump minimum WordPress version to 3.5.
|
257 |
+
|
258 |
= 0.9.6 =
|
259 |
* __BUGFIX:__ Fix issue where if no terms have images but 'having_images' is false, nothing would be returned (props Matt).
|
260 |
|
taxonomy-images.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
Plugin Name: Taxonomy Images
|
5 |
Plugin URI: https://github.com/benhuson/Taxonomy-Images
|
6 |
Description: Associate images from your media library to categories, tags and custom taxonomies.
|
7 |
-
Version: 0
|
8 |
Author: Michael Fields, Ben Huson
|
9 |
Author URI: https://github.com/benhuson
|
10 |
License: GNU General Public License v2 or later
|
@@ -26,1236 +26,22 @@ along with this program; if not, write to the Free Software
|
|
26 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
27 |
*/
|
28 |
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
/**
|
35 |
-
* Version Number.
|
36 |
-
*
|
37 |
-
* @return string The plugin's version number.
|
38 |
-
* @access private
|
39 |
-
* @since 0.7
|
40 |
-
* @alter 0.7.4
|
41 |
-
*/
|
42 |
-
function taxonomy_image_plugin_version() {
|
43 |
-
return '0.9.6';
|
44 |
-
}
|
45 |
-
|
46 |
-
|
47 |
-
/**
|
48 |
-
* Get a url to a file in this plugin.
|
49 |
-
*
|
50 |
-
* @return string
|
51 |
-
* @access private
|
52 |
-
* @since 0.7
|
53 |
-
*/
|
54 |
-
function taxonomy_image_plugin_url( $file = '' ) {
|
55 |
-
static $path = '';
|
56 |
-
if ( empty( $path ) ) {
|
57 |
-
$path = plugin_dir_url( __FILE__ );
|
58 |
-
}
|
59 |
-
return $path . $file;
|
60 |
-
}
|
61 |
-
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Detail Image Size.
|
65 |
-
*
|
66 |
-
* @return array Configuration for the "detail" image size.
|
67 |
-
* @access private
|
68 |
-
* @since 0.7
|
69 |
-
*/
|
70 |
-
function taxonomy_image_plugin_detail_image_size() {
|
71 |
-
return array(
|
72 |
-
'name' => 'detail',
|
73 |
-
'size' => array( 150, 150, true )
|
74 |
-
);
|
75 |
-
}
|
76 |
-
|
77 |
-
|
78 |
-
/**
|
79 |
-
* Register custom image size with WordPress.
|
80 |
-
*
|
81 |
-
* @access private
|
82 |
-
* @since 2010-10-28
|
83 |
-
*/
|
84 |
-
function taxonomy_image_plugin_add_image_size() {
|
85 |
-
$detail = taxonomy_image_plugin_detail_image_size();
|
86 |
-
add_image_size(
|
87 |
-
$detail['name'],
|
88 |
-
$detail['size'][0],
|
89 |
-
$detail['size'][1],
|
90 |
-
$detail['size'][2]
|
91 |
-
);
|
92 |
-
}
|
93 |
-
add_action( 'init', 'taxonomy_image_plugin_add_image_size' );
|
94 |
-
|
95 |
-
|
96 |
-
/**
|
97 |
-
* Load Plugin Text Domain.
|
98 |
-
*
|
99 |
-
* @access private
|
100 |
-
* @since 0.7.3
|
101 |
-
*/
|
102 |
-
function taxonomy_image_plugin_text_domain() {
|
103 |
-
load_plugin_textdomain( 'taxonomy-images', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
104 |
-
}
|
105 |
-
add_action( 'init', 'taxonomy_image_plugin_text_domain' );
|
106 |
-
|
107 |
-
|
108 |
-
/**
|
109 |
-
* Modal Button.
|
110 |
-
*
|
111 |
-
* Create a button in the modal media window to associate the current image to the term.
|
112 |
-
*
|
113 |
-
* @param array Multidimensional array representing the images form.
|
114 |
-
* @param stdClass WordPress post object.
|
115 |
-
* @return array The image's form array with added button if modal window was accessed by this script.
|
116 |
-
*
|
117 |
-
* @access private
|
118 |
-
* @since 2010-10-28
|
119 |
-
* @alter 0.7
|
120 |
-
*/
|
121 |
-
function taxonomy_image_plugin_modal_button( $fields, $post ) {
|
122 |
-
if ( isset( $fields['image-size'] ) && isset( $post->ID ) ) {
|
123 |
-
$image_id = (int) $post->ID;
|
124 |
-
|
125 |
-
$o = '<div class="taxonomy-image-modal-control" id="' . esc_attr( 'taxonomy-image-modal-control-' . $image_id ) . '">';
|
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 |
-
$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>';
|
128 |
-
$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 ) . '" />';
|
129 |
-
$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' ) ) . '" />';
|
130 |
-
$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' ) ) . '" />';
|
131 |
-
$o .= '</div>';
|
132 |
-
|
133 |
-
$fields['image-size']['extra_rows']['taxonomy-image-plugin-button']['html'] = $o;
|
134 |
-
}
|
135 |
-
return $fields;
|
136 |
-
}
|
137 |
-
add_filter( 'attachment_fields_to_edit', 'taxonomy_image_plugin_modal_button', 20, 2 );
|
138 |
-
|
139 |
-
|
140 |
-
/**
|
141 |
-
* Get Image Source.
|
142 |
-
*
|
143 |
-
* Return a uri to a custom image size.
|
144 |
-
*
|
145 |
-
* If size doesn't exist, attempt to create a resized version.
|
146 |
-
* The output of this function should be escaped before printing to the browser.
|
147 |
-
*
|
148 |
-
* @param int Image ID.
|
149 |
-
* @return string URI of custom image on success; emtpy string otherwise.
|
150 |
-
*
|
151 |
-
* @access private.
|
152 |
-
* @since 2010-10-28
|
153 |
-
*/
|
154 |
-
function taxonomy_image_plugin_get_image_src( $id ) {
|
155 |
-
$detail = taxonomy_image_plugin_detail_image_size();
|
156 |
-
|
157 |
-
/* Return url to custom intermediate size if it exists. */
|
158 |
-
$img = image_get_intermediate_size( $id, $detail['name'] );
|
159 |
-
if ( isset( $img['url'] ) ) {
|
160 |
-
return $img['url'];
|
161 |
-
}
|
162 |
-
|
163 |
-
/* Detail image does not exist, attempt to create it. */
|
164 |
-
$wp_upload_dir = wp_upload_dir();
|
165 |
-
if ( isset( $wp_upload_dir['basedir'] ) ) {
|
166 |
-
|
167 |
-
/* Create path to original uploaded image. */
|
168 |
-
$path = trailingslashit( $wp_upload_dir['basedir'] ) . get_post_meta( $id, '_wp_attached_file', true );
|
169 |
-
if ( is_file( $path ) ) {
|
170 |
-
|
171 |
-
/* Attempt to create a new downsized version of the original image. */
|
172 |
-
$new = image_resize( $path,
|
173 |
-
$detail['size'][0],
|
174 |
-
$detail['size'][1],
|
175 |
-
$detail['size'][2]
|
176 |
-
);
|
177 |
-
|
178 |
-
/* Image creation successful. Generate and cache image metadata. Return url. */
|
179 |
-
if ( ! is_wp_error( $new ) ) {
|
180 |
-
$meta = wp_generate_attachment_metadata( $id, $path );
|
181 |
-
wp_update_attachment_metadata( $id, $meta );
|
182 |
-
$img = image_get_intermediate_size( $id, $detail['name'] );
|
183 |
-
if ( isset( $img['url'] ) ) {
|
184 |
-
return $img['url'];
|
185 |
-
}
|
186 |
-
}
|
187 |
-
}
|
188 |
-
}
|
189 |
-
|
190 |
-
/* Custom intermediate size cannot be created, try for thumbnail. */
|
191 |
-
$img = image_get_intermediate_size( $id, 'thumbnail' );
|
192 |
-
if ( isset( $img['url'] ) ) {
|
193 |
-
return $img['url'];
|
194 |
-
}
|
195 |
-
|
196 |
-
/* Thumbnail cannot be found, try fullsize. */
|
197 |
-
$url = wp_get_attachment_url( $id );
|
198 |
-
if ( ! empty( $url ) ) {
|
199 |
-
return $url;
|
200 |
-
}
|
201 |
-
|
202 |
-
/**
|
203 |
-
* No image can be found.
|
204 |
-
* This is most likely caused by a user deleting an attachment before deleting it's association with a taxonomy.
|
205 |
-
* If we are in the administration panels:
|
206 |
-
* - Delete the association.
|
207 |
-
* - Return uri to default.png.
|
208 |
-
*/
|
209 |
-
if ( is_admin() ) {
|
210 |
-
$assoc = taxonomy_image_plugin_get_associations();
|
211 |
-
foreach ( $assoc as $term => $img ) {
|
212 |
-
if ( $img === $id ) {
|
213 |
-
unset( $assoc[ $term ] );
|
214 |
-
}
|
215 |
-
}
|
216 |
-
update_option( 'taxonomy_image_plugin', $assoc );
|
217 |
-
return taxonomy_image_plugin_url( 'default.png' );
|
218 |
-
}
|
219 |
-
|
220 |
-
/*
|
221 |
-
* No image can be found.
|
222 |
-
* Return path to blank-image.png.
|
223 |
-
*/
|
224 |
-
return taxonomy_image_plugin_url( 'blank.png' );
|
225 |
-
}
|
226 |
-
|
227 |
-
|
228 |
-
/**
|
229 |
-
* Sanitize Associations.
|
230 |
-
*
|
231 |
-
* Ensures that all key/value pairs are positive integers.
|
232 |
-
* This filter will discard all zero and negative values.
|
233 |
-
*
|
234 |
-
* @param array An array of term_taxonomy_id/attachment_id pairs.
|
235 |
-
* @return array Sanitized version of parameter.
|
236 |
-
*
|
237 |
-
* @access private
|
238 |
-
*/
|
239 |
-
function taxonomy_image_plugin_sanitize_associations( $associations ) {
|
240 |
-
$o = array();
|
241 |
-
foreach ( (array) $associations as $tt_id => $im_id ) {
|
242 |
-
$tt_id = absint( $tt_id );
|
243 |
-
$im_id = absint( $im_id );
|
244 |
-
if ( 0 < $tt_id && 0 < $im_id )
|
245 |
-
$o[ $tt_id ] = $im_id;
|
246 |
-
}
|
247 |
-
return $o;
|
248 |
-
}
|
249 |
-
|
250 |
-
|
251 |
-
/**
|
252 |
-
* Sanitize Settings.
|
253 |
-
*
|
254 |
-
* This function is responsible for ensuring that
|
255 |
-
* all values within the 'taxonomy_image_plugin_settings'
|
256 |
-
* options are of the appropriate type.
|
257 |
-
*
|
258 |
-
* @param array Unknown.
|
259 |
-
* @return array Multi-dimensional array of sanitized settings.
|
260 |
-
*
|
261 |
-
* @access private
|
262 |
-
* @since 0.7
|
263 |
-
*/
|
264 |
-
function taxonomy_image_plugin_settings_sanitize( $dirty ) {
|
265 |
-
$clean = array();
|
266 |
-
if ( isset( $dirty['taxonomies'] ) ) {
|
267 |
-
$taxonomies = get_taxonomies();
|
268 |
-
foreach ( (array) $dirty['taxonomies'] as $taxonomy ) {
|
269 |
-
if ( in_array( $taxonomy, $taxonomies ) )
|
270 |
-
$clean['taxonomies'][] = $taxonomy;
|
271 |
-
}
|
272 |
-
}
|
273 |
-
|
274 |
-
/* translators: Notice displayed on the custom administration page. */
|
275 |
-
$message = __( 'Image support for taxonomies successfully updated', 'taxonomy-images' );
|
276 |
-
if ( empty( $clean ) ) {
|
277 |
-
/* translators: Notice displayed on the custom administration page. */
|
278 |
-
$message = __( 'Image support has been disabled for all taxonomies.', 'taxonomy-images' );
|
279 |
-
}
|
280 |
-
|
281 |
-
add_settings_error( 'taxonomy_image_plugin_settings', 'taxonomies_updated', esc_html( $message ), 'updated' );
|
282 |
-
|
283 |
-
return $clean;
|
284 |
-
}
|
285 |
-
|
286 |
-
|
287 |
-
/**
|
288 |
-
* Register settings with WordPress.
|
289 |
-
*
|
290 |
-
* This plugin will store to sets of settings in the
|
291 |
-
* options table. The first is named 'taxonomy_image_plugin'
|
292 |
-
* and stores the associations between terms and images. The
|
293 |
-
* keys in this array represent the term_taxonomy_id of the
|
294 |
-
* term while the value represents the ID of the image
|
295 |
-
* attachment.
|
296 |
-
*
|
297 |
-
* The second setting is used to store everything else. As of
|
298 |
-
* version 0.7 it has one key named 'taxonomies' whichi is a
|
299 |
-
* flat array consisting of taxonomy names representing a
|
300 |
-
* black-list of registered taxonomies. These taxonomies will
|
301 |
-
* NOT be given an image UI.
|
302 |
-
*
|
303 |
-
* @access private
|
304 |
-
*/
|
305 |
-
function taxonomy_image_plugin_register_settings() {
|
306 |
-
register_setting(
|
307 |
-
'taxonomy_image_plugin',
|
308 |
-
'taxonomy_image_plugin',
|
309 |
-
'taxonomy_image_plugin_sanitize_associations'
|
310 |
-
);
|
311 |
-
register_setting(
|
312 |
-
'taxonomy_image_plugin_settings',
|
313 |
-
'taxonomy_image_plugin_settings',
|
314 |
-
'taxonomy_image_plugin_settings_sanitize'
|
315 |
-
);
|
316 |
-
add_settings_section(
|
317 |
-
'taxonomy_image_plugin_settings',
|
318 |
-
esc_html__( 'Settings', 'taxonomy-images' ),
|
319 |
-
'__return_false',
|
320 |
-
'taxonomy_image_plugin_settings'
|
321 |
-
);
|
322 |
-
add_settings_field(
|
323 |
-
'taxonomy-images',
|
324 |
-
esc_html__( 'Taxonomies', 'taxonomy-images' ),
|
325 |
-
'taxonomy_image_plugin_control_taxonomies',
|
326 |
-
'taxonomy_image_plugin_settings',
|
327 |
-
'taxonomy_image_plugin_settings'
|
328 |
-
);
|
329 |
-
}
|
330 |
-
add_action( 'admin_init', 'taxonomy_image_plugin_register_settings' );
|
331 |
-
|
332 |
-
|
333 |
-
/**
|
334 |
-
* Admin Menu.
|
335 |
-
*
|
336 |
-
* Create the admin menu link for the settings page.
|
337 |
-
*
|
338 |
-
* @access private
|
339 |
-
* @since 0.7
|
340 |
-
*/
|
341 |
-
function taxonomy_images_settings_menu() {
|
342 |
-
add_options_page(
|
343 |
-
esc_html__( 'Taxonomy Images', 'taxonomy-images' ), // HTML <title> tag.
|
344 |
-
esc_html__( 'Taxonomy Images', 'taxonomy-images' ), // Link text in admin menu.
|
345 |
-
'manage_options',
|
346 |
-
'taxonomy_image_plugin_settings',
|
347 |
-
'taxonomy_image_plugin_settings_page'
|
348 |
-
);
|
349 |
-
}
|
350 |
-
add_action( 'admin_menu', 'taxonomy_images_settings_menu' );
|
351 |
-
|
352 |
-
|
353 |
-
/**
|
354 |
-
* Settings Page Template.
|
355 |
-
*
|
356 |
-
* This function in conjunction with others usei the WordPress
|
357 |
-
* Settings API to create a settings page where users can adjust
|
358 |
-
* the behaviour of this plugin. Please see the following functions
|
359 |
-
* for more insight on the output generated by this function:
|
360 |
-
*
|
361 |
-
* taxonomy_image_plugin_control_taxonomies()
|
362 |
-
*
|
363 |
-
* @access private
|
364 |
-
* @since 0.7
|
365 |
-
*/
|
366 |
-
function taxonomy_image_plugin_settings_page() {
|
367 |
-
print "\n" . '<div class="wrap">';
|
368 |
-
|
369 |
-
/* translators: Heading of the custom administration page. */
|
370 |
-
print "\n" . '<h2>' . esc_html__( 'Taxonomy Images Plugin Settings', 'taxonomy-images' ) . '</h2>';
|
371 |
-
print "\n" . '<div id="taxonomy-images">';
|
372 |
-
print "\n" . '<form action="options.php" method="post">';
|
373 |
-
|
374 |
-
settings_fields( 'taxonomy_image_plugin_settings' );
|
375 |
-
do_settings_sections( 'taxonomy_image_plugin_settings' );
|
376 |
-
|
377 |
-
/* translators: Button on the custom administration page. */
|
378 |
-
print "\n" . '<div class="button-holder"><input class="button-primary" name="submit" type="submit" value="' . esc_attr__( 'Save Changes', 'taxonomy-images' ) . '" /></div>';
|
379 |
-
print "\n" . '</div></form></div>';
|
380 |
-
}
|
381 |
-
|
382 |
-
|
383 |
-
/**
|
384 |
-
* Taxonomy Checklist.
|
385 |
-
*
|
386 |
-
* @access private
|
387 |
-
*/
|
388 |
-
function taxonomy_image_plugin_control_taxonomies() {
|
389 |
-
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
390 |
-
$taxonomies = get_taxonomies( array(), 'objects' );
|
391 |
-
foreach ( (array) $taxonomies as $taxonomy ) {
|
392 |
-
if ( ! isset( $taxonomy->name ) ) {
|
393 |
-
continue;
|
394 |
-
}
|
395 |
-
|
396 |
-
if ( ! isset( $taxonomy->label ) ) {
|
397 |
-
continue;
|
398 |
-
}
|
399 |
-
|
400 |
-
if ( ! isset( $taxonomy->show_ui ) || empty( $taxonomy->show_ui ) ) {
|
401 |
-
continue;
|
402 |
-
}
|
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 |
-
|
411 |
-
print "\n" . '<p><label for="' . esc_attr( $id ) . '">';
|
412 |
-
print '<input' . $checked . ' id="' . esc_attr( $id ) . '" type="checkbox" name="taxonomy_image_plugin_settings[taxonomies][]" value="' . esc_attr( $taxonomy->name ) . '" />';
|
413 |
-
print ' ' . esc_html( $taxonomy->label ) . '</label></p>';
|
414 |
-
}
|
415 |
-
}
|
416 |
-
|
417 |
-
|
418 |
-
/**
|
419 |
-
* JSON Respose.
|
420 |
-
* Terminates script execution.
|
421 |
-
*
|
422 |
-
* @param array Associative array of values to be encoded in JSON.
|
423 |
-
*
|
424 |
-
* @access private
|
425 |
-
*/
|
426 |
-
function taxonomy_image_plugin_json_response( $args ) {
|
427 |
-
/* translators: An ajax request has failed for an unknown reason. */
|
428 |
-
$response = wp_parse_args( $args, array(
|
429 |
-
'status' => 'bad',
|
430 |
-
'why' => esc_html__( 'Unknown error encountered', 'taxonomy-images' )
|
431 |
-
) );
|
432 |
-
header( 'Content-type: application/jsonrequest' );
|
433 |
-
print json_encode( $response );
|
434 |
-
exit;
|
435 |
-
}
|
436 |
-
|
437 |
-
|
438 |
-
/**
|
439 |
-
* Get Term Info.
|
440 |
-
*
|
441 |
-
* Returns term info by term_taxonomy_id.
|
442 |
-
*
|
443 |
-
* @param int term_taxonomy_id
|
444 |
-
* @return array Keys: term_id (int) and taxonomy (string).
|
445 |
-
*
|
446 |
-
* @access private
|
447 |
-
*/
|
448 |
-
function taxonomy_image_plugin_get_term_info( $tt_id ) {
|
449 |
-
static $cache = array();
|
450 |
-
if ( isset( $cache[ $tt_id ] ) ) {
|
451 |
-
return $cache[ $tt_id ];
|
452 |
-
}
|
453 |
-
|
454 |
-
global $wpdb;
|
455 |
-
|
456 |
-
$data = $wpdb->get_results( $wpdb->prepare( "SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d LIMIT 1", $tt_id ) );
|
457 |
-
if ( isset( $data[0]->term_id ) ) {
|
458 |
-
$cache[ $tt_id ]['term_id'] = absint( $data[0]->term_id );
|
459 |
-
}
|
460 |
-
|
461 |
-
if ( isset( $data[0]->taxonomy ) ) {
|
462 |
-
$cache[ $tt_id ]['taxonomy'] = $data[0]->taxonomy;
|
463 |
-
}
|
464 |
-
|
465 |
-
if ( isset( $cache[ $tt_id ] ) ) {
|
466 |
-
return $cache[ $tt_id ];
|
467 |
-
}
|
468 |
-
|
469 |
-
return array();
|
470 |
-
}
|
471 |
-
|
472 |
-
|
473 |
-
/**
|
474 |
-
* Check Taxonomy Permissions.
|
475 |
-
*
|
476 |
-
* Allows a permission check to be performed on a term
|
477 |
-
* when all you know is the term_taxonomy_id.
|
478 |
-
*
|
479 |
-
* @param int term_taxonomy_id
|
480 |
-
* @return bool True if user can edit terms, False if not.
|
481 |
-
*
|
482 |
-
* @access private
|
483 |
-
*/
|
484 |
-
function taxonomy_image_plugin_check_permissions( $tt_id ) {
|
485 |
-
$data = taxonomy_image_plugin_get_term_info( $tt_id );
|
486 |
-
if ( ! isset( $data['taxonomy'] ) ) {
|
487 |
-
return false;
|
488 |
-
}
|
489 |
-
|
490 |
-
$taxonomy = get_taxonomy( $data['taxonomy'] );
|
491 |
-
if ( ! isset( $taxonomy->cap->edit_terms ) ) {
|
492 |
-
return false;
|
493 |
-
}
|
494 |
-
|
495 |
-
return current_user_can( $taxonomy->cap->edit_terms );
|
496 |
}
|
497 |
|
|
|
498 |
|
499 |
-
|
500 |
-
* Create an association.
|
501 |
-
*
|
502 |
-
* Callback for the wp_ajax_{$_GET['action']} hook.
|
503 |
-
*
|
504 |
-
* @access private
|
505 |
-
*/
|
506 |
-
function taxonomy_image_plugin_create_association() {
|
507 |
-
if ( ! isset( $_POST['tt_id'] ) ) {
|
508 |
-
taxonomy_image_plugin_json_response( array(
|
509 |
-
'status' => 'bad',
|
510 |
-
'why' => esc_html__( 'tt_id not sent', 'taxonomy-images' ),
|
511 |
-
) );
|
512 |
-
}
|
513 |
-
|
514 |
-
$tt_id = absint( $_POST['tt_id'] );
|
515 |
-
if ( empty( $tt_id ) ) {
|
516 |
-
taxonomy_image_plugin_json_response( array(
|
517 |
-
'status' => 'bad',
|
518 |
-
'why' => esc_html__( 'tt_id is empty', 'taxonomy-images' ),
|
519 |
-
) );
|
520 |
-
}
|
521 |
-
|
522 |
-
if ( ! taxonomy_image_plugin_check_permissions( $tt_id ) ) {
|
523 |
-
taxonomy_image_plugin_json_response( array(
|
524 |
-
'status' => 'bad',
|
525 |
-
'why' => esc_html__( 'You do not have the correct capability to manage this term', 'taxonomy-images' ),
|
526 |
-
) );
|
527 |
-
}
|
528 |
-
|
529 |
-
if ( ! isset( $_POST['wp_nonce'] ) ) {
|
530 |
-
taxonomy_image_plugin_json_response( array(
|
531 |
-
'status' => 'bad',
|
532 |
-
'why' => esc_html__( 'No nonce included.', 'taxonomy-images' ),
|
533 |
-
) );
|
534 |
-
}
|
535 |
-
|
536 |
-
if ( ! wp_verify_nonce( $_POST['wp_nonce'], 'taxonomy-image-plugin-create-association' ) ) {
|
537 |
-
taxonomy_image_plugin_json_response( array(
|
538 |
-
'status' => 'bad',
|
539 |
-
'why' => esc_html__( 'Nonce did not match', 'taxonomy-images' ),
|
540 |
-
) );
|
541 |
-
}
|
542 |
-
|
543 |
-
if ( ! isset( $_POST['attachment_id'] ) ) {
|
544 |
-
taxonomy_image_plugin_json_response( array(
|
545 |
-
'status' => 'bad',
|
546 |
-
'why' => esc_html__( 'Image id not sent', 'taxonomy-images' )
|
547 |
-
) );
|
548 |
-
}
|
549 |
-
|
550 |
-
$image_id = absint( $_POST['attachment_id'] );
|
551 |
-
if ( empty( $image_id ) ) {
|
552 |
-
taxonomy_image_plugin_json_response( array(
|
553 |
-
'status' => 'bad',
|
554 |
-
'why' => esc_html__( 'Image id is not a positive integer', 'taxonomy-images' )
|
555 |
-
) );
|
556 |
-
}
|
557 |
-
|
558 |
-
$assoc = taxonomy_image_plugin_get_associations();
|
559 |
-
$assoc[ $tt_id ] = $image_id;
|
560 |
-
if ( update_option( 'taxonomy_image_plugin', taxonomy_image_plugin_sanitize_associations( $assoc ) ) ) {
|
561 |
-
taxonomy_image_plugin_json_response( array(
|
562 |
-
'status' => 'good',
|
563 |
-
'why' => esc_html__( 'Image successfully associated', 'taxonomy-images' ),
|
564 |
-
'attachment_thumb_src' => taxonomy_image_plugin_get_image_src( $image_id )
|
565 |
-
) );
|
566 |
-
} else {
|
567 |
-
taxonomy_image_plugin_json_response( array(
|
568 |
-
'status' => 'bad',
|
569 |
-
'why' => esc_html__( 'Association could not be created', 'taxonomy-images' )
|
570 |
-
) );
|
571 |
-
}
|
572 |
-
|
573 |
-
/* Don't know why, but something didn't work. */
|
574 |
-
taxonomy_image_plugin_json_response();
|
575 |
-
}
|
576 |
-
add_action( 'wp_ajax_taxonomy_image_create_association', 'taxonomy_image_plugin_create_association' );
|
577 |
-
|
578 |
-
|
579 |
-
/**
|
580 |
-
* Remove an association.
|
581 |
-
*
|
582 |
-
* Removes an association from the setting stored in the database.
|
583 |
-
* Print json encoded message and terminates script execution.
|
584 |
-
*
|
585 |
-
* @access private
|
586 |
-
*/
|
587 |
-
function taxonomy_image_plugin_remove_association() {
|
588 |
-
if ( ! isset( $_POST['tt_id'] ) ) {
|
589 |
-
taxonomy_image_plugin_json_response( array(
|
590 |
-
'status' => 'bad',
|
591 |
-
'why' => esc_html__( 'tt_id not sent', 'taxonomy-images' ),
|
592 |
-
) );
|
593 |
-
}
|
594 |
-
|
595 |
-
$tt_id = absint( $_POST['tt_id'] );
|
596 |
-
if ( empty( $tt_id ) ) {
|
597 |
-
taxonomy_image_plugin_json_response( array(
|
598 |
-
'status' => 'bad',
|
599 |
-
'why' => esc_html__( 'tt_id is empty', 'taxonomy-images' ),
|
600 |
-
) );
|
601 |
-
}
|
602 |
-
|
603 |
-
if ( ! taxonomy_image_plugin_check_permissions( $tt_id ) ) {
|
604 |
-
taxonomy_image_plugin_json_response( array(
|
605 |
-
'status' => 'bad',
|
606 |
-
'why' => esc_html__( 'You do not have the correct capability to manage this term', 'taxonomy-images' ),
|
607 |
-
) );
|
608 |
-
}
|
609 |
-
|
610 |
-
if ( ! isset( $_POST['wp_nonce'] ) ) {
|
611 |
-
taxonomy_image_plugin_json_response( array(
|
612 |
-
'status' => 'bad',
|
613 |
-
'why' => esc_html__( 'No nonce included', 'taxonomy-images' ),
|
614 |
-
) );
|
615 |
-
}
|
616 |
-
|
617 |
-
if ( ! wp_verify_nonce( $_POST['wp_nonce'], 'taxonomy-image-plugin-remove-association') ) {
|
618 |
-
taxonomy_image_plugin_json_response( array(
|
619 |
-
'status' => 'bad',
|
620 |
-
'why' => esc_html__( 'Nonce did not match', 'taxonomy-images' ),
|
621 |
-
) );
|
622 |
-
}
|
623 |
-
|
624 |
-
$assoc = taxonomy_image_plugin_get_associations();
|
625 |
-
if ( ! isset( $assoc[ $tt_id ] ) ) {
|
626 |
-
taxonomy_image_plugin_json_response( array(
|
627 |
-
'status' => 'good',
|
628 |
-
'why' => esc_html__( 'Nothing to remove', 'taxonomy-images' )
|
629 |
-
) );
|
630 |
-
}
|
631 |
-
|
632 |
-
unset( $assoc[ $tt_id ] );
|
633 |
-
|
634 |
-
if ( update_option( 'taxonomy_image_plugin', $assoc ) ) {
|
635 |
-
taxonomy_image_plugin_json_response( array(
|
636 |
-
'status' => 'good',
|
637 |
-
'why' => esc_html__( 'Association successfully removed', 'taxonomy-images' )
|
638 |
-
) );
|
639 |
-
} else {
|
640 |
-
taxonomy_image_plugin_json_response( array(
|
641 |
-
'status' => 'bad',
|
642 |
-
'why' => esc_html__( 'Association could not be removed', 'taxonomy-images' )
|
643 |
-
) );
|
644 |
-
}
|
645 |
-
|
646 |
-
/* Don't know why, but something didn't work. */
|
647 |
-
taxonomy_image_plugin_json_response();
|
648 |
-
}
|
649 |
-
add_action( 'wp_ajax_taxonomy_image_plugin_remove_association', 'taxonomy_image_plugin_remove_association' );
|
650 |
-
|
651 |
-
|
652 |
-
/**
|
653 |
-
* Get a list of user-defined associations.
|
654 |
-
* Associations are stored in the WordPress options table.
|
655 |
-
*
|
656 |
-
* @param bool Should WordPress query the database for the results
|
657 |
-
* @return array List of associations. Key => taxonomy_term_id; Value => image_id
|
658 |
-
*
|
659 |
-
* @access private
|
660 |
-
*/
|
661 |
-
function taxonomy_image_plugin_get_associations( $refresh = false ) {
|
662 |
-
static $associations = array();
|
663 |
-
if ( empty( $associations ) || $refresh ) {
|
664 |
-
$associations = taxonomy_image_plugin_sanitize_associations( get_option( 'taxonomy_image_plugin' ) );
|
665 |
-
}
|
666 |
-
|
667 |
-
return $associations;
|
668 |
-
}
|
669 |
-
add_action( 'init', 'taxonomy_image_plugin_get_associations' );
|
670 |
-
|
671 |
-
|
672 |
-
/**
|
673 |
-
* Dynamically create hooks for each taxonomy.
|
674 |
-
*
|
675 |
-
* Adds hooks for each taxonomy that the user has given
|
676 |
-
* an image interface to via settings page. These hooks
|
677 |
-
* enable the image interface on wp-admin/edit-tags.php.
|
678 |
-
*
|
679 |
-
* @access private
|
680 |
-
* @since 0.4.3
|
681 |
-
* @alter 0.7
|
682 |
-
*/
|
683 |
-
function taxonomy_image_plugin_add_dynamic_hooks() {
|
684 |
-
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
685 |
-
if ( ! isset( $settings['taxonomies'] ) ) {
|
686 |
-
return;
|
687 |
-
}
|
688 |
-
|
689 |
-
foreach ( $settings['taxonomies'] as $taxonomy ) {
|
690 |
-
add_filter( 'manage_' . $taxonomy . '_custom_column', 'taxonomy_image_plugin_taxonomy_rows', 15, 3 );
|
691 |
-
add_filter( 'manage_edit-' . $taxonomy . '_columns', 'taxonomy_image_plugin_taxonomy_columns' );
|
692 |
-
add_action( $taxonomy . '_edit_form_fields', 'taxonomy_image_plugin_edit_tag_form', 10, 2 );
|
693 |
-
}
|
694 |
-
}
|
695 |
-
add_action( 'admin_init', 'taxonomy_image_plugin_add_dynamic_hooks' );
|
696 |
-
|
697 |
-
|
698 |
-
/**
|
699 |
-
* Edit Term Columns.
|
700 |
-
*
|
701 |
-
* Insert a new column on wp-admin/edit-tags.php.
|
702 |
-
*
|
703 |
-
* @see taxonomy_image_plugin_add_dynamic_hooks()
|
704 |
-
*
|
705 |
-
* @param array A list of columns.
|
706 |
-
* @return array List of columns with "Images" inserted after the checkbox.
|
707 |
-
*
|
708 |
-
* @access private
|
709 |
-
* @since 0.4.3
|
710 |
-
*/
|
711 |
-
function taxonomy_image_plugin_taxonomy_columns( $original_columns ) {
|
712 |
-
$new_columns = $original_columns;
|
713 |
-
array_splice( $new_columns, 1 );
|
714 |
-
$new_columns['taxonomy_image_plugin'] = esc_html__( 'Image', 'taxonomy-images' );
|
715 |
-
return array_merge( $new_columns, $original_columns );
|
716 |
-
}
|
717 |
-
|
718 |
-
|
719 |
-
/**
|
720 |
-
* Edit Term Rows.
|
721 |
-
*
|
722 |
-
* Create image control for each term row of wp-admin/edit-tags.php.
|
723 |
-
*
|
724 |
-
* @see taxonomy_image_plugin_add_dynamic_hooks()
|
725 |
-
*
|
726 |
-
* @param string Row.
|
727 |
-
* @param string Name of the current column.
|
728 |
-
* @param int Term ID.
|
729 |
-
* @return string @see taxonomy_image_plugin_control_image()
|
730 |
-
*
|
731 |
-
* @access private
|
732 |
-
* @since 2010-11-08
|
733 |
-
*/
|
734 |
-
function taxonomy_image_plugin_taxonomy_rows( $row, $column_name, $term_id ) {
|
735 |
-
if ( 'taxonomy_image_plugin' === $column_name ) {
|
736 |
-
global $taxonomy;
|
737 |
-
return $row . taxonomy_image_plugin_control_image( $term_id, $taxonomy );
|
738 |
-
}
|
739 |
-
return $row;
|
740 |
-
}
|
741 |
-
|
742 |
-
|
743 |
-
/**
|
744 |
-
* Edit Term Control.
|
745 |
-
*
|
746 |
-
* Create image control for wp-admin/edit-tag-form.php.
|
747 |
-
* Hooked into the '{$taxonomy}_edit_form_fields' action.
|
748 |
-
*
|
749 |
-
* @param stdClass Term object.
|
750 |
-
* @param string Taxonomy slug.
|
751 |
-
*
|
752 |
-
* @access private
|
753 |
-
* @since 2010-11-08
|
754 |
-
*/
|
755 |
-
function taxonomy_image_plugin_edit_tag_form( $term, $taxonomy ) {
|
756 |
-
$taxonomy = get_taxonomy( $taxonomy );
|
757 |
-
$name = __( 'term', 'taxonomy-images' );
|
758 |
-
if ( isset( $taxonomy->labels->singular_name ) )
|
759 |
-
$name = strtolower( $taxonomy->labels->singular_name );
|
760 |
-
?>
|
761 |
-
<tr class="form-field hide-if-no-js">
|
762 |
-
<th scope="row" valign="top"><label for="description"><?php print esc_html__( 'Image', 'taxonomy-images' ) ?></label></th>
|
763 |
-
<td>
|
764 |
-
<?php print taxonomy_image_plugin_control_image( $term->term_id, $taxonomy->name ); ?>
|
765 |
-
<div class="clear"></div>
|
766 |
-
<span class="description"><?php printf( esc_html__( 'Associate an image from your media library to this %1$s.', 'taxonomy-images' ), esc_html( $name ) ); ?></span>
|
767 |
-
</td>
|
768 |
-
</tr>
|
769 |
-
<?php
|
770 |
-
}
|
771 |
-
|
772 |
-
/**
|
773 |
-
* Image Control.
|
774 |
-
*
|
775 |
-
* Creates all image controls on edit-tags.php.
|
776 |
-
*
|
777 |
-
* @todo Remove rel tag from link... will need to adjust js to accomodate.
|
778 |
-
* @since 0.7
|
779 |
-
* @access private
|
780 |
-
*/
|
781 |
-
function taxonomy_image_plugin_control_image( $term_id, $taxonomy ) {
|
782 |
-
|
783 |
-
$term = get_term( $term_id, $taxonomy );
|
784 |
-
|
785 |
-
$tt_id = 0;
|
786 |
-
if ( isset( $term->term_taxonomy_id ) ) {
|
787 |
-
$tt_id = (int) $term->term_taxonomy_id;
|
788 |
-
}
|
789 |
-
|
790 |
-
$taxonomy = get_taxonomy( $taxonomy );
|
791 |
-
|
792 |
-
$name = esc_html__( 'term', 'taxonomy-images' );
|
793 |
-
if ( isset( $taxonomy->labels->singular_name ) ) {
|
794 |
-
$name = strtolower( $taxonomy->labels->singular_name );
|
795 |
-
}
|
796 |
-
|
797 |
-
$hide = ' hide';
|
798 |
-
$attachment_id = 0;
|
799 |
-
$associations = taxonomy_image_plugin_get_associations();
|
800 |
-
if ( isset( $associations[ $tt_id ] ) ) {
|
801 |
-
$attachment_id = (int) $associations[ $tt_id ];
|
802 |
-
$hide = '';
|
803 |
-
}
|
804 |
-
|
805 |
-
$img = taxonomy_image_plugin_get_image_src( $attachment_id );
|
806 |
-
|
807 |
-
$term = get_term( $term_id, $taxonomy->name );
|
808 |
-
|
809 |
-
$nonce = wp_create_nonce( 'taxonomy-image-plugin-create-association' );
|
810 |
-
$nonce_remove = wp_create_nonce( 'taxonomy-image-plugin-remove-association' );
|
811 |
-
|
812 |
-
$thickbox_class = version_compare( get_bloginfo( 'version' ), 3.5 ) >= 0 ? '' : 'thickbox';
|
813 |
-
|
814 |
-
$o = "\n" . '<div id="' . esc_attr( 'taxonomy-image-control-' . $tt_id ) . '" class="taxonomy-image-control hide-if-no-js">';
|
815 |
-
$o .= "\n" . '<a class="' . $thickbox_class . ' taxonomy-image-thumbnail" data-tt-id="' . $tt_id . '" data-attachment-id="' . $attachment_id . '" data-nonce="' . $nonce . '" 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>';
|
816 |
-
$o .= "\n" . '<a class="control upload ' . $thickbox_class . '" data-tt-id="' . $tt_id . '" data-attachment-id="' . $attachment_id . '" data-nonce="' . $nonce . '" 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>';
|
817 |
-
$o .= "\n" . '<a class="control remove' . $hide . '" data-tt-id="' . $tt_id . '" data-nonce="' . $nonce_remove . '" 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>';
|
818 |
-
$o .= "\n" . '<input type="hidden" class="tt_id" name="' . esc_attr( 'tt_id-' . $tt_id ) . '" value="' . esc_attr( $tt_id ) . '" />';
|
819 |
-
$o .= "\n" . '<input type="hidden" class="image_id" name="' . esc_attr( 'image_id-' . $tt_id ) . '" value="' . esc_attr( $attachment_id ) . '" />';
|
820 |
-
|
821 |
-
if ( isset( $term->name ) && isset( $term->slug ) ) {
|
822 |
-
$o .= "\n" . '<input type="hidden" class="term_name" name="' . esc_attr( 'term_name-' . $term->slug ) . '" value="' . esc_attr( $term->name ) . '" />';
|
823 |
-
}
|
824 |
-
|
825 |
-
$o .= "\n" . '</div>';
|
826 |
-
return $o;
|
827 |
-
}
|
828 |
-
|
829 |
-
|
830 |
-
/**
|
831 |
-
* Custom javascript for modal media box.
|
832 |
-
*
|
833 |
-
* This script need to be added to all instance of the media upload box.
|
834 |
-
*
|
835 |
-
* @access private
|
836 |
-
*/
|
837 |
-
function taxonomy_image_plugin_media_upload_popup_js() {
|
838 |
-
|
839 |
-
if ( version_compare( get_bloginfo( 'version' ), 3.5 ) >= 0 ) {
|
840 |
-
return;
|
841 |
-
}
|
842 |
-
|
843 |
-
wp_enqueue_script(
|
844 |
-
'taxonomy-images-media-upload-popup',
|
845 |
-
taxonomy_image_plugin_url( 'js/media-upload-popup.js' ),
|
846 |
-
array( 'jquery' ),
|
847 |
-
taxonomy_image_plugin_version()
|
848 |
-
);
|
849 |
-
wp_localize_script( 'taxonomy-images-media-upload-popup', 'TaxonomyImagesModal', array(
|
850 |
-
'termBefore' => esc_html__( '“', 'taxonomy-images' ),
|
851 |
-
'termAfter' => esc_html__( '”', 'taxonomy-images' ),
|
852 |
-
'associating' => esc_html__( 'Associating …', 'taxonomy-images' ),
|
853 |
-
'success' => esc_html__( 'Successfully Associated', 'taxonomy-images' ),
|
854 |
-
'removing' => esc_html__( 'Removing …', 'taxonomy-images' ),
|
855 |
-
'removed' => esc_html__( 'Successfully Removed', 'taxonomy-images' )
|
856 |
-
) );
|
857 |
-
}
|
858 |
-
add_action( 'admin_print_scripts-media-upload-popup', 'taxonomy_image_plugin_media_upload_popup_js' );
|
859 |
-
|
860 |
-
|
861 |
-
/**
|
862 |
-
* Custom javascript for wp-admin/edit-tags.php.
|
863 |
-
*
|
864 |
-
* @access private
|
865 |
-
*/
|
866 |
-
function taxonomy_image_plugin_edit_tags_js() {
|
867 |
-
if ( false == taxonomy_image_plugin_is_screen_active() ) {
|
868 |
-
return;
|
869 |
-
}
|
870 |
-
|
871 |
-
if ( version_compare( get_bloginfo( 'version' ), 3.5 ) >= 0 ) {
|
872 |
-
return;
|
873 |
-
}
|
874 |
-
|
875 |
-
wp_enqueue_script(
|
876 |
-
'taxonomy-image-plugin-edit-tags',
|
877 |
-
taxonomy_image_plugin_url( 'js/edit-tags.js' ),
|
878 |
-
array( 'jquery', 'thickbox' ),
|
879 |
-
taxonomy_image_plugin_version()
|
880 |
-
);
|
881 |
-
wp_localize_script( 'taxonomy-image-plugin-edit-tags', 'taxonomyImagesPlugin', array(
|
882 |
-
'nonce' => wp_create_nonce( 'taxonomy-image-plugin-remove-association' ),
|
883 |
-
'img_src' => taxonomy_image_plugin_url( 'default.png' ),
|
884 |
-
'tt_id' => 0,
|
885 |
-
'image_id' => 0,
|
886 |
-
) );
|
887 |
-
}
|
888 |
-
add_action( 'admin_print_scripts-edit-tags.php', 'taxonomy_image_plugin_edit_tags_js' );
|
889 |
-
|
890 |
-
|
891 |
-
/**
|
892 |
-
* Custom styles.
|
893 |
-
*
|
894 |
-
* @since 0.7
|
895 |
-
* @access private
|
896 |
-
*/
|
897 |
-
function taxonomy_image_plugin_css_admin() {
|
898 |
-
if ( false == taxonomy_image_plugin_is_screen_active() && current_filter() != 'admin_print_styles-media-upload-popup' ) {
|
899 |
-
return;
|
900 |
-
}
|
901 |
-
|
902 |
-
wp_enqueue_style(
|
903 |
-
'taxonomy-image-plugin-edit-tags',
|
904 |
-
taxonomy_image_plugin_url( 'css/admin.css' ),
|
905 |
-
array(),
|
906 |
-
taxonomy_image_plugin_version(),
|
907 |
-
'screen'
|
908 |
-
);
|
909 |
-
}
|
910 |
-
add_action( 'admin_print_styles-edit-tags.php', 'taxonomy_image_plugin_css_admin' ); // Pre WordPress 4.5
|
911 |
-
add_action( 'admin_print_styles-term.php', 'taxonomy_image_plugin_css_admin' ); // WordPress 4.5+
|
912 |
-
add_action( 'admin_print_styles-media-upload-popup', 'taxonomy_image_plugin_css_admin' );
|
913 |
-
|
914 |
-
|
915 |
-
/**
|
916 |
-
* Thickbox styles.
|
917 |
-
*
|
918 |
-
* @since 0.7
|
919 |
-
* @access private
|
920 |
-
*/
|
921 |
-
function taxonomy_image_plugin_css_thickbox() {
|
922 |
-
if ( false == taxonomy_image_plugin_is_screen_active() ) {
|
923 |
-
return;
|
924 |
-
}
|
925 |
-
|
926 |
-
wp_enqueue_style( 'thickbox' );
|
927 |
-
}
|
928 |
-
add_action( 'admin_print_styles-edit-tags.php', 'taxonomy_image_plugin_css_thickbox' );
|
929 |
-
|
930 |
-
|
931 |
-
/**
|
932 |
-
* Public Styles.
|
933 |
-
*
|
934 |
-
* Prints custom css to all public pages. If you do not
|
935 |
-
* wish to have these styles included for you, please
|
936 |
-
* insert the following code into your theme's functions.php
|
937 |
-
* file:
|
938 |
-
*
|
939 |
-
* add_filter( 'taxonomy-images-disable-public-css', '__return_true' );
|
940 |
-
*
|
941 |
-
* @since 0.7
|
942 |
-
* @access private
|
943 |
-
*/
|
944 |
-
function taxonomy_image_plugin_css_public() {
|
945 |
-
if ( apply_filters( 'taxonomy-images-disable-public-css', false ) ) {
|
946 |
-
return;
|
947 |
-
}
|
948 |
-
|
949 |
-
wp_enqueue_style(
|
950 |
-
'taxonomy-image-plugin-public',
|
951 |
-
taxonomy_image_plugin_url( 'css/style.css' ),
|
952 |
-
array(),
|
953 |
-
taxonomy_image_plugin_version(),
|
954 |
-
'screen'
|
955 |
-
);
|
956 |
-
}
|
957 |
-
add_action( 'wp_enqueue_scripts', 'taxonomy_image_plugin_css_public' );
|
958 |
-
|
959 |
-
|
960 |
-
/**
|
961 |
-
* Activation.
|
962 |
-
*
|
963 |
-
* Two entries in the options table will created when this
|
964 |
-
* plugin is activated in the event that they do not exist.
|
965 |
-
*
|
966 |
-
* 'taxonomy_image_plugin' (array) A flat list of all assocaitions
|
967 |
-
* made by this plugin. Keys are integers representing the
|
968 |
-
* term_taxonomy_id of terms. Values are integers representing the
|
969 |
-
* ID property of an image attachment.
|
970 |
-
*
|
971 |
-
* 'taxonomy_image_plugin_settings' (array) A multi-dimensional array
|
972 |
-
* of user-defined settings. As of version 0.7, only one key is used:
|
973 |
-
* 'taxonomies' which is a whitelist of registered taxonomies having ui
|
974 |
-
* that support the custom image ui provided by this plugin.
|
975 |
-
*
|
976 |
-
* @access private
|
977 |
-
* @alter 0.7
|
978 |
-
*/
|
979 |
-
function taxonomy_image_plugin_activate() {
|
980 |
-
$associations = get_option( 'taxonomy_image_plugin' );
|
981 |
-
if ( false === $associations ) {
|
982 |
-
add_option( 'taxonomy_image_plugin', array() );
|
983 |
-
}
|
984 |
-
|
985 |
-
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
986 |
-
if ( false === $settings ) {
|
987 |
-
add_option( 'taxonomy_image_plugin_settings', array(
|
988 |
-
'taxonomies' => array()
|
989 |
-
) );
|
990 |
-
}
|
991 |
-
}
|
992 |
-
register_activation_hook( __FILE__, 'taxonomy_image_plugin_activate' );
|
993 |
-
|
994 |
-
|
995 |
-
/**
|
996 |
-
* Is Screen Active?
|
997 |
-
*
|
998 |
-
* @return bool
|
999 |
-
*
|
1000 |
-
* @access private
|
1001 |
-
* @since 0.7
|
1002 |
-
*/
|
1003 |
-
function taxonomy_image_plugin_is_screen_active() {
|
1004 |
-
$screen = get_current_screen();
|
1005 |
-
if ( ! isset( $screen->taxonomy ) ) {
|
1006 |
-
return false;
|
1007 |
-
}
|
1008 |
-
|
1009 |
-
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
1010 |
-
if ( ! isset( $settings['taxonomies'] ) ) {
|
1011 |
-
return false;
|
1012 |
-
}
|
1013 |
-
|
1014 |
-
if ( in_array( $screen->taxonomy, $settings['taxonomies'] ) ) {
|
1015 |
-
return true;
|
1016 |
-
}
|
1017 |
-
|
1018 |
-
return false;
|
1019 |
-
}
|
1020 |
-
|
1021 |
-
|
1022 |
-
/**
|
1023 |
-
* Cache Images
|
1024 |
-
*
|
1025 |
-
* Sets the WordPress object cache for all term images
|
1026 |
-
* associated to the posts in the provided array. This
|
1027 |
-
* function has been created to minimize queries when
|
1028 |
-
* using this plugins get_the_terms() style function.
|
1029 |
-
*
|
1030 |
-
* @param array Post objects.
|
1031 |
-
*
|
1032 |
-
* @access private
|
1033 |
-
* @since 1.1
|
1034 |
-
*/
|
1035 |
-
function taxonomy_image_plugin_cache_images( $posts ) {
|
1036 |
-
$assoc = taxonomy_image_plugin_get_associations();
|
1037 |
-
if ( empty( $assoc ) ) {
|
1038 |
-
return;
|
1039 |
-
}
|
1040 |
-
|
1041 |
-
$tt_ids = array();
|
1042 |
-
foreach ( (array) $posts as $post ) {
|
1043 |
-
if ( ! isset( $post->ID ) || ! isset( $post->post_type ) ) {
|
1044 |
-
continue;
|
1045 |
-
}
|
1046 |
-
|
1047 |
-
$taxonomies = get_object_taxonomies( $post->post_type );
|
1048 |
-
if ( empty( $taxonomies ) ) {
|
1049 |
-
continue;
|
1050 |
-
}
|
1051 |
-
|
1052 |
-
foreach ( $taxonomies as $taxonomy ) {
|
1053 |
-
$the_terms = get_the_terms( $post->ID, $taxonomy );
|
1054 |
-
foreach ( (array) $the_terms as $term ) {
|
1055 |
-
if ( ! isset( $term->term_taxonomy_id ) ) {
|
1056 |
-
continue;
|
1057 |
-
}
|
1058 |
-
$tt_ids[] = $term->term_taxonomy_id;
|
1059 |
-
}
|
1060 |
-
}
|
1061 |
-
}
|
1062 |
-
$tt_ids = array_filter( array_unique( $tt_ids ) );
|
1063 |
-
|
1064 |
-
$image_ids = array();
|
1065 |
-
foreach ( $tt_ids as $tt_id ) {
|
1066 |
-
if ( ! isset( $assoc[ $tt_id ] ) ) {
|
1067 |
-
continue;
|
1068 |
-
}
|
1069 |
-
|
1070 |
-
if ( in_array( $assoc[ $tt_id ], $image_ids ) ) {
|
1071 |
-
continue;
|
1072 |
-
}
|
1073 |
-
|
1074 |
-
$image_ids[] = $assoc[ $tt_id ];
|
1075 |
-
}
|
1076 |
-
|
1077 |
-
if ( empty( $image_ids ) ) {
|
1078 |
-
return;
|
1079 |
-
}
|
1080 |
-
|
1081 |
-
$images = get_posts( array(
|
1082 |
-
'include' => $image_ids,
|
1083 |
-
'post_type' => 'attachment'
|
1084 |
-
) );
|
1085 |
-
}
|
1086 |
-
|
1087 |
-
|
1088 |
-
/**
|
1089 |
-
* Cache Images
|
1090 |
-
*
|
1091 |
-
* Cache all term images associated with posts in
|
1092 |
-
* the main WordPress query.
|
1093 |
-
*
|
1094 |
-
* @param array Post objects.
|
1095 |
-
*
|
1096 |
-
* @access private
|
1097 |
-
* @since 0.7
|
1098 |
-
*/
|
1099 |
-
function taxonomy_image_plugin_cache_queried_images() {
|
1100 |
-
global $posts;
|
1101 |
-
taxonomy_image_plugin_cache_images( $posts );
|
1102 |
-
}
|
1103 |
-
add_action( 'template_redirect', 'taxonomy_image_plugin_cache_queried_images' );
|
1104 |
-
|
1105 |
-
|
1106 |
-
/**
|
1107 |
-
* Check Taxonomy
|
1108 |
-
*
|
1109 |
-
* Wrapper for WordPress core functions taxonomy_exists().
|
1110 |
-
* In the event that an unregistered taxonomy is passed a
|
1111 |
-
* E_USER_NOTICE will be generated.
|
1112 |
-
*
|
1113 |
-
* @param string Taxonomy name as registered with WordPress.
|
1114 |
-
* @param string Name of the current function or filter.
|
1115 |
-
* @return bool True if taxonomy exists, False if not.
|
1116 |
-
*
|
1117 |
-
* @access private
|
1118 |
-
* @since 0.7
|
1119 |
-
*/
|
1120 |
-
function taxonomy_image_plugin_check_taxonomy( $taxonomy, $filter ) {
|
1121 |
-
if ( ! taxonomy_exists( $taxonomy ) ) {
|
1122 |
-
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' ),
|
1123 |
-
'<var>' . esc_html__( 'taxonomy', 'taxonomy-images' ) . '</var>',
|
1124 |
-
'<code>' . esc_html( $filter ) . '</code>',
|
1125 |
-
'<strong>' . esc_html( $taxonomy ) . '</strong>'
|
1126 |
-
) );
|
1127 |
-
return false;
|
1128 |
-
}
|
1129 |
-
|
1130 |
-
$settings = get_option( 'taxonomy_image_plugin_settings' );
|
1131 |
-
|
1132 |
-
if ( ! isset( $settings['taxonomies'] ) ) {
|
1133 |
-
trigger_error( sprintf( esc_html__( 'No taxonomies have image support. %1$s', 'taxonomy-images' ), taxonomy_images_plugin_settings_page_link() ) );
|
1134 |
-
return false;
|
1135 |
-
}
|
1136 |
-
|
1137 |
-
if ( ! in_array( $taxonomy, (array) $settings['taxonomies'] ) ) {
|
1138 |
-
trigger_error( sprintf( esc_html__( 'The %1$s taxonomy does not have image support. %2$s', 'taxonomy-images' ),
|
1139 |
-
'<strong>' . esc_html( $taxonomy ) . '</strong>',
|
1140 |
-
taxonomy_images_plugin_settings_page_link()
|
1141 |
-
) );
|
1142 |
-
return false;
|
1143 |
-
}
|
1144 |
-
|
1145 |
-
return true;
|
1146 |
-
}
|
1147 |
-
|
1148 |
-
|
1149 |
-
/**
|
1150 |
-
* Please Use Filter.
|
1151 |
-
*
|
1152 |
-
* Report to user that they are directly calling a function
|
1153 |
-
* instead of using supported filters. A E_USER_NOTICE will
|
1154 |
-
* be generated.
|
1155 |
-
*
|
1156 |
-
* @param string Name of function called.
|
1157 |
-
* @param string Name of filter to use instead.
|
1158 |
-
*
|
1159 |
-
* @access private
|
1160 |
-
* @since 0.7
|
1161 |
-
*/
|
1162 |
-
function taxonomy_image_plugin_please_use_filter( $function, $filter ) {
|
1163 |
-
trigger_error( sprintf( esc_html__( 'The %1$s has been called directly. Please use the %2$s filter instead.', 'taxonomy-images' ),
|
1164 |
-
'<code>' . esc_html( $function . '()' ) . '</code>',
|
1165 |
-
'<code>' . esc_html( $filter ) . '</code>'
|
1166 |
-
) );
|
1167 |
-
}
|
1168 |
-
|
1169 |
-
|
1170 |
-
/**
|
1171 |
-
* Plugin Meta Links.
|
1172 |
-
*
|
1173 |
-
* Add a link to this plugin's setting page when it
|
1174 |
-
* displays in the table on wp-admin/plugins.php.
|
1175 |
-
*
|
1176 |
-
* @param array List of links.
|
1177 |
-
* @param string Current plugin being displayed in plugins.php.
|
1178 |
-
* @return array Potentially modified list of links.
|
1179 |
-
*
|
1180 |
-
* @access private
|
1181 |
-
* @since 0.7
|
1182 |
-
*/
|
1183 |
-
function taxonomy_images_plugin_row_meta( $links, $file ) {
|
1184 |
-
static $plugin_name = '';
|
1185 |
-
|
1186 |
-
if ( empty( $plugin_name ) ) {
|
1187 |
-
$plugin_name = plugin_basename( __FILE__ );
|
1188 |
-
}
|
1189 |
-
|
1190 |
-
if ( $plugin_name != $file ) {
|
1191 |
-
return $links;
|
1192 |
-
}
|
1193 |
-
|
1194 |
-
$link = taxonomy_images_plugin_settings_page_link( esc_html__( 'Settings', 'taxonomy-images' ) );
|
1195 |
-
if ( ! empty( $link ) ) {
|
1196 |
-
$links[] = $link;
|
1197 |
-
}
|
1198 |
-
|
1199 |
-
$links[] = '<a href="http://wordpress.mfields.org/donate/">' . esc_html__( 'Donate', 'taxonomy-images' ) . '</a>';
|
1200 |
-
|
1201 |
-
return $links;
|
1202 |
-
}
|
1203 |
-
add_filter( 'plugin_row_meta', 'taxonomy_images_plugin_row_meta', 10, 2 );
|
1204 |
-
|
1205 |
-
|
1206 |
-
/**
|
1207 |
-
* Settings Page Link.
|
1208 |
-
*
|
1209 |
-
* @param array Localized link text.
|
1210 |
-
* @return string HTML link to settings page.
|
1211 |
-
*
|
1212 |
-
* @access private
|
1213 |
-
* @since 0.7
|
1214 |
-
*/
|
1215 |
-
function taxonomy_images_plugin_settings_page_link( $link_text = '' ) {
|
1216 |
-
if ( empty( $link_text ) ) {
|
1217 |
-
$link_text = __( 'Manage Settings', 'taxonomy-images' );
|
1218 |
-
}
|
1219 |
-
|
1220 |
-
$link = '';
|
1221 |
-
if ( current_user_can( 'manage_options' ) ) {
|
1222 |
-
$link = '<a href="' . esc_url( add_query_arg( array( 'page' => 'taxonomy_image_plugin_settings' ), admin_url( 'options-general.php' ) ) ) . '">' . esc_html( $link_text ) . '</a>';
|
1223 |
-
}
|
1224 |
-
|
1225 |
-
return $link;
|
1226 |
-
}
|
1227 |
-
|
1228 |
-
/**
|
1229 |
-
* Enqueue Admin Scripts
|
1230 |
-
*
|
1231 |
-
* @since 0.9
|
1232 |
-
*/
|
1233 |
-
function taxonomy_images_admin_enqueue_scripts() {
|
1234 |
-
|
1235 |
-
if ( false == taxonomy_image_plugin_is_screen_active() ) {
|
1236 |
-
return;
|
1237 |
-
}
|
1238 |
-
|
1239 |
-
if ( version_compare( get_bloginfo( 'version' ), 3.5 ) < 0 ) {
|
1240 |
-
return;
|
1241 |
-
}
|
1242 |
|
1243 |
-
|
|
|
1244 |
|
1245 |
-
|
1246 |
-
'taxonomy-images-media-modal',
|
1247 |
-
taxonomy_image_plugin_url( 'js/media-modal.js' ),
|
1248 |
-
array( 'jquery' ),
|
1249 |
-
taxonomy_image_plugin_version()
|
1250 |
-
);
|
1251 |
|
1252 |
-
|
1253 |
-
|
1254 |
-
'attachment_id' => 0,
|
1255 |
-
'uploader_title' => __( 'Set featured image', 'taxonomy-images' ),
|
1256 |
-
'uploader_button_text' => __( 'Set featured image', 'taxonomy-images' ),
|
1257 |
-
'default_img_src' => taxonomy_image_plugin_url( 'default.png' )
|
1258 |
-
) );
|
1259 |
|
1260 |
}
|
1261 |
-
add_action( 'admin_enqueue_scripts', 'taxonomy_images_admin_enqueue_scripts' );
|
4 |
Plugin Name: Taxonomy Images
|
5 |
Plugin URI: https://github.com/benhuson/Taxonomy-Images
|
6 |
Description: Associate images from your media library to categories, tags and custom taxonomies.
|
7 |
+
Version: 1.0
|
8 |
Author: Michael Fields, Ben Huson
|
9 |
Author URI: https://github.com/benhuson
|
10 |
License: GNU General Public License v2 or later
|
26 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
27 |
*/
|
28 |
|
29 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
30 |
|
31 |
+
if ( ! defined( 'TAXONOMY_IMAGES_FILE' ) ) {
|
32 |
+
define( 'TAXONOMY_IMAGES_FILE', __FILE__ );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
+
// Load term meta plugin version which requires PHP 5.3 and taxonomy meta support
|
40 |
+
require_once( trailingslashit( dirname( TAXONOMY_IMAGES_FILE ) ) . 'plugin/plugin.php' );
|
41 |
|
42 |
+
} else {
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
+
// Load legacy plugin version
|
45 |
+
require_once( trailingslashit( dirname( TAXONOMY_IMAGES_FILE ) ) . 'legacy/plugin.php' );
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
}
|
|