PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.52.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.52.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.52.0, at inc/autoterms-functions.php

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