Version Description
- Disable options autoload to enhance wordpress queries performace
Download this release
Release Info
Developer | elzahlan |
Plugin | Categories Images |
Version | 3.0.1 |
Comparing to | |
See all releases |
Code changes from version 2.5.4 to 3.0.1
- assets/css/zci-styles.css +6 -0
- assets/images/placeholder.png +0 -0
- assets/index.php +2 -0
- assets/js/zci-scripts.js +71 -0
- categories-images.php +281 -313
- index.php +2 -0
- readme.txt +14 -5
- screenshot-1.jpg +0 -0
- screenshot-1.png +0 -0
- screenshot-2.jpg +0 -0
- screenshot-2.png +0 -0
- screenshot-3.jpg +0 -0
- screenshot-3.png +0 -0
- screenshot-4.jpg +0 -0
- screenshot-4.png +0 -0
- screenshot-5.jpg +0 -0
- screenshot-5.png +0 -0
- templates/admin.php +8 -0
assets/css/zci-styles.css
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Thumbnail style */
|
2 |
+
th.column-thumb {width:60px;}
|
3 |
+
.form-field img.zci-taxonomy-image {border:1px solid #eee;max-width:300px;max-height:300px;}
|
4 |
+
.inline-edit-row fieldset .thumb label span.title {width:48px;height:48px;border:1px solid #eee;display:inline-block;}
|
5 |
+
.column-thumb span {width:48px;height:48px;border:1px solid #eee;display:inline-block;}
|
6 |
+
.inline-edit-row fieldset .thumb img,.column-thumb img {width:48px;height:48px;}
|
assets/images/placeholder.png
ADDED
Binary file
|
assets/index.php
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Silence is golden.
|
assets/js/zci-scripts.js
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
jQuery(document).ready(function($) {
|
2 |
+
var upload_button;
|
3 |
+
|
4 |
+
$(".z_upload_image_button").on('click', function(event) {
|
5 |
+
upload_button = $(this);
|
6 |
+
var frame;
|
7 |
+
if (zci_config.wordpress_ver >= "3.5") {
|
8 |
+
event.preventDefault();
|
9 |
+
if (frame) {
|
10 |
+
frame.open();
|
11 |
+
return;
|
12 |
+
}
|
13 |
+
frame = wp.media();
|
14 |
+
frame.on( "select", function() {
|
15 |
+
// Grab the selected attachment.
|
16 |
+
var attachment = frame.state().get("selection").first();
|
17 |
+
var attachmentUrl = attachment.attributes.url;
|
18 |
+
attachmentUrl = attachmentUrl.replace('-scaled.', '.');
|
19 |
+
|
20 |
+
frame.close();
|
21 |
+
$(".zci-taxonomy-image").attr("src", attachmentUrl);
|
22 |
+
if (upload_button.parent().prev().children().hasClass("tax_list")) {
|
23 |
+
upload_button.parent().prev().children().val(attachmentUrl);
|
24 |
+
upload_button.parent().prev().prev().children().attr("src", attachmentUrl);
|
25 |
+
}
|
26 |
+
else
|
27 |
+
$("#zci_taxonomy_image").val(attachmentUrl);
|
28 |
+
});
|
29 |
+
frame.open();
|
30 |
+
}
|
31 |
+
else {
|
32 |
+
tb_show("", "media-upload.php?type=image&TB_iframe=true");
|
33 |
+
return false;
|
34 |
+
}
|
35 |
+
});
|
36 |
+
|
37 |
+
$(".z_remove_image_button").on('click', function() {
|
38 |
+
$(".zci-taxonomy-image").attr("src", zci_config.placeholder);
|
39 |
+
$("#zci_taxonomy_image").val("");
|
40 |
+
$(this).parent().siblings(".title").children("img").attr("src", zci_config.placeholder);
|
41 |
+
$(".inline-edit-col :input[name='zci_taxonomy_image']").val("");
|
42 |
+
return false;
|
43 |
+
});
|
44 |
+
|
45 |
+
if (zci_config.wordpress_ver < "3.5") {
|
46 |
+
window.send_to_editor = function(html) {
|
47 |
+
imgurl = $("img",html).attr("src");
|
48 |
+
if (upload_button.parent().prev().children().hasClass("tax_list")) {
|
49 |
+
upload_button.parent().prev().children().val(imgurl);
|
50 |
+
upload_button.parent().prev().prev().children().attr("src", imgurl);
|
51 |
+
}
|
52 |
+
else
|
53 |
+
$("#zci_taxonomy_image").val(imgurl);
|
54 |
+
tb_remove();
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
+
$(".editinline").on('click', function() {
|
59 |
+
var tax_id = $(this).parents("tr").attr("id").substr(4);
|
60 |
+
var thumb = $("#tag-"+tax_id+" .thumb img").attr("src");
|
61 |
+
|
62 |
+
// To Do: fix image input url in quick mode
|
63 |
+
/*if (thumb != zci_config.placeholder) {
|
64 |
+
$(".inline-edit-col :input[name='zci_taxonomy_image']").val(thumb);
|
65 |
+
} else {
|
66 |
+
$(".inline-edit-col :input[name='zci_taxonomy_image']").val("");
|
67 |
+
}*/
|
68 |
+
|
69 |
+
$(".inline-edit-col .title img").attr("src",thumb);
|
70 |
+
});
|
71 |
+
});
|
categories-images.php
CHANGED
@@ -1,363 +1,331 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Plugin Name: Categories Images
|
4 |
-
* Plugin URI: http://zahlan.net/blog/
|
5 |
* Description: Categories Images Plugin allow you to add an image to category or any custom term.
|
6 |
-
* Author: Muhammad
|
7 |
-
* Version:
|
8 |
* Author URI: http://zahlan.net/
|
9 |
* Domain Path: /languages
|
10 |
* Text Domain: categories-images
|
|
|
11 |
*/
|
12 |
|
|
|
|
|
|
|
13 |
if (!defined('Z_PLUGIN_URL'))
|
14 |
define('Z_PLUGIN_URL', untrailingslashit(plugins_url('', __FILE__)));
|
15 |
|
16 |
-
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
if (is_array($z_taxonomies)) {
|
25 |
-
$zci_options = get_option('zci_options');
|
26 |
-
|
27 |
-
if (!is_array($zci_options))
|
28 |
-
$zci_options = array();
|
29 |
-
|
30 |
-
if (empty($zci_options['excluded_taxonomies']))
|
31 |
-
$zci_options['excluded_taxonomies'] = array();
|
32 |
-
|
33 |
-
foreach ($z_taxonomies as $z_taxonomy) {
|
34 |
-
if (in_array($z_taxonomy, $zci_options['excluded_taxonomies']))
|
35 |
-
continue;
|
36 |
-
add_action($z_taxonomy.'_add_form_fields', 'z_add_texonomy_field');
|
37 |
-
add_action($z_taxonomy.'_edit_form_fields', 'z_edit_texonomy_field');
|
38 |
-
add_filter( 'manage_edit-' . $z_taxonomy . '_columns', 'z_taxonomy_columns' );
|
39 |
-
add_filter( 'manage_' . $z_taxonomy . '_custom_column', 'z_taxonomy_column', 10, 3 );
|
40 |
-
}
|
41 |
-
}
|
42 |
-
}
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
.form-field img.taxonomy-image {border:1px solid #eee;max-width:300px;max-height:300px;}
|
48 |
-
.inline-edit-row fieldset .thumb label span.title {width:48px;height:48px;border:1px solid #eee;display:inline-block;}
|
49 |
-
.column-thumb span {width:48px;height:48px;border:1px solid #eee;display:inline-block;}
|
50 |
-
.inline-edit-row fieldset .thumb img,.column-thumb img {width:48px;height:48px;}
|
51 |
-
</style>';
|
52 |
-
}
|
53 |
|
54 |
-
//
|
55 |
-
|
56 |
-
if (get_bloginfo('version') >= 3.5)
|
57 |
-
wp_enqueue_media();
|
58 |
-
else {
|
59 |
-
wp_enqueue_style('thickbox');
|
60 |
-
wp_enqueue_script('thickbox');
|
61 |
-
}
|
62 |
-
|
63 |
-
echo '<div class="form-field">
|
64 |
-
<label for="taxonomy_image">' . __('Image', 'categories-images') . '</label>
|
65 |
-
<input type="text" name="taxonomy_image" id="taxonomy_image" value="" />
|
66 |
-
<br/>
|
67 |
-
<button class="z_upload_image_button button">' . __('Upload/Add image', 'categories-images') . '</button>
|
68 |
-
</div>'.z_script();
|
69 |
-
}
|
70 |
|
71 |
-
//
|
72 |
-
|
73 |
-
if (get_bloginfo('version') >= 3.5)
|
74 |
-
wp_enqueue_media();
|
75 |
-
else {
|
76 |
-
wp_enqueue_style('thickbox');
|
77 |
-
wp_enqueue_script('thickbox');
|
78 |
}
|
79 |
-
|
80 |
-
if (z_taxonomy_image_url( $taxonomy->term_id, NULL, TRUE ) == Z_IMAGE_PLACEHOLDER)
|
81 |
-
$image_url = "";
|
82 |
-
else
|
83 |
-
$image_url = z_taxonomy_image_url( $taxonomy->term_id, NULL, TRUE );
|
84 |
-
echo '<tr class="form-field">
|
85 |
-
<th scope="row" valign="top"><label for="taxonomy_image">' . __('Image', 'categories-images') . '</label></th>
|
86 |
-
<td><img class="taxonomy-image" src="' . z_taxonomy_image_url( $taxonomy->term_id, 'medium', TRUE ) . '"/><br/><input type="text" name="taxonomy_image" id="taxonomy_image" value="'.$image_url.'" /><br />
|
87 |
-
<button class="z_upload_image_button button">' . __('Upload/Add image', 'categories-images') . '</button>
|
88 |
-
<button class="z_remove_image_button button">' . __('Remove image', 'categories-images') . '</button>
|
89 |
-
</td>
|
90 |
-
</tr>'.z_script();
|
91 |
-
}
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
var wordpress_ver = "'.get_bloginfo("version").'", upload_button;
|
98 |
-
$(".z_upload_image_button").click(function(event) {
|
99 |
-
upload_button = $(this);
|
100 |
-
var frame;
|
101 |
-
if (wordpress_ver >= "3.5") {
|
102 |
-
event.preventDefault();
|
103 |
-
if (frame) {
|
104 |
-
frame.open();
|
105 |
-
return;
|
106 |
-
}
|
107 |
-
frame = wp.media();
|
108 |
-
frame.on( "select", function() {
|
109 |
-
// Grab the selected attachment.
|
110 |
-
var attachment = frame.state().get("selection").first();
|
111 |
-
frame.close();
|
112 |
-
if (upload_button.parent().prev().children().hasClass("tax_list")) {
|
113 |
-
upload_button.parent().prev().children().val(attachment.attributes.url);
|
114 |
-
upload_button.parent().prev().prev().children().attr("src", attachment.attributes.url);
|
115 |
-
}
|
116 |
-
else
|
117 |
-
$("#taxonomy_image").val(attachment.attributes.url);
|
118 |
-
});
|
119 |
-
frame.open();
|
120 |
-
}
|
121 |
-
else {
|
122 |
-
tb_show("", "media-upload.php?type=image&TB_iframe=true");
|
123 |
-
return false;
|
124 |
-
}
|
125 |
-
});
|
126 |
|
127 |
-
|
128 |
-
$(
|
129 |
-
$("#taxonomy_image").val("");
|
130 |
-
$(this).parent().siblings(".title").children("img").attr("src","' . Z_IMAGE_PLACEHOLDER . '");
|
131 |
-
$(".inline-edit-col :input[name=\'taxonomy_image\']").val("");
|
132 |
-
return false;
|
133 |
-
});
|
134 |
|
135 |
-
if (
|
136 |
-
|
137 |
-
imgurl = $("img",html).attr("src");
|
138 |
-
if (upload_button.parent().prev().children().hasClass("tax_list")) {
|
139 |
-
upload_button.parent().prev().children().val(imgurl);
|
140 |
-
upload_button.parent().prev().prev().children().attr("src", imgurl);
|
141 |
-
}
|
142 |
-
else
|
143 |
-
$("#taxonomy_image").val(imgurl);
|
144 |
-
tb_remove();
|
145 |
-
}
|
146 |
-
}
|
147 |
|
148 |
-
$
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
$(".inline-edit-col :input[name=\'taxonomy_image\']").val("");
|
156 |
-
}
|
157 |
-
|
158 |
-
$(".inline-edit-col .title img").attr("src",thumb);
|
159 |
-
});
|
160 |
-
});
|
161 |
-
</script>';
|
162 |
-
}
|
163 |
|
164 |
-
//
|
165 |
-
add_action(
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
}
|
171 |
|
172 |
-
//
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
|
|
|
|
|
|
|
|
190 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
}
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
|
|
199 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
}
|
201 |
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
|
208 |
-
|
209 |
-
if ($column_name == 'thumb')
|
210 |
-
echo '<fieldset>
|
211 |
-
<div class="thumb inline-edit-col">
|
212 |
-
<label>
|
213 |
-
<span class="title"><img src="" alt="Thumbnail"/></span>
|
214 |
-
<span class="input-text-wrap"><input type="text" name="taxonomy_image" value="" class="tax_list" /></span>
|
215 |
-
<span class="input-text-wrap">
|
216 |
-
<button class="z_upload_image_button button">' . __('Upload/Add image', 'categories-images') . '</button>
|
217 |
-
<button class="z_remove_image_button button">' . __('Remove image', 'categories-images') . '</button>
|
218 |
-
</span>
|
219 |
-
</label>
|
220 |
-
</div>
|
221 |
-
</fieldset>';
|
222 |
-
}
|
223 |
|
224 |
-
|
225 |
-
|
226 |
-
*
|
227 |
-
* @access public
|
228 |
-
* @param mixed $columns
|
229 |
-
* @return void
|
230 |
-
*/
|
231 |
-
function z_taxonomy_columns( $columns ) {
|
232 |
-
$new_columns = array();
|
233 |
-
$new_columns['cb'] = $columns['cb'];
|
234 |
-
$new_columns['thumb'] = __('Image', 'categories-images');
|
235 |
|
236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
|
238 |
-
|
239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
* @param mixed $column
|
247 |
-
* @param mixed $id
|
248 |
-
* @return void
|
249 |
-
*/
|
250 |
-
function z_taxonomy_column( $columns, $column, $id ) {
|
251 |
-
if ( $column == 'thumb' )
|
252 |
-
$columns = '<span><img src="' . z_taxonomy_image_url($id, 'thumbnail', TRUE) . '" alt="' . __('Thumbnail', 'categories-images') . '" class="wp-post-image" /></span>';
|
253 |
-
|
254 |
-
return $columns;
|
255 |
-
}
|
256 |
|
257 |
-
//
|
258 |
-
function
|
259 |
-
|
260 |
-
|
|
|
|
|
|
|
261 |
|
262 |
-
//
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
268 |
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
}
|
275 |
|
276 |
-
//
|
277 |
-
function
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
|
|
287 |
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
$disabled_taxonomies = array('nav_menu', 'link_category', 'post_format');
|
292 |
-
foreach (get_taxonomies() as $tax) : if (in_array($tax, $disabled_taxonomies)) continue; ?>
|
293 |
-
<input type="checkbox" name="zci_options[excluded_taxonomies][<?php echo $tax ?>]" value="<?php echo $tax ?>" <?php checked(isset($options['excluded_taxonomies'][$tax])); ?> /> <?php echo $tax ;?><br />
|
294 |
-
<?php endforeach;
|
295 |
-
}
|
296 |
|
297 |
-
//
|
298 |
-
function
|
299 |
-
|
300 |
-
|
|
|
|
|
301 |
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
?>
|
308 |
-
<div class="wrap">
|
309 |
-
<?php screen_icon(); ?>
|
310 |
-
<h2><?php _e('Categories Images', 'categories-images'); ?></h2>
|
311 |
-
<form method="post" action="options.php">
|
312 |
-
<?php settings_fields('zci_options'); ?>
|
313 |
-
<?php do_settings_sections('zci-options'); ?>
|
314 |
-
<?php submit_button(); ?>
|
315 |
-
</form>
|
316 |
-
</div>
|
317 |
-
<?php
|
318 |
-
}
|
319 |
|
320 |
-
//
|
321 |
-
function
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
|
|
331 |
}
|
332 |
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
if(!empty($attr['class']))
|
342 |
-
$image_attr .= ' class="'.$attr['class'].'" ';
|
343 |
-
if(!empty($attr['alt']))
|
344 |
-
$image_attr .= ' alt="'.$attr['alt'].'" ';
|
345 |
-
if(!empty($attr['width']))
|
346 |
-
$image_attr .= ' width="'.$attr['width'].'" ';
|
347 |
-
if(!empty($attr['height']))
|
348 |
-
$image_attr .= ' height="'.$attr['height'].'" ';
|
349 |
-
if(!empty($attr['title']))
|
350 |
-
$image_attr .= ' title="'.$attr['title'].'" ';
|
351 |
-
}
|
352 |
-
$taxonomy_image = '<img src="'.$taxonomy_image_url.'" '.$image_attr.'/>';
|
353 |
-
}
|
354 |
}
|
355 |
-
|
356 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
}
|
358 |
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* @package CategoriesImages
|
4 |
+
*/
|
5 |
+
|
6 |
/**
|
7 |
* Plugin Name: Categories Images
|
8 |
+
* Plugin URI: http://zahlan.net/blog/categories-images/
|
9 |
* Description: Categories Images Plugin allow you to add an image to category or any custom term.
|
10 |
+
* Author: Muhammad El Zahlan
|
11 |
+
* Version: 3.0.1
|
12 |
* Author URI: http://zahlan.net/
|
13 |
* Domain Path: /languages
|
14 |
* Text Domain: categories-images
|
15 |
+
* License: GPLv2 or later
|
16 |
*/
|
17 |
|
18 |
+
if (!defined('ABSPATH'))
|
19 |
+
die;
|
20 |
+
|
21 |
if (!defined('Z_PLUGIN_URL'))
|
22 |
define('Z_PLUGIN_URL', untrailingslashit(plugins_url('', __FILE__)));
|
23 |
|
24 |
+
class ZCategoriesImages
|
25 |
+
{
|
26 |
+
public $plugin_name;
|
27 |
+
private $zci_placeholder;
|
28 |
|
29 |
+
function __construct() {
|
30 |
+
$this->plugin_name = plugin_basename(__FILE__);
|
31 |
|
32 |
+
// The placeholder image url
|
33 |
+
$this->zci_placeholder = plugins_url('/assets/images/placeholder.png', __FILE__);
|
34 |
+
add_action('admin_init', [$this, 'zAdminInit']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
// save our taxonomy image while edit or create term
|
37 |
+
add_action('edit_term', [$this, 'zSaveTaxonomyImage']);
|
38 |
+
add_action('create_term', [$this, 'zSaveTaxonomyImage']);
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
+
// Plugin menu in admin panel
|
41 |
+
add_action('admin_menu', [$this, 'zSettingsMenu']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
+
// Settings page link in plugins list
|
44 |
+
add_filter("plugin_action_links_{$this->plugin_name}", [$this, 'zSettingsLink']);
|
|
|
|
|
|
|
|
|
|
|
45 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
+
function zAdminInit() {
|
48 |
+
$z_taxonomies = get_taxonomies();
|
49 |
+
if (is_array($z_taxonomies)) {
|
50 |
+
$zci_options = get_option('zci_options');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
if (!is_array($zci_options))
|
53 |
+
$zci_options = array();
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
+
if (empty($zci_options['excluded_taxonomies']))
|
56 |
+
$zci_options['excluded_taxonomies'] = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
+
foreach ($z_taxonomies as $z_taxonomy) {
|
59 |
+
if (in_array($z_taxonomy, $zci_options['excluded_taxonomies']))
|
60 |
+
continue;
|
61 |
+
add_action($z_taxonomy.'_add_form_fields', [$this, 'zAddTexonomyField']);
|
62 |
+
add_action($z_taxonomy.'_edit_form_fields', [$this, 'zEditTexonomyField']);
|
63 |
+
add_filter('manage_edit-'.$z_taxonomy.'_columns', [$this, 'zTaxonomyColumns']);
|
64 |
+
add_filter('manage_'.$z_taxonomy.'_custom_column', [$this, 'zTaxonomyColumn'], 10, 3 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
+
// If tax is deleted
|
67 |
+
add_action("delete_{$z_taxonomy}", function($tt_id) {
|
68 |
+
delete_option('z_taxonomy_image'.$tt_id);
|
69 |
+
});
|
70 |
+
}
|
71 |
+
}
|
|
|
72 |
|
73 |
+
// Register styles and scripts
|
74 |
+
if ( strpos( $_SERVER['SCRIPT_NAME'], 'edit-tags.php' ) > 0 || strpos( $_SERVER['SCRIPT_NAME'], 'term.php' ) > 0 ) {
|
75 |
+
add_action('admin_enqueue_scripts', [$this, 'zAdminEnqueue']);
|
76 |
+
add_action('quick_edit_custom_box', [$this, 'zQuickEditCustomBox'], 10, 3);
|
77 |
+
}
|
78 |
+
|
79 |
+
// Register settings
|
80 |
+
register_setting('zci_options', 'zci_options');
|
81 |
+
add_settings_section('zci_settings', __('Categories Images settings', 'categories-images'), [$this, 'zSectionText'], 'zci-options');
|
82 |
+
add_settings_field('z_excluded_taxonomies', __('Excluded Taxonomies', 'categories-images'), [$this, 'zExcludedTaxonomies'], 'zci-options', 'zci_settings');
|
83 |
+
}
|
84 |
+
|
85 |
+
function zAdminEnqueue() {
|
86 |
+
wp_enqueue_style('categories-images-styles', plugins_url('/assets/css/zci-styles.css', __FILE__));
|
87 |
+
wp_enqueue_script('categories-images-scripts', plugins_url('/assets/js/zci-scripts.js', __FILE__));
|
88 |
|
89 |
+
$zci_js_config = [
|
90 |
+
'wordpress_ver' => get_bloginfo("version"),
|
91 |
+
'placeholder' => $this->zci_placeholder
|
92 |
+
];
|
93 |
+
wp_localize_script('categories-images-scripts', 'zci_config', $zci_js_config);
|
94 |
+
}
|
95 |
+
|
96 |
+
// add image field in add form
|
97 |
+
function zAddTexonomyField() {
|
98 |
+
if (get_bloginfo('version') >= 3.5)
|
99 |
+
wp_enqueue_media();
|
100 |
+
else {
|
101 |
+
wp_enqueue_style('thickbox');
|
102 |
+
wp_enqueue_script('thickbox');
|
103 |
}
|
104 |
+
|
105 |
+
echo '<div class="form-field">
|
106 |
+
<label for="zci_taxonomy_image">' . __('Image', 'categories-images') . '</label>
|
107 |
+
<input type="text" name="zci_taxonomy_image" id="zci_taxonomy_image" value="" />
|
108 |
+
<br/>
|
109 |
+
<button class="z_upload_image_button button">' . __('Upload/Add image', 'categories-images') . '</button>
|
110 |
+
</div>';
|
111 |
}
|
112 |
+
|
113 |
+
// add image field in edit form
|
114 |
+
function zEditTexonomyField($taxonomy) {
|
115 |
+
if (get_bloginfo('version') >= 3.5)
|
116 |
+
wp_enqueue_media();
|
117 |
+
else {
|
118 |
+
wp_enqueue_style('thickbox');
|
119 |
+
wp_enqueue_script('thickbox');
|
120 |
}
|
121 |
+
|
122 |
+
if ($this->zTaxonomyImageUrl( $taxonomy->term_id, NULL, TRUE ) == $this->zci_placeholder)
|
123 |
+
$image_url = "";
|
124 |
+
else
|
125 |
+
$image_url = $this->zTaxonomyImageUrl( $taxonomy->term_id, NULL, TRUE );
|
126 |
+
echo '<tr class="form-field">
|
127 |
+
<th scope="row" valign="top"><label for="zci_taxonomy_image">' . __('Image', 'categories-images') . '</label></th>
|
128 |
+
<td><img class="zci-taxonomy-image" src="' . $this->zTaxonomyImageUrl( $taxonomy->term_id, 'medium', TRUE ) . '"/><br/><input type="text" name="zci_taxonomy_image" id="zci_taxonomy_image" value="'.$image_url.'" /><br />
|
129 |
+
<button class="z_upload_image_button button">' . __('Upload/Add image', 'categories-images') . '</button>
|
130 |
+
<button class="z_remove_image_button button">' . __('Remove image', 'categories-images') . '</button>
|
131 |
+
</td>
|
132 |
+
</tr>';
|
133 |
}
|
134 |
|
135 |
+
/**
|
136 |
+
* Thumbnail column added to category admin.
|
137 |
+
*
|
138 |
+
* @access public
|
139 |
+
* @param mixed $columns
|
140 |
+
* @return void
|
141 |
+
*/
|
142 |
+
function zTaxonomyColumns( $columns ) {
|
143 |
+
$new_columns = array();
|
144 |
+
$new_columns['cb'] = $columns['cb'];
|
145 |
+
$new_columns['thumb'] = __('Image', 'categories-images');
|
146 |
|
147 |
+
unset( $columns['cb'] );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
+
return array_merge( $new_columns, $columns );
|
150 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
|
152 |
+
/**
|
153 |
+
* Thumbnail column value added to category admin.
|
154 |
+
*
|
155 |
+
* @access public
|
156 |
+
* @param mixed $columns
|
157 |
+
* @param mixed $column
|
158 |
+
* @param mixed $id
|
159 |
+
* @return void
|
160 |
+
*/
|
161 |
+
function zTaxonomyColumn( $columns, $column, $id ) {
|
162 |
+
if ( $column == 'thumb' )
|
163 |
+
$columns = '<span><img src="' . $this->zTaxonomyImageUrl($id, 'thumbnail', TRUE) . '" alt="' . __('Thumbnail', 'categories-images') . '" class="wp-post-image" /></span>';
|
164 |
+
|
165 |
+
return $columns;
|
166 |
+
}
|
167 |
|
168 |
+
function zQuickEditCustomBox($column_name, $screen, $name) {
|
169 |
+
if ($column_name == 'thumb')
|
170 |
+
echo '<fieldset>
|
171 |
+
<div class="thumb inline-edit-col">
|
172 |
+
<label>
|
173 |
+
<span class="title"><img src="" alt="Thumbnail"/></span>
|
174 |
+
<span class="input-text-wrap"><input type="text" name="zci_taxonomy_image" value="" class="tax_list" /></span>
|
175 |
+
<span class="input-text-wrap">
|
176 |
+
<button class="z_upload_image_button button">' . __('Upload/Add image', 'categories-images') . '</button>
|
177 |
+
<button class="z_remove_image_button button">' . __('Remove image', 'categories-images') . '</button>
|
178 |
+
</span>
|
179 |
+
</label>
|
180 |
+
</div>
|
181 |
+
</fieldset>';
|
182 |
+
}
|
183 |
|
184 |
+
function zSaveTaxonomyImage($term_id) {
|
185 |
+
if(isset($_POST['zci_taxonomy_image'])) {
|
186 |
+
update_option('z_taxonomy_image'.$term_id, $_POST['zci_taxonomy_image'], false);
|
187 |
+
}
|
188 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
|
190 |
+
// get attachment ID by image url
|
191 |
+
function zGetAttachmentIdByUrl($image_src) {
|
192 |
+
global $wpdb;
|
193 |
+
$query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid = %s", $image_src);
|
194 |
+
$id = $wpdb->get_var($query);
|
195 |
+
return (!empty($id)) ? $id : NULL;
|
196 |
+
}
|
197 |
|
198 |
+
// get taxonomy image url for the given term_id (Place holder image by default)
|
199 |
+
function zTaxonomyImageUrl($term_id = NULL, $size = 'full', $return_placeholder = FALSE) {
|
200 |
+
if (!$term_id) {
|
201 |
+
if (is_category())
|
202 |
+
$term_id = get_query_var('cat');
|
203 |
+
elseif (is_tag())
|
204 |
+
$term_id = get_query_var('tag_id');
|
205 |
+
elseif (is_tax()) {
|
206 |
+
$current_term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
|
207 |
+
$term_id = $current_term->term_id;
|
208 |
+
}
|
209 |
+
}
|
210 |
+
|
211 |
+
$taxonomy_image_url = get_option('z_taxonomy_image'.$term_id);
|
212 |
+
if(!empty($taxonomy_image_url)) {
|
213 |
+
$attachment_id = $this->zGetAttachmentIdByUrl($taxonomy_image_url);
|
214 |
+
if(!empty($attachment_id)) {
|
215 |
+
$taxonomy_image_url = wp_get_attachment_image_src($attachment_id, $size);
|
216 |
+
$taxonomy_image_url = $taxonomy_image_url[0];
|
217 |
+
}
|
218 |
+
}
|
219 |
|
220 |
+
if ($return_placeholder)
|
221 |
+
return ($taxonomy_image_url != '') ? $taxonomy_image_url : $this->zci_placeholder;
|
222 |
+
else
|
223 |
+
return $taxonomy_image_url;
|
224 |
+
}
|
|
|
225 |
|
226 |
+
// display taxonomy image for the given term_id
|
227 |
+
function zTaxonomyImage($term_id = NULL, $size = 'full', $attr = NULL, $echo = TRUE) {
|
228 |
+
if (!$term_id) {
|
229 |
+
if (is_category())
|
230 |
+
$term_id = get_query_var('cat');
|
231 |
+
elseif (is_tag())
|
232 |
+
$term_id = get_query_var('tag_id');
|
233 |
+
elseif (is_tax()) {
|
234 |
+
$current_term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy'));
|
235 |
+
$term_id = $current_term->term_id;
|
236 |
+
}
|
237 |
+
}
|
238 |
+
|
239 |
+
$taxonomy_image_url = get_option('z_taxonomy_image'.$term_id);
|
240 |
+
if(!empty($taxonomy_image_url)) {
|
241 |
+
$attachment_id = $this->zGetAttachmentIdByUrl($taxonomy_image_url);
|
242 |
+
if(!empty($attachment_id))
|
243 |
+
$taxonomy_image = wp_get_attachment_image($attachment_id, $size, FALSE, $attr);
|
244 |
+
else {
|
245 |
+
$image_attr = '';
|
246 |
+
if(is_array($attr)) {
|
247 |
+
if(!empty($attr['class']))
|
248 |
+
$image_attr .= ' class="'.$attr['class'].'" ';
|
249 |
+
if(!empty($attr['alt']))
|
250 |
+
$image_attr .= ' alt="'.$attr['alt'].'" ';
|
251 |
+
if(!empty($attr['width']))
|
252 |
+
$image_attr .= ' width="'.$attr['width'].'" ';
|
253 |
+
if(!empty($attr['height']))
|
254 |
+
$image_attr .= ' height="'.$attr['height'].'" ';
|
255 |
+
if(!empty($attr['title']))
|
256 |
+
$image_attr .= ' title="'.$attr['title'].'" ';
|
257 |
+
}
|
258 |
+
$taxonomy_image = '<img src="'.$taxonomy_image_url.'" '.$image_attr.'/>';
|
259 |
+
}
|
260 |
+
}
|
261 |
+
else{
|
262 |
+
$taxonomy_image = '';
|
263 |
+
}
|
264 |
|
265 |
+
if ($echo)
|
266 |
+
echo $taxonomy_image;
|
267 |
+
else
|
268 |
+
return $taxonomy_image;
|
269 |
+
}
|
270 |
|
271 |
+
function zSettingsMenu() {
|
272 |
+
add_menu_page(__('Categories Images settings', 'categories-images'), __('Categories Images', 'categories-images'), 'manage_options', 'zci_settings', [$this, 'zSettingsPage'], 'dashicons-format-image', 80);
|
273 |
+
}
|
|
|
|
|
|
|
|
|
|
|
274 |
|
275 |
+
// Plugin option page
|
276 |
+
function zSettingsPage() {
|
277 |
+
if (!current_user_can('manage_options'))
|
278 |
+
wp_die(__( 'You do not have sufficient permissions to access this page.', 'categories-images'));
|
279 |
+
require_once plugin_dir_path(__FILE__).'templates/admin.php';
|
280 |
+
}
|
281 |
|
282 |
+
function zSettingsLink($links) {
|
283 |
+
$settings_link = '<a href="admin.php?page=zci_settings">Settings</a>';
|
284 |
+
array_push($links, $settings_link);
|
285 |
+
return $links;
|
286 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
|
288 |
+
// Settings section description
|
289 |
+
function zSectionText() {
|
290 |
+
echo '<p>'.__('Please select the taxonomies you want to exclude it from Categories Images plugin', 'categories-images').'</p>';
|
291 |
+
}
|
292 |
+
|
293 |
+
// Excluded taxonomies checkboxs
|
294 |
+
function zExcludedTaxonomies() {
|
295 |
+
$options = get_option('zci_options');
|
296 |
+
$disabled_taxonomies = ['nav_menu', 'link_category', 'post_format'];
|
297 |
+
foreach (get_taxonomies() as $tax) : if (in_array($tax, $disabled_taxonomies)) continue; ?>
|
298 |
+
<input type="checkbox" name="zci_options[excluded_taxonomies][<?php echo $tax ?>]" value="<?php echo $tax ?>" <?php checked(isset($options['excluded_taxonomies'][$tax])); ?> /> <?php echo $tax ;?><br />
|
299 |
+
<?php endforeach;
|
300 |
}
|
301 |
|
302 |
+
function activate() {
|
303 |
+
// Things will happen if the plugin activated.
|
304 |
+
flush_rewrite_rules();
|
305 |
+
}
|
306 |
+
|
307 |
+
function deactivate() {
|
308 |
+
// Things will happen if the plugin deactivated.
|
309 |
+
flush_rewrite_rules();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
310 |
}
|
311 |
+
}
|
312 |
+
|
313 |
+
if (class_exists('ZCategoriesImages')) {
|
314 |
+
$z_categories_images = new ZCategoriesImages();
|
315 |
+
|
316 |
+
// After activating the plugin
|
317 |
+
register_activation_hook(__FILE__, [$z_categories_images, 'activate']);
|
318 |
+
|
319 |
+
// After deactivating the plugin
|
320 |
+
register_deactivation_hook(__FILE__, [$z_categories_images, 'deactivate']);
|
321 |
+
|
322 |
+
function z_taxonomy_image_url($term_id = NULL, $size = 'full', $return_placeholder = FALSE) {
|
323 |
+
$zci = new ZCategoriesImages();
|
324 |
+
return $zci->zTaxonomyImageUrl($term_id, $size, $return_placeholder);
|
325 |
}
|
326 |
|
327 |
+
function z_taxonomy_image($term_id = NULL, $size = 'full', $attr = NULL, $echo = TRUE) {
|
328 |
+
$zci = new ZCategoriesImages();
|
329 |
+
return $zci->zTaxonomyImage($term_id, $size, $attr, $echo);
|
330 |
+
}
|
331 |
}
|
index.php
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Silence is golden.
|
readme.txt
CHANGED
@@ -1,10 +1,11 @@
|
|
1 |
=== Categories Images ===
|
2 |
Contributors: elzahlan
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=G8LC4VSYKYSGA
|
4 |
-
Tags: Category Image, Category Images, Categories Images, taxonomy image, taxonomy images, taxonomies images, category icon, categories icons, category logo, categories logos, admin, wp-admin, category image plugin, categories images plugin, category featured image, categories featured images, feature image for category
|
5 |
Requires at least: 2.8
|
6 |
-
Tested up to: 4
|
7 |
-
Stable tag:
|
|
|
8 |
|
9 |
The Categories Images Plugin allow you to add image with category or taxonomy.
|
10 |
|
@@ -52,10 +53,19 @@ Please check the documentation page:
|
|
52 |
1. Image preview and new image field in add/edit category or taxonomy with upload button which allow you to select current or upload a new image.
|
53 |
2. New image field with (upload/remove) buttons to allow you to edit category or taxonomy image in quick edit.
|
54 |
3. When you click the upload button the wordpress upload box will popup, upload or select image then press use this image.
|
55 |
-
4. New
|
56 |
5. Now you can exclude any taxonomy from the plugin and save changes.
|
57 |
|
58 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
= 2.5.4 =
|
60 |
* Fix compatibility with the latest Wordpress version
|
61 |
|
@@ -133,7 +143,6 @@ Thanks to Patrick http://www.patrickbos.nl and Hassan http://profiles.wordpress.
|
|
133 |
* Added default image placeholder.
|
134 |
* Added thumbnail in categories or taxonomies list.
|
135 |
* Added image thumbnail, image text box, upload button and remove button in quick edit.
|
136 |
-
|
137 |
Thank so much to Joe Tse http://tkjune.com :)
|
138 |
|
139 |
= 1.2 =
|
1 |
=== Categories Images ===
|
2 |
Contributors: elzahlan
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=G8LC4VSYKYSGA
|
4 |
+
Tags: Category Image, Category Images, Categories Images, taxonomy image, taxonomy images, taxonomies images, category icon, categories icons, category logo, categories logos, admin, wp-admin, category image plugin, categories images plugin, category featured image, categories featured images, feature image for category,term image, tag image, term images, tag images, media category
|
5 |
Requires at least: 2.8
|
6 |
+
Tested up to: 5.4
|
7 |
+
Stable tag: 3.0.1
|
8 |
+
License: GPLv2 or later
|
9 |
|
10 |
The Categories Images Plugin allow you to add image with category or taxonomy.
|
11 |
|
53 |
1. Image preview and new image field in add/edit category or taxonomy with upload button which allow you to select current or upload a new image.
|
54 |
2. New image field with (upload/remove) buttons to allow you to edit category or taxonomy image in quick edit.
|
55 |
3. When you click the upload button the wordpress upload box will popup, upload or select image then press use this image.
|
56 |
+
4. New menu (Categories Images) for the plugin settings.
|
57 |
5. Now you can exclude any taxonomy from the plugin and save changes.
|
58 |
|
59 |
== Changelog ==
|
60 |
+
|
61 |
+
= 3.0.1 =
|
62 |
+
* Disable options autoload to enhance wordpress queries performace
|
63 |
+
|
64 |
+
= 3.0.0 =
|
65 |
+
* Fix settings page issues
|
66 |
+
* Fix compatibility with the latest Wordpress version
|
67 |
+
* Rewrote the whole plugin from scratch, now the code is much efficient, readable and cleaner
|
68 |
+
|
69 |
= 2.5.4 =
|
70 |
* Fix compatibility with the latest Wordpress version
|
71 |
|
143 |
* Added default image placeholder.
|
144 |
* Added thumbnail in categories or taxonomies list.
|
145 |
* Added image thumbnail, image text box, upload button and remove button in quick edit.
|
|
|
146 |
Thank so much to Joe Tse http://tkjune.com :)
|
147 |
|
148 |
= 1.2 =
|
screenshot-1.jpg
DELETED
Binary file
|
screenshot-1.png
ADDED
Binary file
|
screenshot-2.jpg
DELETED
Binary file
|
screenshot-2.png
ADDED
Binary file
|
screenshot-3.jpg
DELETED
Binary file
|
screenshot-3.png
ADDED
Binary file
|
screenshot-4.jpg
DELETED
Binary file
|
screenshot-4.png
ADDED
Binary file
|
screenshot-5.jpg
DELETED
Binary file
|
screenshot-5.png
ADDED
Binary file
|
templates/admin.php
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div class="wrap">
|
2 |
+
<h2><?php _e('Categories Images', 'categories-images'); ?></h2>
|
3 |
+
<form method="post" action="options.php">
|
4 |
+
<?php settings_fields('zci_options'); ?>
|
5 |
+
<?php do_settings_sections('zci-options'); ?>
|
6 |
+
<?php submit_button(); ?>
|
7 |
+
</form>
|
8 |
+
</div>
|