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 / autoterms-functions.php

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

652 lines 25.8 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 Autoterms option.
4 *
5 * @return mixed
6 */
7 function taxopress_get_autoterm_data()
8 {
9 return array_filter((array)apply_filters('taxopress_get_autoterm_data', get_option('taxopress_autoterms', []),
10 get_current_blog_id()));
11 }
12
13 /**
14 * Fetch our TAXOPRESS Autoterms content option.
15 *
16 * @return mixed
17 */
18 function taxopress_get_autoterms_content_data()
19 {
20 return array_filter((array)apply_filters('taxopress_get_autoterm_content_data', get_option('taxopress_autoterms_content', []),
21 get_current_blog_id()));
22 }
23
24 /**
25 * Fetch our TAXOPRESS Autoterms schedule option.
26 *
27 * @return mixed
28 */
29 function taxopress_get_autoterms_schedule_data()
30 {
31 return array_filter((array)apply_filters('taxopress_get_autoterm_schedule_data', get_option('taxopress_autoterms_schedule', []),
32 get_current_blog_id()));
33 }
34
35 /**
36 * Get the selected autoterm from the $_POST global.
37 *
38 * @return bool|string False on no result, sanitized autoterm if set.
39 * @internal
40 *
41 */
42 function taxopress_get_current_autoterm()
43 {
44
45 $autoterms = false;
46
47 if (!empty($_GET) && isset($_GET['taxopress_autoterms'])) {
48 $autoterms = sanitize_text_field($_GET['taxopress_autoterms']);
49 } else {
50 $autoterms = taxopress_get_autoterm_data();
51 if (!empty($autoterms)) {
52 // Will return the first array key.
53 $autoterms = key($autoterms);
54 }
55 }
56
57 /**
58 * Filters the current autoterm to edit.
59 *
60 * @param string $autoterms autoterm slug.
61 */
62 return apply_filters('taxopress_current_autoterm', $autoterms);
63 }
64
65 /**
66 * Get auto terms for current post
67 *
68 *
69 * @return mixed
70 */
71 function taxopress_post_type_autoterms()
72 {
73 global $pagenow;
74
75 $allowed_pages = ['post-new.php', 'post.php', 'page.php', 'page-new.php'];
76 if (!in_array($pagenow, $allowed_pages)) {
77 return false;
78 }
79
80 $autoterms = taxopress_get_autoterm_data();
81
82 if (count($autoterms) > 0) {
83 foreach ($autoterms as $autoterm) {
84
85 $post_types = (isset($autoterm['post_types']) && is_array($autoterm['post_types']) && count($autoterm['post_types']) > 0) ? $autoterm['post_types'] : false;
86
87 if (!$post_types) {
88 continue;
89 }
90
91 if (in_array(get_post_type(), $post_types)) {
92 return $autoterm;
93 }
94 }
95 }
96
97 return false;
98 }
99
100 /**
101 * Handle the save and deletion of autoterm data.
102 */
103 function taxopress_process_autoterm()
104 {
105
106 if (wp_doing_ajax()) {
107 return;
108 }
109
110 if (!is_admin()) {
111 return;
112 }
113
114 if(!current_user_can('simple_tags')){
115 return;
116 }
117
118 if (empty($_GET)) {
119 return;
120 }
121
122 if (!isset($_GET['page'])) {
123 return;
124 }
125 if (!in_array($_GET['page'], ['st_autoterms', 'st_autoterms_schedule'])) {
126 return;
127 }
128
129 if (isset($_GET['new_autoterm'])) {
130 if ((int)$_GET['new_autoterm'] === 1) {
131 add_action('admin_notices', "taxopress_autoterms_update_success_admin_notice");
132 add_filter('removable_query_args', 'taxopress_saved_autoterm_filter_removable_query_args');
133 }
134 }
135
136 if (isset($_GET['deleted_autoterm'])) {
137 if ((int)$_GET['deleted_autoterm'] === 1) {
138 add_action('admin_notices', "taxopress_autoterms_delete_success_admin_notice");
139 add_filter('removable_query_args', 'taxopress_deleted_autoterm_filter_removable_query_args');
140 }
141 }
142
143
144 if (!empty($_POST) && isset($_POST['autoterm_submit'])) {
145 $result = '';
146 if (isset($_POST['autoterm_submit'])) {
147 check_admin_referer('taxopress_addedit_autoterm_nonce_action',
148 'taxopress_addedit_autoterm_nonce_field');
149 $result = taxopress_update_autoterm($_POST);
150 }
151
152 if ($result) {
153 wp_safe_redirect(
154 add_query_arg(
155 [
156 'page' => 'st_autoterms',
157 'add' => 'new_item',
158 'action' => 'edit',
159 'taxopress_autoterms' => $result,
160 'new_autoterm' => 1,
161 ],
162 taxopress_admin_url('admin.php')
163 )
164 );
165
166 exit();
167 }
168 } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] === 'taxopress-delete-autoterm') {
169 $nonce = sanitize_text_field($_REQUEST['_wpnonce']);
170 if (wp_verify_nonce($nonce, 'autoterm-action-request-nonce')) {
171 taxopress_action_delete_autoterm(sanitize_text_field($_REQUEST['taxopress_autoterms']));
172 add_action('admin_notices', "taxopress_autoterms_delete_autoterm_admin_notice");
173 }
174 add_filter('removable_query_args', 'taxopress_delete_autoterm_filter_removable_query_args');
175 } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] === 'taxopress-delete-autoterm-log') {
176 $nonce = sanitize_text_field($_REQUEST['_wpnonce']);
177 if (wp_verify_nonce($nonce, 'autoterm-action-request-nonce')) {
178 wp_delete_post((int)$_REQUEST['taxopress_autoterms_log'], true);
179 add_action('admin_notices', "taxopress_autoterms_delete_autoterm_log_admin_notice");
180 }
181 add_filter('removable_query_args', 'taxopress_delete_autoterm_log_filter_removable_query_args');
182 } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] === 'taxopress-delete-autoterm-logs') {
183 $nonce = sanitize_text_field($_REQUEST['_wpnonce']);
184 if (wp_verify_nonce($nonce, 'autoterm-action-request-nonce')) {
185 global $wpdb;
186 $result = $wpdb->query(
187 $wpdb->prepare("
188 DELETE posts, pt, pm
189 FROM {$wpdb->prefix}posts posts
190 LEFT JOIN {$wpdb->prefix}term_relationships pt ON pt.object_id = posts.ID
191 LEFT JOIN {$wpdb->prefix}postmeta pm ON pm.post_id = posts.ID
192 WHERE posts.post_type = %s
193 ",
194 'taxopress_logs'
195 )
196 );
197 add_action('admin_notices', "taxopress_autoterms_delete_autoterm_logs_admin_notice");
198 }
199 add_filter('removable_query_args', 'taxopress_delete_autoterm_log_filter_removable_query_args');
200 } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] === 'taxopress-enable-autoterm-logs') {
201 $nonce = sanitize_text_field($_REQUEST['_wpnonce']);
202 if (wp_verify_nonce($nonce, 'autoterm-action-request-nonce')) {
203 delete_option('taxopress_autoterms_logs_disabled');
204 add_action('admin_notices', "taxopress_autoterms_enable_log_admin_notice");
205 }
206 add_filter('removable_query_args', 'taxopress_delete_autoterm_log_filter_removable_query_args');
207 } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] === 'taxopress-disable-autoterm-logs') {
208 $nonce = sanitize_text_field($_REQUEST['_wpnonce']);
209 if (wp_verify_nonce($nonce, 'autoterm-action-request-nonce')) {
210 update_option('taxopress_autoterms_logs_disabled', 1);
211 add_action('admin_notices', "taxopress_autoterms_disable_log_admin_notice");
212 }
213 add_filter('removable_query_args', 'taxopress_delete_autoterm_log_filter_removable_query_args');
214 } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] === 'taxopress-update-autoterm-limit') {
215 $nonce = sanitize_text_field($_REQUEST['_wpnonce']);
216 if (wp_verify_nonce($nonce, 'autoterm-action-request-nonce')) {
217 $limit = (int)$_REQUEST['limit'];
218 if($limit > 0){
219 update_option('taxopress_auto_terms_logs_limit', $limit);
220 add_action('admin_notices', "taxopress_autoterms_limit_updated_admin_notice");
221 }else{
222 add_action('admin_notices', "taxopress_autoterms_limit_invalid_admin_notice");
223 }
224 }
225 add_filter('removable_query_args', 'taxopress_delete_autoterm_log_filter_removable_query_args');
226 }
227 }
228
229 add_action('admin_init', 'taxopress_process_autoterm', 8);
230
231
232 /**
233 * Create default autoterm.
234 */
235 function taxopress_create_default_autoterm()
236 {
237
238 if (wp_doing_ajax()) {
239 return;
240 }
241
242 if (!is_admin()) {
243 return;
244 }
245
246 if(!current_user_can('simple_tags')){
247 return;
248 }
249
250 if ((int)get_option('taxopress_default_autoterms') > 0) {
251 return;
252 }
253
254 if (count(taxopress_get_autoterm_data()) > 0) {
255 return;
256 }
257
258 //create default or export previous
259 $create_default = true;
260
261 $options = get_option( STAGS_OPTIONS_NAME_AUTO );
262 if(is_array($options) && count($options) > 0 ){
263 foreach($options as $options_post_type => $options_taxdata){
264 if(is_array($options_taxdata) && count($options_taxdata) > 0){
265 $create_default = false;
266 foreach($options_taxdata as $options_taxonomy => $options_taxonomy_data){
267 $taxonomy = get_taxonomy($options_taxonomy);
268 $default = [];
269 $default['taxopress_autoterm']['autoterm_from'] = 'posts';
270 $default['taxopress_autoterm']['title'] = ''. (is_object($taxonomy) ? $taxonomy->labels->name : $options_taxonomy ) .' '. ucwords($options_post_type) .' Auto term';
271 $default['taxopress_autoterm']['taxonomy'] = $options_taxonomy;
272 $default['post_types'] = [];
273 $default['post_status'] = ['publish'];
274 $default['taxopress_autoterm']['autoterm_useall'] = isset($options_taxonomy_data['at_all']) ? $options_taxonomy_data['at_all'] : 0;
275 $default['taxopress_autoterm']['autoterm_useonly'] = isset($options_taxonomy_data['at_all_no']) ? $options_taxonomy_data['at_all_no'] : 0;
276 $default['taxopress_autoterm']['autoterm_target'] = isset($options_taxonomy_data['at_empty']) ? $options_taxonomy_data['at_empty'] : 0;
277 $default['taxopress_autoterm']['autoterm_word'] = isset($options_taxonomy_data['only_full_word']) ? $options_taxonomy_data['only_full_word'] : 0;
278 $default['taxopress_autoterm']['autoterm_hash'] = isset($options_taxonomy_data['allow_hashtag_format']) ? $options_taxonomy_data['allow_hashtag_format'] : 0;
279 $default['specific_terms'] = isset($options_taxonomy_data['auto_list']) ? (array) maybe_unserialize($options_taxonomy_data['auto_list']) : [];
280 $default['taxopress_autoterm']['terms_limit'] = '5';
281 $default['taxopress_autoterm']['synonyms_term'] = 1;
282
283 $result = taxopress_update_autoterm($default);
284 }
285 }
286 }
287 }
288
289 if($create_default){
290 $default = [];
291 $default['taxopress_autoterm']['title'] = esc_html__('Auto term', 'simple-tags');
292 $default['taxopress_autoterm']['taxonomy'] = 'post_tag';
293 $default['post_types'] = [];
294 $default['post_status'] = ['publish'];
295 $default['taxopress_autoterm']['autoterm_from'] = 'posts';
296 $default['taxopress_autoterm']['autoterm_use_taxonomy'] = '1';
297 $default['taxopress_autoterm']['autoterm_useall'] = '1';
298 $default['taxopress_autoterm']['autoterm_useonly'] = '0';
299 $default['taxopress_autoterm']['autoterm_target'] = '0';
300 $default['taxopress_autoterm']['autoterm_word'] = '0';
301 $default['taxopress_autoterm']['autoterm_hash'] = '0';
302 $default['taxopress_autoterm']['terms_limit'] = '5';
303 $default['taxopress_autoterm']['synonyms_term'] = 1;
304 $default['taxopress_autoterm']['autoterm_for_post'] = '1';
305 $default['taxopress_autoterm']['autoterm_for_schedule'] = '1';
306 $default['taxopress_autoterm']['autoterm_for_existing_content'] = '1';
307 $default['taxopress_autoterm']['autoterm_for_metaboxes'] = '1';
308 $default['taxopress_autoterm']['schedule_terms_limit'] = '5';
309 $default['taxopress_autoterm']['schedule_autoterm_target'] = '0';
310 $default['taxopress_autoterm']['schedule_autoterm_word'] = '0';
311 $default['taxopress_autoterm']['schedule_autoterm_hash'] = '0';
312 $default['taxopress_autoterm']['existing_content_terms_limit'] = '5';
313 $default['specific_terms'] = [];
314 $default['find_in_customs_entries'] = [];
315 $default['find_in_custom_fields_custom_items'] = [];
316 $default['find_in_taxonomies_custom_items'] = [];
317 $result = taxopress_update_autoterm($default);
318 }
319 update_option('taxopress_default_autoterms', $result);
320 }
321
322 add_action('admin_init', 'taxopress_create_default_autoterm', 8);
323
324
325 /**
326 * Add to or update our TAXOPRESS option with new data.
327 *
328 *
329 * @param array $data Array of autoterm data to update. Optional.
330 * @return bool|string False on failure, string on success.
331 * @internal
332 *
333 */
334 function taxopress_update_autoterm($data = [])
335 {
336 $sanitized_data = [];
337 foreach ($data as $key => $value) {
338 if (!is_array($value)) {
339 $sanitized_data[$key] = taxopress_sanitize_text_field($value);
340 } else {
341 $new_value = [];
342 foreach ($data[$key] as $option_key => $option_value) {
343 if ($option_key === 'terms_regex_code') {
344 $regex_pattern = sanitize_text_field($option_value);
345 if ( !empty($regex_pattern) && preg_match( $regex_pattern, '' ) !== false ) {
346 $new_value[$option_key] = $regex_pattern;
347 } else {
348 $new_value[$option_key] = '';//invalid expression
349 }
350 } else {
351 $new_value[$option_key] = taxopress_sanitize_text_field($option_value);
352 }
353 }
354 $sanitized_data[$key] = $new_value;
355 }
356 }
357 $data = $sanitized_data;
358
359 $autoterms = taxopress_get_autoterm_data();
360
361 $title = $data['taxopress_autoterm']['title'];
362 $title = str_replace('"', '', htmlspecialchars_decode($title));
363 $title = htmlspecialchars($title, ENT_QUOTES);
364 $title = trim($title);
365 $data['taxopress_autoterm']['title'] = stripslashes_deep($title);
366
367
368 //update other post post
369 $data['taxopress_autoterm']['specific_terms'] = isset($data['specific_terms']) ? $data['specific_terms'] : [];
370 $data['taxopress_autoterm']['post_types'] = isset($data['post_types']) ? $data['post_types'] : [];
371 $data['taxopress_autoterm']['post_status'] = isset($data['post_status']) ? $data['post_status'] : [];
372
373 $data['taxopress_autoterm']['html_exclusion'] = isset($data['html_exclusion']) ? $data['html_exclusion'] : [];
374 $data['taxopress_autoterm']['html_exclusion_customs'] = isset($data['html_exclusion_customs']) ? $data['html_exclusion_customs'] : [];
375 $data['taxopress_autoterm']['html_exclusion_customs_entry'] = isset($data['html_exclusion_customs_entry']) ? array_unique($data['html_exclusion_customs_entry']) : [];
376
377 $data['taxopress_autoterm']['find_in_customs_entries'] = isset($data['find_in_customs_entries']) ? $data['find_in_customs_entries'] : [];
378 $data['taxopress_autoterm']['find_in_custom_fields_custom_items'] = isset($data['find_in_custom_fields_custom_items']) ? $data['find_in_custom_fields_custom_items'] : [];
379 $data['taxopress_autoterm']['find_in_taxonomies_custom_items'] = isset($data['find_in_taxonomies_custom_items']) ? $data['find_in_taxonomies_custom_items'] : [];
380
381
382 //update our custom checkbox value if not checked
383 if (!isset($data['taxopress_autoterm']['autoterm_useall'])) {
384 $data['taxopress_autoterm']['autoterm_useall'] = 0;
385 }
386 if (!isset($data['taxopress_autoterm']['autoterm_useonly'])) {
387 $data['taxopress_autoterm']['autoterm_useonly'] = 0;
388 }
389 if (!isset($data['taxopress_autoterm']['autoterm_target'])) {
390 $data['taxopress_autoterm']['autoterm_target'] = 0;
391 }
392 if (!isset($data['taxopress_autoterm']['autoterm_word'])) {
393 $data['taxopress_autoterm']['autoterm_word'] = 0;
394 }
395 if (!isset($data['taxopress_autoterm']['autoterm_hash'])) {
396 $data['taxopress_autoterm']['autoterm_hash'] = 0;
397 }
398 if (!isset($data['taxopress_autoterm']['synonyms_term'])) {
399 $data['taxopress_autoterm']['synonyms_term'] = 0;
400 }
401 if (!isset($data['taxopress_autoterm']['autoterm_for_post'])) {
402 $data['taxopress_autoterm']['autoterm_for_post'] = 0;
403 }
404 if (!isset($data['taxopress_autoterm']['autoterm_for_schedule'])) {
405 $data['taxopress_autoterm']['autoterm_for_schedule'] = 0;
406 }
407 if (!isset($data['taxopress_autoterm']['autoterm_for_existing_content'])) {
408 $data['taxopress_autoterm']['autoterm_for_existing_content'] = 0;
409 }
410 if (!isset($data['taxopress_autoterm']['autoterm_for_metaboxes'])) {
411 $data['taxopress_autoterm']['autoterm_for_metaboxes'] = 0;
412 }
413 if (!isset($data['taxopress_autoterm']['schedule_autoterm_target'])) {
414 $data['taxopress_autoterm']['schedule_autoterm_target'] = 0;
415 }
416 if (!isset($data['taxopress_autoterm']['schedule_autoterm_word'])) {
417 $data['taxopress_autoterm']['schedule_autoterm_word'] = 0;
418 }
419 if (!isset($data['taxopress_autoterm']['schedule_autoterm_hash'])) {
420 $data['taxopress_autoterm']['schedule_autoterm_hash'] = 0;
421 }
422
423 if (isset($data['edited_autoterm'])) {
424 $autoterm_id = $data['edited_autoterm'];
425 $autoterms[$autoterm_id] = $data['taxopress_autoterm'];
426 $success = update_option('taxopress_autoterms', $autoterms);
427 //return 'update_success';
428 } else {
429 $autoterm_id = (int)get_option('taxopress_autoterm_ids_increament') + 1;
430 $data['taxopress_autoterm']['ID'] = $autoterm_id;
431 $autoterms[$autoterm_id] = $data['taxopress_autoterm'];
432 $success = update_option('taxopress_autoterms', $autoterms);
433 $update_id = update_option('taxopress_autoterm_ids_increament', $autoterm_id);
434 //return 'add_success';
435 }
436
437 return $autoterm_id;
438 }
439
440 /**
441 * Successful update callback.
442 */
443 function taxopress_autoterms_update_success_admin_notice()
444 {
445 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
446 echo taxopress_admin_notices_helper(esc_html__('Settings updated successfully.', 'simple-tags'));
447 }
448
449 /**
450 * Successful deleted callback.
451 */
452 function taxopress_autoterms_delete_success_admin_notice()
453 {
454 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
455 echo taxopress_admin_notices_helper(esc_html__('Auto Terms successfully deleted.', 'simple-tags'), false);
456 }
457
458 function taxopress_autoterms_enable_log_admin_notice()
459 {
460 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
461 echo taxopress_admin_notices_helper(esc_html__('Auto Terms logs enabled successfully.', 'simple-tags'));
462 }
463
464 function taxopress_autoterms_disable_log_admin_notice()
465 {
466 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
467 echo taxopress_admin_notices_helper(esc_html__('Auto Terms logs disabled successfully.', 'simple-tags'));
468 }
469
470 function taxopress_autoterms_delete_autoterm_admin_notice()
471 {
472 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
473 echo taxopress_admin_notices_helper(esc_html__('Auto Terms deleted successfully.', 'simple-tags'));
474 }
475
476 function taxopress_autoterms_delete_autoterm_log_admin_notice()
477 {
478 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
479 echo taxopress_admin_notices_helper(esc_html__('Auto Terms log deleted successfully.', 'simple-tags'));
480 }
481
482 function taxopress_autoterms_delete_autoterm_logs_admin_notice()
483 {
484 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
485 echo taxopress_admin_notices_helper(esc_html__('Auto Terms logs deleted successfully.', 'simple-tags'));
486 }
487
488 function taxopress_autoterms_limit_updated_admin_notice()
489 {
490 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
491 echo taxopress_admin_notices_helper(esc_html__('Auto Terms limit updated successfully.', 'simple-tags'));
492 }
493
494 function taxopress_autoterms_limit_invalid_admin_notice()
495 {
496 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
497 echo taxopress_admin_notices_helper(esc_html__('Auto Terms limit must be greater than 0.', 'simple-tags'), false);
498 }
499
500 /**
501 * Filters the list of query arguments which get removed from admin area URLs in WordPress.
502 *
503 * @link https://core.trac.wordpress.org/ticket/23367
504 *
505 * @param string[] $args Array of removable query arguments.
506 * @return string[] Updated array of removable query arguments.
507 */
508 function taxopress_saved_autoterm_filter_removable_query_args(array $args)
509 {
510 return array_merge($args, [
511 'new_autoterm',
512 ]);
513 }
514
515 /**
516 * Filters the list of query arguments which get removed from admin area URLs in WordPress.
517 *
518 * @link https://core.trac.wordpress.org/ticket/23367
519 *
520 * @param string[] $args Array of removable query arguments.
521 * @return string[] Updated array of removable query arguments.
522 */
523 function taxopress_deleted_autoterm_filter_removable_query_args(array $args)
524 {
525 return array_merge($args, [
526 'deleted_autoterm',
527 ]);
528 }
529
530 /**
531 * Filters the list of query arguments which get removed from admin area URLs in WordPress.
532 *
533 * @link https://core.trac.wordpress.org/ticket/23367
534 *
535 * @param string[] $args Array of removable query arguments.
536 * @return string[] Updated array of removable query arguments.
537 */
538 function taxopress_delete_autoterm_filter_removable_query_args(array $args)
539 {
540 return array_merge($args, [
541 'action',
542 'taxopress_autoterms',
543 '_wpnonce',
544 ]);
545 }
546
547 /**
548 * Filters the list of query arguments which get removed from admin area URLs in WordPress.
549 *
550 * @link https://core.trac.wordpress.org/ticket/23367
551 *
552 * @param string[] $args Array of removable query arguments.
553 * @return string[] Updated array of removable query arguments.
554 */
555 function taxopress_delete_autoterm_log_filter_removable_query_args(array $args)
556 {
557 return array_merge($args, [
558 'action',
559 'taxopress_autoterms_log',
560 '_wpnonce',
561 ]);
562 }
563
564 /**
565 * Delete our custom autoterm from the array of autoterms.
566 * @return bool|string False on failure, string on success.
567 */
568 function taxopress_action_delete_autoterm($autoterm_id)
569 {
570 $autoterms = taxopress_get_autoterm_data();
571
572 if (array_key_exists($autoterm_id, $autoterms)) {
573 unset($autoterms[$autoterm_id]);
574 $success = update_option('taxopress_autoterms', $autoterms);
575 }
576
577 if (isset($success)) {
578 add_action('admin_notices', "taxopress_taxdeleted_admin_notice");
579 wp_safe_redirect(
580 add_query_arg(
581 [
582 'page' => 'st_autoterms',
583 'deleted_autoterm' => 1,
584 ],
585 taxopress_admin_url('admin.php')
586 )
587 );
588 exit();
589 }
590 }
591
592 /**
593 * Get auto terms logs data
594 *
595 */
596 function taxopress_autoterms_logs_data($per_page = 20, $current_page = 1, $orderby = 'ID', $order = 'desc', $schedule_query = false)
597 {
598
599 $meta_query[] = array('relation' => 'AND');
600 $meta_query[] = array(
601 'key' => '_taxopress_log_component',
602 'value' => 'st_autoterms',
603 );
604
605 /**
606 * Custom filter handler
607 */
608 $custom_filters = [
609 'log_source_filter' => '_taxopress_log_action',
610 'log_filter_post_type' => '_taxopress_log_post_type',
611 'log_filter_taxonomy' => '_taxopress_log_taxonomy',
612 'log_filter_status_message' => '_taxopress_log_status_message',
613 'log_filter_settings' => '_taxopress_log_option_id'
614 ];
615 foreach ($custom_filters as $filter => $option) {
616 if (!empty($_REQUEST[$filter])) {
617 $meta_query[] = array(
618 'key' => sanitize_key($option),
619 'value' => sanitize_text_field($_REQUEST[$filter]),
620 );
621 }
622 }
623
624 if ($schedule_query) {
625 $meta_query[] = array(
626 'key' => '_taxopress_log_action',
627 'value' => ['daily_cron_schedule', 'hourly_cron_schedule'],
628 'compare' => 'IN'
629 );
630 }
631
632 $logs_arg = array(
633 'post_type' => 'taxopress_logs',
634 'post_status' => 'publish',
635 'paged' => $current_page,
636 'posts_per_page' => $per_page,
637 'meta_query' => $meta_query,
638 'orderby' => $orderby,
639 'order' => $order,
640 );
641
642 /**
643 * Handle search
644 */
645 if ((!empty($_REQUEST['s'])) && $search = sanitize_text_field($_REQUEST['s'])) {
646 $logs_arg['s'] = $search;
647 }
648
649 $logs = new WP_Query($logs_arg);
650
651 return ['posts'=> $logs->posts, 'counts'=> $logs->found_posts];
652 }