PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.40.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.40.0
3.54.0 3.53.0 3.52.0 3.51.0 3.50.0 3.45.0 3.38.0 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.40.0 3.40.1 3.41.0 3.42.0 3.43.0 3.44.0 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 All 178 releases
simple-tags / inc / tag-clouds-functions.php

tag-clouds-functions.php in Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms 3.40.0, at inc/tag-clouds-functions.php

352 lines 11.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Fetch our TAXOPRESS Terms Display option.
4 *
5 * @return mixed
6 */
7 function taxopress_get_tagcloud_data()
8 {
9 return array_filter( (array)apply_filters('taxopress_get_tagcloud_data', get_option('taxopress_tagclouds', []), get_current_blog_id()));
10 }
11
12 /**
13 * Get the selected tagcloud from the $_POST global.
14 *
15 * @return bool|string False on no result, sanitized tagcloud if set.
16 * @internal
17 *
18 */
19 function taxopress_get_current_tagcloud()
20 {
21
22 $tagclouds = false;
23
24 if (!empty($_GET) && isset($_GET['taxopress_termsdisplay'])) {
25 $tagclouds = sanitize_text_field($_GET['taxopress_termsdisplay']);
26 } else {
27 $tagclouds = taxopress_get_tagcloud_data();
28 if (!empty($tagclouds)) {
29 // Will return the first array key.
30 $tagclouds = key($tagclouds);
31 }
32 }
33
34 /**
35 * Filters the current tagcloud to edit.
36 *
37 * @param string $tagclouds tagcloud slug.
38 */
39 return apply_filters('taxopress_current_tagcloud', $tagclouds);
40 }
41
42 /**
43 * Handle the save and deletion of tagcloud data.
44 */
45 function taxopress_process_tagcloud()
46 {
47
48 if (wp_doing_ajax()) {
49 return;
50 }
51
52 if (!is_admin()) {
53 return;
54 }
55
56 if (empty($_GET)) {
57 return;
58 }
59
60 if (!isset($_GET['page'])) {
61 return;
62 }
63 if ('st_terms_display' !== $_GET['page']) {
64 return;
65 }
66
67 if(!current_user_can('simple_tags')){
68 return;
69 }
70
71 if (isset($_GET['new_tagcloud'])) {
72 if ((int)$_GET['new_tagcloud'] === 1) {
73 add_action('admin_notices', "taxopress_termsdisplay_update_success_admin_notice");
74 add_filter('removable_query_args', 'taxopress_saved_tagcloud_filter_removable_query_args');
75 }
76 }
77
78 if (isset($_GET['deleted_tagcloud'])) {
79 if ((int)$_GET['deleted_tagcloud'] === 1) {
80 add_action('admin_notices', "taxopress_termsdisplay_delete_success_admin_notice");
81 add_filter('removable_query_args', 'taxopress_deleted_tagcloud_filter_removable_query_args');
82 }
83 }
84
85
86 if (!empty($_POST) && isset($_POST['tagcloud_submit'])) {
87 $result = '';
88 if (isset($_POST['tagcloud_submit'])) {
89 check_admin_referer('taxopress_addedit_tagcloud_nonce_action', 'taxopress_addedit_tagcloud_nonce_field');
90 $result = taxopress_update_tagcloud($_POST);
91 }
92
93 if ($result) {
94 wp_safe_redirect(
95 add_query_arg(
96 [
97 'page' => 'st_terms_display',
98 'add' => 'new_item',
99 'action' => 'edit',
100 'taxopress_termsdisplay' => $result,
101 'new_tagcloud' => 1,
102 ],
103 taxopress_admin_url('admin.php')
104 )
105 );
106
107 exit();
108 }
109 } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] === 'taxopress-delete-tagcloud') {
110 $nonce = sanitize_text_field($_REQUEST['_wpnonce']);
111 if (wp_verify_nonce($nonce, 'tagcloud-action-request-nonce')) {
112 taxopress_action_delete_tagcloud(sanitize_text_field($_REQUEST['taxopress_termsdisplay']));
113 }
114 add_filter('removable_query_args', 'taxopress_delete_tagcloud_filter_removable_query_args');
115 }
116 }
117
118
119
120 /**
121 * Create default cloud tag.
122 */
123 function taxopress_create_default_tag_cloud()
124 {
125
126 if (wp_doing_ajax()) {
127 return;
128 }
129
130 if (!is_admin()) {
131 return;
132 }
133
134 if ((int)get_option('taxopress_default_tagclouds') > 0 ) {
135 return;
136 }
137
138 if (count(taxopress_get_tagcloud_data()) > 0 ) {
139 return;
140 }
141
142 if(!current_user_can('simple_tags')){
143 return;
144 }
145
146 $default = [];
147 $default['taxopress_tag_cloud']['title'] = esc_html__('Terms Display', 'simple-tags');
148 $default['taxopress_tag_cloud']['post_type'] = '';
149 $default['taxopress_tag_cloud']['before'] = '';
150 $default['taxopress_tag_cloud']['after'] = '';
151 $default['taxopress_tag_cloud']['taxonomy'] = 'post_tag';
152 $default['taxopress_tag_cloud']['max'] = 20;
153 $default['taxopress_tag_cloud']['selectionby'] = 'count';
154 $default['taxopress_tag_cloud']['selection'] = 'desc';
155 $default['taxopress_tag_cloud']['orderby'] = 'random';
156 $default['taxopress_tag_cloud']['order'] = 'desc';
157 $default['taxopress_tag_cloud']['smallest'] = 12;
158 $default['taxopress_tag_cloud']['largest'] = 12;
159 $default['taxopress_tag_cloud']['unit'] = 'pt';
160 $default['taxopress_tag_cloud']['format'] = 'border';
161 $default['taxopress_tag_cloud']['color'] = 1;
162 $default['taxopress_tag_cloud']['mincolor'] = '#353535';
163 $default['taxopress_tag_cloud']['maxcolor'] = '#000000';
164 $default['taxopress_tag_cloud']['xformat'] = '<a href="%tag_link%" id="tag-link-%tag_id%" class="st-tags t%tag_scale%" title="%tag_count% topics" %tag_rel% style="%tag_size% %tag_color%">%tag_name%</a>';
165 $default['taxopress_tag_cloud']['limit_days'] = 0;
166 $default['tagcloud_submit'] = 'Add Terms Display';
167 $default['cpt_tax_status'] = 'new';
168 $result = taxopress_update_tagcloud($default);
169 update_option('taxopress_default_tagclouds', $result);
170 }
171
172
173 /**
174 * Add to or update our TAXOPRESS option with new data.
175 *
176 *
177 * @param array $data Array of tagcloud data to update. Optional.
178 * @return bool|string False on failure, string on success.
179 * @internal
180 *
181 */
182 function taxopress_update_tagcloud($data = [])
183 {
184 $sanitized_data = [];
185 foreach ($data as $key => $value) {
186 if (!is_array($value)) {
187 $sanitized_data[$key] = taxopress_sanitize_text_field($value);
188 } else {
189 $new_value = [];
190 foreach ($data[$key] as $option_key => $option_value) {
191 if ($option_key === 'xformat') {
192 $new_value[$option_key] = taxopress_sanitize_text_field($option_value);
193 } else {
194 $new_value[$option_key] = taxopress_sanitize_text_field($option_value);
195 }
196 }
197 $sanitized_data[$key] = $new_value;
198 }
199 }
200 $data = $sanitized_data;
201
202 $tagclouds = taxopress_get_tagcloud_data();
203
204 $title = $data['taxopress_tag_cloud']['title'];
205 $title = str_replace('"', '', htmlspecialchars_decode($title));
206 $title = htmlspecialchars($title, ENT_QUOTES);
207 $title = trim($title);
208 $data['taxopress_tag_cloud']['title'] = stripslashes_deep($title);
209
210 $xformat = $data['taxopress_tag_cloud']['xformat'];
211 $data['taxopress_tag_cloud']['xformat'] = stripslashes_deep($xformat);
212
213 if( !empty($data['taxopress_tag_cloud']['color'])){
214 $data['taxopress_tag_cloud']['color'] = taxopress_disp_boolean($data['taxopress_tag_cloud']['color']);
215 }
216
217 if (isset($data['edited_tagcloud'])) {
218 $tagcloud_id = $data['edited_tagcloud'];
219 $tagclouds[$tagcloud_id] = $data['taxopress_tag_cloud'];
220 $success = update_option('taxopress_tagclouds', $tagclouds);
221 //return 'update_success';
222 }else{
223 $tagcloud_id = (int)get_option('taxopress_tagcloud_ids_increament')+1;
224 $data['taxopress_tag_cloud']['ID'] = $tagcloud_id;
225 $tagclouds[$tagcloud_id] = $data['taxopress_tag_cloud'];
226 $success = update_option('taxopress_tagclouds', $tagclouds);
227 $update_id = update_option('taxopress_tagcloud_ids_increament', $tagcloud_id);
228 //return 'add_success';
229 }
230 return $tagcloud_id;
231
232 }
233
234 /**
235 * Successful update callback.
236 */
237 function taxopress_termsdisplay_update_success_admin_notice()
238 {
239 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
240 echo taxopress_admin_notices_helper(esc_html__('Settings updated successfully.', 'simple-tags'));
241 }
242
243 /**
244 * Successful deleted callback.
245 */
246 function taxopress_termsdisplay_delete_success_admin_notice()
247 {
248 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
249 echo taxopress_admin_notices_helper(esc_html__('Terms Display successfully deleted.', 'simple-tags'), false);
250 }
251
252 /**
253 * Filters the list of query arguments which get removed from admin area URLs in WordPress.
254 *
255 * @link https://core.trac.wordpress.org/ticket/23367
256 *
257 * @param string[] $args Array of removable query arguments.
258 * @return string[] Updated array of removable query arguments.
259 */
260 function taxopress_saved_tagcloud_filter_removable_query_args(array $args)
261 {
262 return array_merge($args, [
263 'new_tagcloud',
264 ]);
265 }
266
267 /**
268 * Filters the list of query arguments which get removed from admin area URLs in WordPress.
269 *
270 * @link https://core.trac.wordpress.org/ticket/23367
271 *
272 * @param string[] $args Array of removable query arguments.
273 * @return string[] Updated array of removable query arguments.
274 */
275 function taxopress_deleted_tagcloud_filter_removable_query_args(array $args)
276 {
277 return array_merge($args, [
278 'deleted_tagcloud',
279 ]);
280 }
281
282 /**
283 * Filters the list of query arguments which get removed from admin area URLs in WordPress.
284 *
285 * @link https://core.trac.wordpress.org/ticket/23367
286 *
287 * @param string[] $args Array of removable query arguments.
288 * @return string[] Updated array of removable query arguments.
289 */
290 function taxopress_delete_tagcloud_filter_removable_query_args(array $args)
291 {
292 return array_merge($args, [
293 'action',
294 'taxopress_termsdisplay',
295 '_wpnonce',
296 ]);
297 }
298
299 /**
300 * Delete our custom taxonomy from the array of taxonomies.
301 * @return bool|string False on failure, string on success.
302 */
303 function taxopress_action_delete_tagcloud($tagcloud_id)
304 {
305 $tagclouds = taxopress_get_tagcloud_data();
306
307 if (array_key_exists($tagcloud_id, $tagclouds)) {
308 unset($tagclouds[$tagcloud_id]);
309 $success = update_option('taxopress_tagclouds', $tagclouds);
310 }
311
312 if (isset($success)) {
313 add_action('admin_notices', "taxopress_taxdeleted_admin_notice");
314 wp_safe_redirect(
315 add_query_arg(
316 [
317 'page' => 'st_terms_display',
318 'deleted_tagcloud' => 1,
319 ],
320 taxopress_admin_url('admin.php')
321 )
322 );
323 exit();
324 }
325 }
326
327 function taxopress_termsdisplay_shortcode($atts)
328 {
329 extract(shortcode_atts(array(
330 'id' => 0
331 ), $atts));
332
333 $tagcloud_id = $id;
334 $tagclouds = taxopress_get_tagcloud_data();
335
336 ob_start();
337 if (array_key_exists($tagcloud_id, $tagclouds)) {
338 $tagclouds[$tagcloud_id]['number'] = $tagclouds[$tagcloud_id]['max'];
339 if (!isset($tagclouds[$tagcloud_id]['color'])) {
340 $tagclouds[$tagcloud_id]['color'] = 'false';
341 }
342 $tagcloud_arg = build_query($tagclouds[$tagcloud_id]);
343 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
344 echo SimpleTags_Client_TagCloud::extendedTagCloud( $tagcloud_arg );
345
346 }
347
348 $html = ob_get_clean();
349 return $html;
350
351
352 }