PluginProbe
PublishPress Taxonomies – Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 4.0.0
PublishPress Taxonomies – Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v4.0.0
4.0.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 All 179 releases
simple-tags / inc / class.admin.php

class.admin.php in PublishPress Taxonomies – Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms 4.0.0, at inc/class.admin.php

1,627 lines 72.4 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.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.NotPrepared,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotValidated -- Legacy PublishPress Taxonomies file: keep behavior unchanged while documenting existing PHPCS exceptions.
4
5 // Include modules
6 require_once(TAXOPRESS_ABSPATH . '/modules/taxopress-ai/taxopress-ai.php');
7
8 class SimpleTags_Admin
9 {
10 // CPT and Taxonomy support
11 public static $post_type = 'post';
12 public static $post_type_name = '';
13 public static $taxonomy = '';
14 public static $taxo_name = '';
15 public static $admin_url = '';
16 public static $enabled_menus = [];
17
18 public const MENU_SLUG = 'st_options';
19
20 /**
21 * Initialize Admin
22 *
23 * @return void
24 * @author WebFactory Ltd
25 */
26 public function __construct()
27 {
28 // DB Upgrade ?
29 self::upgrade();
30
31 // Which taxo ?
32 self::register_taxonomy();
33
34 // Plugin installer
35 add_action('admin_init', array(__CLASS__, 'plugin_installer_upgrade_code'));
36
37 // Redirect on plugin activation
38 add_action('admin_init', array(__CLASS__, 'redirect_on_activate'));
39
40 // Admin menu
41 add_action('admin_menu', array(__CLASS__, 'admin_menu'));
42
43 //Admin footer credit
44 add_filter('admin_body_class', array(__CLASS__, 'taxopress_admin_body_class'));
45 add_action('in_admin_footer', array(__CLASS__, 'taxopress_admin_footer'));
46
47 // Load JavaScript and CSS
48 add_action('admin_enqueue_scripts', array(__CLASS__, 'admin_enqueue_scripts'));
49
50 add_action('admin_enqueue_scripts', [$this, 'maybe_enqueue_frontend_assets_in_admin']);
51
52 add_action('admin_head', array($this, 'taxopress_hide_other_plugin_notices'));
53
54 add_action('wp_ajax_taxopress_search_posts', [$this, 'taxopress_search_posts_ajax']);
55
56 //ui class is used accross many pages. So, it should be here
57 require STAGS_DIR . '/inc/class.admin.taxonomies.ui.php';
58
59 $dashboard_screen = (isset($_GET['page']) && $_GET['page'] === 'st_dashboard') ? true : false;
60
61 //dashboard
62 require STAGS_DIR . '/inc/dashboard.php';
63 SimpleTags_Dashboard::get_instance();
64 self::$enabled_menus['st_dashboard'] = esc_html__('Dashboard', 'simple-tags');
65 if (1 === (int) SimpleTags_Plugin::get_option_value('active_taxonomies')) {
66 self::$enabled_menus['st_taxonomies'] = esc_html__('Taxonomies', 'simple-tags');
67 }
68
69 //hidden-terms
70 if (1 === (int) SimpleTags_Plugin::get_option_value('enable_hidden_terms')) {
71 require STAGS_DIR . '/inc/hidden-terms.php';
72 SimpleTags_Hidden_Terms::get_instance();
73 }
74
75 //terms
76 if ($dashboard_screen || 1 === (int) SimpleTags_Plugin::get_option_value('active_st_terms')) {
77 require STAGS_DIR . '/inc/terms-table.php';
78 require STAGS_DIR . '/inc/terms.php';
79 SimpleTags_Terms::get_instance();
80 self::$enabled_menus['st_terms'] = esc_html__('Terms', 'simple-tags');
81 }
82
83 //posts
84 if ($dashboard_screen || 1 === (int) SimpleTags_Plugin::get_option_value('active_st_posts')) {
85 require STAGS_DIR . '/inc/posts-table.php';
86 require STAGS_DIR . '/inc/posts.php';
87 SimpleTags_Posts::get_instance();
88 self::$enabled_menus['st_posts'] = esc_html__('Posts', 'simple-tags');
89 }
90
91 //tag clouds/ terms display
92 if ($dashboard_screen || 1 === (int) SimpleTags_Plugin::get_option_value('active_terms_display')) {
93 require_once STAGS_DIR . '/inc/tag-clouds-action.php';
94 require STAGS_DIR . '/inc/tag-clouds-table.php';
95 require STAGS_DIR . '/inc/tag-clouds.php';
96 SimpleTags_Tag_Clouds::get_instance();
97 }
98
99 //post tags
100 if ($dashboard_screen || 1 === (int) SimpleTags_Plugin::get_option_value('active_post_tags')) {
101 require_once STAGS_DIR . '/inc/post-tags-action.php';
102 require STAGS_DIR . '/inc/post-tags-table.php';
103 require STAGS_DIR . '/inc/post-tags.php';
104 SimpleTags_Post_Tags::get_instance();
105 }
106
107 //Related Posts
108 if ($dashboard_screen || 1 === (int) SimpleTags_Plugin::get_option_value('active_related_posts_new')) {
109 require_once STAGS_DIR . '/inc/related-posts-action.php';
110 require STAGS_DIR . '/inc/related-posts-table.php';
111 require STAGS_DIR . '/inc/related-posts.php';
112 SimpleTags_Related_Post::get_instance();
113 }
114
115 //Auto Links
116 if ($dashboard_screen || 1 === (int) SimpleTags_Plugin::get_option_value('active_auto_links')) {
117 require STAGS_DIR . '/inc/autolinks-table.php';
118 require STAGS_DIR . '/inc/autolinks.php';
119 SimpleTags_Autolink::get_instance();
120 }
121
122 //Auto Terms
123 if ($dashboard_screen || 1 === (int) SimpleTags_Plugin::get_option_value('active_auto_terms')) {
124 require STAGS_DIR . '/inc/autoterms-table.php';
125 require STAGS_DIR . '/inc/autoterms-logs-table.php';
126 require STAGS_DIR . '/inc/autoterms.php';
127 require STAGS_DIR . '/inc/autoterms_content.php';
128 require STAGS_DIR . '/inc/schedule.php';
129 require STAGS_DIR . '/inc/schedule-logs-table.php';
130 SimpleTags_Autoterms::get_instance();
131 SimpleTags_Autoterms_Content::get_instance();
132 SimpleTags_Autoterms_Schedule::get_instance();
133 self::$enabled_menus['st_autoterms'] = esc_html__('Auto Terms', 'simple-tags');
134 }
135
136 TaxoPress_AI_Module::get_instance();
137
138 //click terms option
139 require STAGS_DIR . '/inc/class.admin.clickterms.php';
140 new SimpleTags_Admin_ClickTags();
141
142 require STAGS_DIR . '/inc/class.admin.autocomplete.php';
143 new SimpleTags_Admin_Autocomplete();
144
145 // Mass edit terms
146 if ($dashboard_screen || 1 === (int) SimpleTags_Plugin::get_option_value('active_mass_edit')) {
147 require STAGS_DIR . '/inc/class.admin.mass.php';
148 new SimpleTags_Admin_Mass();
149 }
150
151 // Manage terms
152 if ($dashboard_screen || 1 === (int) SimpleTags_Plugin::get_option_value('active_manage')) {
153 require STAGS_DIR . '/inc/class-tag-table.php';
154 require STAGS_DIR . '/inc/class.admin.manage.php';
155 SimpleTags_Admin_Manage::get_instance();
156 }
157
158 require STAGS_DIR . '/inc/class.admin.post.php';
159 new SimpleTags_Admin_Post_Settings();
160
161 //taxonomies
162 if ($dashboard_screen || 1 === (int) SimpleTags_Plugin::get_option_value('active_taxonomies')) {
163 require_once STAGS_DIR . '/inc/taxonomies-action.php';
164 require STAGS_DIR . '/inc/class-taxonomies-table.php';
165 require STAGS_DIR . '/inc/taxonomies.php';
166 SimpleTags_Admin_Taxonomies::get_instance();
167 }
168
169 do_action('taxopress_admin_class_after_includes');
170
171 // Ajax action, JS Helper and admin action
172 add_action('wp_ajax_simpletags', array(__CLASS__, 'ajax_check'));
173 // Save dashboard feature
174 add_action('wp_ajax_save_taxopress_dashboard_feature_by_ajax', [__CLASS__, 'saveDashboardFeature']);
175 // Plugin action links
176 add_filter('plugin_action_links_' . plugin_basename(TAXOPRESS_FILE), [__CLASS__, 'plugin_settings_link']);
177 }
178
179 public function taxopress_hide_other_plugin_notices()
180 {
181 global $pagenow;
182
183 $taxopress_pages = taxopress_admin_pages();
184
185 if (isset($_GET['page']) && in_array($_GET['page'], $taxopress_pages)) {
186 echo '<style>
187 .notice:not(.taxopress-notice) {
188 display: none !important;
189 }
190 </style>';
191 }
192 }
193
194 /**
195 * Plugin action links
196 */
197 public static function plugin_settings_link($links)
198 {
199
200 foreach (self::$enabled_menus as $menu_slug => $menu_title) {
201 $links[] = '<a href="' . admin_url('admin.php?page=' . $menu_slug) . '">' . $menu_title . '</a>';
202 }
203
204 return $links;
205 }
206
207 /**
208 * Ajax for saving a feature from dashboard page
209 *
210 * Copied from PublishPress Blocks
211 *
212 * @return boolean,void Return false if failure, echo json on success
213 */
214 public static function saveDashboardFeature()
215 {
216 if (!current_user_can('admin_simple_tags')) {
217 wp_send_json(__('No permission!', 'simple-tags'), 403);
218 return false;
219 }
220
221 if (
222 !wp_verify_nonce(
223 sanitize_key(wp_unslash($_POST['nonce'])),
224 'st-admin-js'
225 )
226 ) {
227 wp_send_json(__('Invalid nonce token!', 'simple-tags'), 400);
228 return false;
229 }
230
231 if (empty($_POST['feature'])) {
232 wp_send_json(__('Error: wrong data', 'simple-tags'), 400);
233 return false;
234 }
235
236 $feature = sanitize_text_field(wp_unslash($_POST['feature']));
237 $new_state = sanitize_text_field(wp_unslash($_POST['new_state']));
238
239 SimpleTags_Plugin::set_option_value($feature, $new_state);
240
241 wp_send_json(true, 200);
242 }
243
244 /**
245 * Ajax Dispatcher
246 */
247 public static function ajax_check()
248 {
249 if (isset($_GET['stags_action']) && 'maybe_create_tag' === $_GET['stags_action'] && isset($_GET['tag'])) {
250 if (!check_ajax_referer('st-admin-js', 'nonce', false)) {
251 wp_send_json_error(['message' => __('Security check failed.', 'simple-tags')], 403);
252 }
253
254 $taxonomy = get_taxonomy('post_tag');
255 if (!$taxonomy || empty($taxonomy->cap->manage_terms) || !current_user_can($taxonomy->cap->manage_terms)) {
256 wp_send_json_error(['message' => __('Permission denied.', 'simple-tags')], 403);
257 }
258
259 self::maybe_create_tag(sanitize_text_field(wp_unslash($_GET['tag'])));
260 }
261 }
262
263 /**
264 * Maybe create a tag, and return the term_id
265 *
266 * @param string $tag_name
267 */
268 public static function maybe_create_tag($tag_name = '')
269 {
270 $term_id = 0;
271 //restore & in tag post
272 $tag_name = sanitize_text_field(str_replace("simpletagand", "&", $tag_name));
273 $result_term = term_exists($tag_name, 'post_tag', 0);
274 if (empty($result_term)) {
275 $result_term = wp_insert_term(
276 $tag_name,
277 'post_tag'
278 );
279
280 if (!is_wp_error($result_term)) {
281 $term_id = (int) $result_term['term_id'];
282 }
283 } else {
284 $term_id = (int) $result_term['term_id'];
285 }
286
287 wp_send_json_success(['term_id' => $term_id]);
288 }
289
290 /**
291 * Ajax for search posts
292 *
293 * @return void
294 */
295 public static function taxopress_search_posts_ajax()
296 {
297 if (!check_ajax_referer('st-admin-js', 'nonce', false)) {
298 wp_send_json_error(['message' => __('Security check failed.', 'simple-tags')]);
299 }
300
301 if (!current_user_can('simple_tags')) {
302 wp_send_json_error(['message' => __('Permission denied.', 'simple-tags')]);
303 }
304
305 $search = isset($_GET['search']) ? sanitize_text_field(wp_unslash($_GET['search'])) : '';
306 $paged = max(1, intval($_GET['page'] ?? 1));
307 $post_type = 'post';
308
309
310 $query = new WP_Query([
311 'post_type' => $post_type,
312 'post_status' => 'publish',
313 'posts_per_page' => 10,
314 'paged' => $paged,
315 'orderby' => 'date',
316 'order' => 'DESC',
317 'fields' => 'ids'
318 ]);
319
320 $results = [];
321 foreach ($query->posts as $post_id) {
322 $results[] = [
323 'id' => $post_id,
324 'text' => get_the_title($post_id)
325 ];
326 }
327
328 wp_send_json([
329 'results' => $results,
330 'more' => $paged < $query->max_num_pages
331 ]);
332 }
333
334 /**
335 * Test if current URL is not a DEV environnement
336 *
337 * Copy from monsterinsights_is_dev_url(), thanks !
338 *
339 * @param string $url
340 *
341 * @return bool
342 */
343 private static function is_dev_url($url = '')
344 {
345 $is_local_url = false;
346
347 // Trim it up
348 $url = strtolower(trim($url));
349 // Need to get the host...so let's add the scheme so we can use parse_url
350 if (false === strpos($url, 'http://') && false === strpos($url, 'https://')) {
351 $url = 'http://' . $url;
352 }
353
354 $url_parts = wp_parse_url($url);
355 $host = !empty($url_parts['host']) ? $url_parts['host'] : false;
356 if (!empty($url) && !empty($host)) {
357 if (false !== ip2long($host)) {
358 if (!filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
359 $is_local_url = true;
360 }
361 } elseif ('localhost' === $host) {
362 $is_local_url = true;
363 }
364
365 $tlds_to_check = array('.local', ':8888', ':8080', ':8081', '.invalid', '.example', '.test');
366 foreach ($tlds_to_check as $tld) {
367 if (false !== strpos($host, $tld)) {
368 $is_local_url = true;
369 break;
370 }
371 }
372
373 if (substr_count($host, '.') > 1) {
374 $subdomains_to_check = array('dev.', '*.staging.', 'beta.', 'test.');
375 foreach ($subdomains_to_check as $subdomain) {
376 $subdomain = str_replace('.', '(.)', $subdomain);
377 $subdomain = str_replace(array('*', '(.)'), '(.*)', $subdomain);
378 if (preg_match('/^(' . $subdomain . ')/', $host)) {
379 $is_local_url = true;
380 break;
381 }
382 }
383 }
384 }
385
386 return $is_local_url;
387 }
388
389 /**
390 * Init taxonomy class variable, load this action after all actions on init !
391 * Make a public static function for call it from children class...
392 *
393 * @return void
394 * @author WebFactory Ltd
395 */
396 public static function register_taxonomy()
397 {
398 add_action('init', array(__CLASS__, 'init'), 99999999);
399 }
400
401 /**
402 * Put in var class the current taxonomy choose by the user
403 *
404 * @return void
405 * @author WebFactory Ltd
406 */
407 public static function init()
408 {
409 self::$taxo_name = esc_html__('Post tags', 'simple-tags');
410 self::$post_type_name = esc_html__('Posts', 'simple-tags');
411
412 // Custom CPT ?
413 if (isset($_GET['cpt']) && !empty($_GET['cpt']) && post_type_exists(sanitize_text_field(wp_unslash($_GET['cpt'])))) {
414 $cpt = get_post_type_object(sanitize_text_field(wp_unslash($_GET['cpt'])));
415 self::$post_type = $cpt->name;
416 self::$post_type_name = $cpt->labels->name;
417 }
418
419 // Get compatible taxo for current post type
420 $compatible_taxonomies = get_object_taxonomies(self::$post_type);
421
422 // Custom taxo ?
423 if (isset($_GET['taxo']) && !empty($_GET['taxo']) && taxonomy_exists(sanitize_text_field(wp_unslash($_GET['taxo'])))) {
424 $taxo = get_taxonomy(sanitize_text_field(wp_unslash($_GET['taxo'])));
425
426 // Taxo is compatible ?
427 if (in_array($taxo->name, $compatible_taxonomies)) {
428 self::$taxonomy = $taxo->name;
429 self::$taxo_name = $taxo->labels->name;
430 } else {
431 unset($taxo);
432 }
433 }
434
435 // Default taxo from CPT...
436 if (!isset($taxo) && is_array($compatible_taxonomies) && !empty($compatible_taxonomies)) {
437 // Take post_tag before category
438 if (in_array('post_tag', $compatible_taxonomies, true)) {
439 $taxo = get_taxonomy('post_tag');
440 } else {
441 $taxo = get_taxonomy(current($compatible_taxonomies));
442 }
443
444 self::$taxonomy = $taxo->name;
445 self::$taxo_name = $taxo->labels->name;
446
447 // TODO: Redirect for help user that see the URL...
448 } elseif (!isset($taxo)) {
449 // TODO: We can't wp_die on init as it affect all pages
450 //wp_die(esc_html__('This custom post type not have taxonomies.', 'simple-tags'));
451 }
452
453 // Free memory
454 unset($cpt, $taxo);
455 }
456
457 /**
458 * Build HTML form for allow user to change taxonomy for the current page.
459 *
460 * @param string $page_value
461 *
462 * @return void
463 * @author Olatechpro
464 */
465 public static function boxSelectorTaxonomy($page_value = '')
466 {
467 echo '<div class="box-selector-taxonomy">' . PHP_EOL;
468
469 echo '<div class="change-taxo">' . PHP_EOL;
470 echo '<form action="" method="get">' . PHP_EOL;
471 if (!empty($page_value)) {
472 echo '<input type="hidden" name="page" value="' . esc_attr($page_value) . '" />' . PHP_EOL;
473 }
474 $taxonomies = [];
475 echo '<select name="cpt" id="cpt-select" class="st-cpt-select">' . PHP_EOL;
476 foreach (get_post_types(array('show_ui' => true), 'objects') as $post_type) {
477 $taxonomies_children = get_object_taxonomies($post_type->name);
478 if (empty($taxonomies_children)) {
479 continue;
480 }
481 $taxonomies[$post_type->name] = $taxonomies_children;
482 echo '<option ' . selected($post_type->name, self::$post_type, false) . ' value="' . esc_attr($post_type->name) . '">' . esc_html($post_type->labels->name) . '</option>' . PHP_EOL;
483 }
484 echo '</select>' . PHP_EOL;
485
486 echo '<select name="taxo" id="taxonomy-select" class="st-taxonomy-select">' . PHP_EOL;
487 foreach ($taxonomies as $parent_post => $taxonomy) {
488 if (count($taxonomy) > 0) {
489 foreach ($taxonomy as $tax_name) {
490 $taxonomy = get_taxonomy($tax_name);
491 if (false === (bool) $taxonomy->show_ui) {
492 continue;
493 }
494
495 if (self::$post_type == $parent_post) {
496 $class = "";
497 } else {
498 $class = "st-hide-content";
499 }
500
501 echo '<option ' . selected($tax_name, self::$taxonomy, false) . ' value="' . esc_attr($tax_name) . '" data-post="' . esc_attr($parent_post) . '" class="' . esc_attr($class) . '">' . esc_html($taxonomy->labels->name) . '</option>' . PHP_EOL;
502 }
503 }
504 }
505 echo '</select>' . PHP_EOL;
506
507 echo '<input type="submit" class="button" id="submit-change-taxo" value="' . esc_attr__('Change selection', 'simple-tags') . '" />' . PHP_EOL;
508 echo '</form>' . PHP_EOL;
509 echo '</div>' . PHP_EOL;
510 echo '</div>' . PHP_EOL;
511 }
512
513 public static function tabSelectorTaxonomy($tab_slug = '', $page_slug = '')
514 {
515 $current_taxo = isset($_GET["{$tab_slug}_taxo"]) ? sanitize_text_field(wp_unslash($_GET["{$tab_slug}_taxo"])) : get_option("{$tab_slug}_taxo", '');
516 $current_cpt = isset($_GET["{$tab_slug}_cpt"]) ? sanitize_text_field(wp_unslash($_GET["{$tab_slug}_cpt"])) : get_option("{$tab_slug}_cpt", '');
517
518 // Fallbacks if not yet set
519 if (empty($current_cpt)) {
520 foreach (get_post_types(['show_ui' => true], 'objects') as $pt) {
521 if (!empty(get_object_taxonomies($pt->name))) {
522 $current_cpt = $pt->name;
523 break;
524 }
525 }
526 }
527 if (empty($current_taxo) && $current_cpt) {
528 $possible_taxos = get_object_taxonomies($current_cpt);
529 if (!empty($possible_taxos)) {
530 $current_taxo = $possible_taxos[0];
531 }
532 }
533
534 // Save for use elsewhere
535 self::$post_type = $current_cpt;
536 self::$taxonomy = $current_taxo;
537
538 // Update $post_type_name dynamically
539 if ($current_cpt) {
540 $post_type_object = get_post_type_object($current_cpt);
541 if ($post_type_object) {
542 self::$post_type_name = $post_type_object->labels->name;
543 }
544 }
545
546 // Save to DB for persistence
547 update_option("{$tab_slug}_taxo", $current_taxo);
548 update_option("{$tab_slug}_cpt", $current_cpt);
549
550 // Build list of post types and taxonomies (only CPTs with taxonomies)
551 $taxonomies = [];
552 echo '<div class="box-selector-taxonomy tab-taxo-filter tab-taxo-filter-' . esc_attr($tab_slug) . '">' . PHP_EOL;
553 echo '<div class="change-taxo">' . PHP_EOL;
554
555 echo '<form action="' . esc_url(admin_url('admin.php')) . '" method="get">' . PHP_EOL;
556 $page = !empty($page_slug) ? $page_slug : (isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : 'st_manage');
557 echo '<input type="hidden" name="page" value="' . esc_attr($page) . '" />' . PHP_EOL;
558 echo '<input type="hidden" name="page" value="st_manage" />' . PHP_EOL;
559
560 if (!empty($tab_slug)) {
561 echo '<input type="hidden" name="tab" value="' . esc_attr($tab_slug) . '" />' . PHP_EOL;
562 }
563
564 // CPT dropdown
565 echo '<select name="' . esc_attr($tab_slug) . '_cpt" class="st-cpt-select st-cpt-select-' . esc_attr($tab_slug) . '">' . PHP_EOL;
566 foreach (get_post_types(['show_ui' => true], 'objects') as $post_type) {
567 $taxonomies_children = get_object_taxonomies($post_type->name);
568 if (empty($taxonomies_children)) {
569 continue;
570 }
571 $taxonomies[$post_type->name] = $taxonomies_children;
572 echo '<option ' . selected($post_type->name, $current_cpt, false) . ' value="' . esc_attr($post_type->name) . '">' . esc_html($post_type->labels->name) . '</option>' . PHP_EOL;
573 }
574 echo '</select>' . PHP_EOL;
575
576 // Taxonomy dropdown
577 echo '<select name="' . esc_attr($tab_slug) . '_taxo" class="st-taxonomy-select st-taxonomy-select-' . esc_attr($tab_slug) . '">' . PHP_EOL;
578 foreach ($taxonomies as $parent_post => $taxonomy_list) {
579 foreach ($taxonomy_list as $tax_name) {
580 $taxonomy = get_taxonomy($tax_name);
581 if (false === (bool) $taxonomy->show_ui) {
582 continue;
583 }
584 $class = ($parent_post === $current_cpt) ? '' : 'st-hide-content';
585
586 echo '<option ' . selected($tax_name, $current_taxo, false) .
587 ' value="' . esc_attr($tax_name) . '"' .
588 ' data-post="' . esc_attr($parent_post) . '"' .
589 ' class="' . esc_attr($class) . '">' .
590 esc_html($taxonomy->labels->name) .
591 '</option>' . PHP_EOL;
592 }
593 }
594 echo '</select>' . PHP_EOL;
595
596 echo '<input type="submit" class="button" value="' . esc_attr__('Change selection', 'simple-tags') . '" />' . PHP_EOL;
597 echo '</form>' . PHP_EOL;
598 echo '</div>' . PHP_EOL;
599 echo '</div>' . PHP_EOL;
600 }
601
602 public function maybe_enqueue_frontend_assets_in_admin()
603 {
604
605 $screen = get_current_screen();
606 if (!$screen) {
607 return;
608 }
609
610 if (strpos($screen->id, 'taxopress_page_') === false) {
611 return;
612 }
613
614 $is_edit_mode = isset($_GET['action']) && in_array($_GET['action'], ['edit'], true);
615 if (!$is_edit_mode) {
616 return;
617 }
618
619 $current_page = isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : '';
620
621 // List of pages that need preview functionality
622 $preview_pages = [
623 'st_terms_display',
624 'st_related_posts',
625 'st_post_tags',
626 ];
627
628 if (!in_array($current_page, $preview_pages, true)) {
629 return;
630 }
631
632 if ((int) SimpleTags_Plugin::get_option_value('disable_admin_frontend_scripts') === 1) {
633 return;
634 }
635
636 if (! apply_filters('taxopress_load_admin_frontend_scripts', true)) {
637 return;
638 }
639
640 // Register and enqueue assets
641 wp_register_script('taxopress-frontend-js', STAGS_URL . '/assets/frontend/js/frontend.js', array('jquery'), STAGS_VERSION);
642 wp_register_style('taxopress-frontend-css', STAGS_URL . '/assets/frontend/css/frontend.css', array(), STAGS_VERSION, 'all');
643
644 // Enqueue the assets
645 wp_enqueue_script('taxopress-frontend-js');
646 wp_enqueue_style('taxopress-frontend-css');
647 }
648 /**
649 * Init somes JS and CSS need for PublishPress Taxonomies.
650 *
651 * @return void
652 * @author WebFactory Ltd
653 */
654 public static function admin_enqueue_scripts()
655 {
656 global $pagenow;
657
658 $select_2_page = false;
659 if ((isset($_GET['page']) && in_array($_GET['page'], ['st_posts', 'st_terms', 'st_autolinks', 'st_autoterms', 'st_autoterms_schedule', 'st_terms_display', 'st_related_posts', 'st_post_tags', 'st_mass_terms'])) || in_array($pagenow, ['post.php', 'edit.php', 'post-new.php'])) {
660 $select_2_page = true;
661 }
662
663 do_action('taxopress_admin_class_before_assets_register');
664
665 //color picker style
666 wp_enqueue_style('wp-color-picker');
667
668 // Helper PublishPress Taxonomies
669 wp_register_script('st-helper-add-tags', STAGS_URL . '/assets/js/helper-add-tags.js', array('jquery'), STAGS_VERSION);
670 wp_localize_script('st-helper-add-tags', 'stHelperAddTagsL10n', [
671 'nonce' => wp_create_nonce('st-admin-js'),
672 ]);
673 wp_register_script('st-helper-options', STAGS_URL . '/assets/js/helper-options.js', array('jquery', 'wp-color-picker'), STAGS_VERSION);
674
675 // Register CSS
676 wp_register_style('st-admin', STAGS_URL . '/assets/css/admin.css', array(), STAGS_VERSION, 'all');
677 wp_register_style('st-admin-global', STAGS_URL . '/assets/css/admin-global.css', array(), STAGS_VERSION, 'all');
678
679 // Register tooltip
680 wp_register_script(
681 'taxopress-admin-tooltip',
682 STAGS_URL . '/assets/lib/tooltip/js/tooltip.min.js',
683 ['jquery'],
684 STAGS_VERSION
685 );
686
687 wp_register_style(
688 'taxopress-admin-tooltip',
689 STAGS_URL . '/assets/lib/tooltip/css/tooltip.min.css',
690 [],
691 STAGS_VERSION
692 );
693
694 //enqueue tooltip
695 wp_enqueue_script('taxopress-admin-tooltip');
696 wp_enqueue_style('taxopress-admin-tooltip');
697
698 // Register Select 2
699 wp_register_script(
700 'taxopress-admin-select2',
701 STAGS_URL . '/assets/lib/select2/js/select2.full.min.js',
702 ['jquery'],
703 STAGS_VERSION
704 );
705
706 wp_register_style(
707 'taxopress-admin-select2',
708 STAGS_URL . '/assets/lib/select2/css/select2.min.css',
709 [],
710 STAGS_VERSION
711 );
712
713 if ($select_2_page) {
714 wp_enqueue_script('taxopress-admin-select2');
715 wp_enqueue_style('taxopress-admin-select2');
716 }
717
718 //Register and enqueue admin js
719 $script_dependencies = ['jquery'];
720 if ($select_2_page) {
721 $script_dependencies[] = 'taxopress-admin-select2';
722 $script_dependencies[] = 'wp-util';
723 }
724
725 $taxopress_pages = taxopress_admin_pages();
726
727 if (isset($_GET['page']) && in_array($_GET['page'], $taxopress_pages)) {
728 wp_enqueue_media();
729 }
730
731 wp_register_script('st-admin-js', STAGS_URL . '/assets/js/admin.js', $script_dependencies, STAGS_VERSION);
732 wp_enqueue_script('st-admin-js');
733 //localize script
734 wp_localize_script('st-admin-js', 'st_admin_localize', [
735 'ajaxurl' => admin_url('admin-ajax.php'),
736 'select_valid' => esc_html__('Please select a valid', 'simple-tags'),
737 'check_nonce' => wp_create_nonce('st-admin-js'),
738 'select_default_label' => esc_html__('Select Default Post Thumb', 'simple-tags'),
739 'use_media_label' => esc_html__('Use this media', 'simple-tags'),
740 'existing_content_admin_label' => esc_html__('Edit the current setting.', 'simple-tags'),
741 'request_error' => esc_html__('The request could not be completed. Please try again.', 'simple-tags'),
742 'autoterm_admin_url' => admin_url('admin.php?page=st_autoterms'),
743 'no_terms_message' => esc_html__('No terms will be deleted', 'simple-tags'),
744 'terms_count_message' => esc_html__(' terms will be deleted.', 'simple-tags'),
745 'checking_terms_message' => esc_html__('Checking terms...', 'simple-tags'),
746 'terms_error' => esc_html__('An error occurred while checking terms.', 'simple-tags'),
747 'post_required' => esc_html__('Select a post to see a preview.', 'simple-tags'),
748 'save_settings' => esc_html__('Auto Term ID missing. Kindly save the auto term before using this feature.', 'simple-tags'),
749 'delete_label' => esc_html__('Delete', 'simple-tags'),
750 'ai_nonce' => wp_create_nonce('taxopress-ai-ajax-nonce'),
751 'post_title' => '%post_title%',
752 'post_permalink' => '%post_permalink%',
753 'post_date' => '%post_date%',
754 'post_thumb_url' => '%post_thumb_url%',
755 'post_category' => '%post_category%',
756 'post_size' => '%post_size%',
757 'post_color' => '%post_color%',
758 'merge_cancelled' => esc_html__('Merge has been cancelled.', 'simple-tags'),
759 'cancel_label' => esc_html__('Cancel', 'simple-tags'),
760 'paused_label' => esc_html__('Pause.', 'simple-tags'),
761 'continue_label' => esc_html__('Continue', 'simple-tags'),
762 'merge_in_progress' => esc_html__('Merging terms. Please wait...', 'simple-tags'),
763 'merge_attached_data' => esc_html__('Merging %1$s terms attached to %2$s posts. Please wait...', 'simple-tags'),
764 'merge_large_data' => esc_html__('Large dataset detected, terms will be merged in batches of 20!', 'simple-tags'),
765 'merge_none_merged' => esc_html__('No terms were merged.', 'simple-tags'),
766 'batch_merge_progress' => esc_html__('Batch %1$s of %2$s merged.', 'simple-tags'),
767 'terms_merged_text' => esc_html__('terms merged', 'simple-tags'),
768 'posts_updated_text' => esc_html__('posts updated', 'simple-tags'),
769 'merge_success_update' => esc_html__('All terms merged into "%s"', 'simple-tags'),
770 'merge_partial_update' => esc_html__('Terms merged into "%s"', 'simple-tags'),
771 'merge_partial_missing_terms' => esc_html__('Some batches were skipped because they contained non-existent terms.', 'simple-tags'),
772 'batch_missing_terms' => esc_html__('Batch %1$s failed because it contained non-existent terms: %2$s', 'simple-tags'),
773 'ajax_merge_terms_error' => esc_html__('AJAX error on batch', 'simple-tags'),
774 'batch_error_text' => esc_html__('Error on batch %1$s:', 'simple-tags'),
775 'enable_merge_terms_slug' => SimpleTags_Plugin::get_option_value('enable_merge_terms_slug'),
776 'enable_add_terms_slug' => SimpleTags_Plugin::get_option_value('enable_add_terms_slug'),
777 'enable_remove_terms_slug' => SimpleTags_Plugin::get_option_value('enable_remove_terms_slug'),
778 'enable_rename_terms_slug' => SimpleTags_Plugin::get_option_value('enable_rename_terms_slug'),
779 'enable_mass_edit_terms_slug' => SimpleTags_Plugin::get_option_value('enable_mass-edit_terms_slug'),
780 'select_post_label' => esc_html__('Search Posts...', 'simple-tags'),
781 'loading' => esc_html__('Loading...', 'simple-tags'),
782 'preview_error' => esc_html__('Error loading preview', 'simple-tags'),
783 'enable_ibm_watson_ai_source' => SimpleTags_Plugin::get_option_value('enable_ibm_watson_ai_source'),
784 'enable_dandelion_ai_source' => SimpleTags_Plugin::get_option_value('enable_dandelion_ai_source'),
785 'enable_lseg_ai_source' => SimpleTags_Plugin::get_option_value('enable_lseg_ai_source'),
786 'plugin_url' => STAGS_URL,
787 'using_default_text' => __('Using default PublishPress Taxonomies image', 'simple-tags'),
788 'select_image_label' => esc_html__('Select Media', 'simple-tags'),
789 'change_image_label' => esc_html__('Change Media', 'simple-tags'),
790 'use_default_label' => esc_html__('Use Default', 'simple-tags'),
791 'see_more_suggestions' => esc_html__('See More', 'simple-tags'),
792 'see_less_suggestions' => esc_html__('See Less', 'simple-tags'),
793 'apply_selected' => esc_html__('Apply Selected', 'simple-tags'),
794 'close_suggestions' => esc_html__('Close', 'simple-tags'),
795 'select_suggestion_alert' => esc_html__('Please select at least one suggestion to apply.', 'simple-tags'),
796 'multiple_merge_warning' => esc_html__('You have selected multiple merge suggestions. All selected terms will be merged into a single new term. Do you want to continue?', 'simple-tags'),
797 'no_merge_suggestions' => esc_html__('No merge suggestions found for this taxonomy.', 'simple-tags'),
798 'suggested_terms_title' => esc_html__('Suggested Terms to Merge:', 'simple-tags'),
799 'duplicates_text' => esc_html__('duplicates', 'simple-tags'),
800 'reason_text' => esc_html__('Reason:', 'simple-tags'),
801 'select_all_label' => esc_html__('Select All', 'simple-tags'),
802 'deselect_all_label' => esc_html__('Deselect All', 'simple-tags'),
803 'terms_to_merge_text' => esc_html__('Terms to Merge', 'simple-tags'),
804 'new_term_text' => esc_html__('New Term', 'simple-tags'),
805 'reasons_text' => esc_html__('Reasons', 'simple-tags'),
806 ]);
807
808
809 //Register remodal assets
810 wp_register_script('st-remodal-js', STAGS_URL . '/assets/js/remodal.min.js', array('jquery'), STAGS_VERSION);
811 wp_register_style('st-remodal-css', STAGS_URL . '/assets/css/remodal.css', array(), STAGS_VERSION, 'all');
812 wp_register_style('st-remodal-default-theme-css', STAGS_URL . '/assets/css/remodal-default-theme.css', array(), STAGS_VERSION, 'all');
813
814 // Register location
815 $wp_post_pages = array('post.php', 'post-new.php');
816 $wp_page_pages = array('page.php', 'page-new.php');
817
818 wp_enqueue_style('st-admin-global');
819
820 // Common Helper for Post, Page and Plugin Page
821 if (
822 in_array($pagenow, $wp_post_pages) ||
823 (in_array($pagenow, $wp_page_pages) && is_page_have_tags()) ||
824 (isset($_GET['page']) && in_array($_GET['page'], $taxopress_pages))
825 ) {
826 wp_enqueue_script('st-remodal-js');
827 wp_enqueue_style('st-remodal-css');
828 wp_enqueue_style('st-remodal-default-theme-css');
829 wp_enqueue_style('st-admin');
830
831 do_action('taxopress_admin_class_after_styles_enqueue');
832 }
833
834 // add jQuery tabs for options page. Use jQuery UI Tabs from WP
835 if (isset($_GET['page']) && in_array($_GET['page'], array('st_options', 'st_terms_display', 'st_post_tags', 'st_related_posts',))) {
836 wp_enqueue_script('jquery-ui-tabs');
837 wp_enqueue_script('st-helper-options');
838 }
839
840 do_action('taxopress_admin_class_after_assets_enqueue');
841 }
842
843 /**
844 * Add settings page on WordPress admin menu
845 *
846 * @return void
847 * @author WebFactory Ltd
848 */
849 public static function admin_menu()
850 {
851 self::$admin_url = admin_url('admin.php?page=' . self::MENU_SLUG);
852
853 add_menu_page(
854 __('PublishPress Taxonomies: Options', 'simple-tags'),
855 __('Taxonomies', 'simple-tags'),
856 'admin_simple_tags',
857 self::MENU_SLUG,
858 array(
859 __CLASS__,
860 'page_options',
861 ),
862 'dashicons-tag',
863 69
864 );
865 add_submenu_page(
866 self::MENU_SLUG,
867 __('PublishPress Taxonomies: Options', 'simple-tags'),
868 __('Settings', 'simple-tags'),
869 'admin_simple_tags',
870 self::MENU_SLUG,
871 array(
872 __CLASS__,
873 'page_options',
874 )
875 );
876 }
877
878 /**
879 * Build HTML for page options, manage also save/reset settings
880 *
881 * @return void
882 * @author WebFactory Ltd
883 */
884 public static function page_options()
885 {
886 // Get options
887 $options = (array) SimpleTags_Plugin::get_option();
888
889 if (current_user_can('admin_simple_tags')) {
890 // Update or reset options
891 if (isset($_POST['updateoptions'])) {
892 $dashboard_options = taxopress_dashboard_options();
893 $dashboard_option_keys = array_column($dashboard_options, 'option_key');
894
895 check_admin_referer('updateresetoptions-simpletags');
896
897 $sanitized_options = [];
898
899 $is_fast_update_submission = isset($_GET['page']) && $_GET['page'] === 'st_taxopress_ai';
900
901 // This settings has been migrated to fast update screen so only update from there
902 if ($is_fast_update_submission) {
903 // add PublishPress Taxonomies ai post type and taxonomies options so we can have all post types. TODO: This need to be a filter
904 foreach (get_post_types(['public' => true], 'names') as $post_type => $post_type_object) {
905 if ($post_type == 'post') {
906 $opt_default_value = 'post_tag';
907 } else {
908 $opt_default_value = 0;
909 }
910 $options['taxopress_ai_' . $post_type . '_metabox_default_taxonomy'] = $opt_default_value;
911 $options['taxopress_ai_' . $post_type . '_metabox_display_option'] = 'default';
912 $options['taxopress_ai_' . $post_type . '_support_private_taxonomy'] = 0;
913
914 $options['taxopress_ai_' . $post_type . '_metabox_orderby'] = 'count';
915 $options['taxopress_ai_' . $post_type . '_metabox_order'] = 'desc';
916 $options['taxopress_ai_' . $post_type . '_metabox_maximum_terms'] = 45;
917 $options['taxopress_ai_' . $post_type . '_metabox_show_post_count'] = 0;
918 $options['taxopress_ai_' . $post_type . '_metabox_show_term_slug'] = 0;
919
920 $options['taxopress_ai_' . $post_type . '_minimum_term_length'] = 2;
921 $options['taxopress_ai_' . $post_type . '_maximum_term_length'] = 40;
922
923 $options['taxopress_ai_' . $post_type . '_exclusions'] = '';
924 $options['enable_taxopress_ai_' . $post_type . '_metabox'] = $opt_default_value;
925 $options['taxopress_ai_' . $post_type . '_metabox_filters'] = 1;
926 foreach (['post_terms', 'existing_terms', 'suggest_local_terms', 'create_terms'] as $taxopress_ai_tab) {
927 $options['enable_taxopress_ai_' . $post_type . '_' . $taxopress_ai_tab . '_tab'] = $opt_default_value;
928 }
929 }
930
931 // add metabox post type and taxonomies options so we can have all post types. TODO: This need to be a filter
932 foreach (taxopress_get_all_wp_roles() as $role_name => $role_info) {
933 if (in_array($role_name, ['administrator', 'editor', 'author', 'contributor'])) {
934 $enable_acess_default_value = 1;
935 } else {
936 $enable_acess_default_value = 0;
937 }
938 $options['enable_' . $role_name . '_metabox'] = $enable_acess_default_value;
939 $options['enable_restrict' . $role_name . '_metabox'] = $enable_acess_default_value;
940
941 // ONLY admin + editor default to can edit
942 if (!isset($options['enable_edit_' . $role_name . '_metabox'])) {
943 $options['enable_edit_' . $role_name . '_metabox'] = in_array($role_name, ['administrator', 'editor']) ? 1 : 0;
944 }
945
946 $options['enable_metabox_' . $role_name . ''] = [];
947 $options['remove_taxonomy_metabox_' . $role_name . ''] = [];
948 }
949 }
950
951 foreach ($options as $key => $value) {
952 // If this is NOT a Fast Update submission, preserve metabox/metabox-access keys
953 if (!$is_fast_update_submission && preg_match('/^(enable_taxopress_ai_|taxopress_ai_|enable_.*_metabox|enable_restrict.*_metabox|enable_edit_.*_metabox|enable_metabox_|remove_taxonomy_metabox_)/', $key)) {
954 // Keep existing value as-is
955 if (!is_array($value)) {
956 $sanitized_options[$key] = taxopress_sanitize_text_field($value);
957 } else {
958 $sanitized_options[$key] = map_deep($value, 'sanitize_text_field');
959 }
960 continue;
961 }
962
963 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
964 $post_value = isset($_POST[$key]) ? wp_unslash($_POST[$key]) : '';
965
966 if (empty($post_value) && in_array($key, $dashboard_option_keys)) {
967 $post_value = SimpleTags_Plugin::get_option_value($key);
968 }
969
970 if (!is_array($post_value)) {
971 $sanitized_options[$key] = taxopress_sanitize_text_field($post_value);
972 } else {
973 $sanitized_options[$key] = map_deep($post_value, 'sanitize_text_field');
974 }
975 }
976 $options = $sanitized_options;
977
978 SimpleTags_Plugin::set_option($options);
979
980 do_action('simpletags_settings_save_general_end');
981 do_action('taxopress_settings_saved');
982
983 add_settings_error(__CLASS__, __CLASS__, esc_html__('Options saved', 'simple-tags'), 'updated taxopress-notice');
984 } elseif (isset($_POST['reset_options'])) {
985 check_admin_referer('updateresetoptions-simpletags');
986
987 SimpleTags_Plugin::set_default_option();
988
989 add_settings_error(__CLASS__, __CLASS__, esc_html__('PublishPress Taxonomies options resetted to default options!', 'simple-tags'), 'updated taxopress-notice');
990 } else {
991 //add_settings_error(__CLASS__, __CLASS__, esc_html__('Settings updated', 'simple-tags'), 'updated');
992 }
993 }
994
995 settings_errors(__CLASS__);
996 include STAGS_DIR . '/views/admin/page-settings.php';
997 }
998
999 /**
1000 * Get terms for a post, format terms for input and autocomplete usage
1001 *
1002 * @param string $taxonomy
1003 * @param integer $post_id
1004 *
1005 * @return string
1006 * @author WebFactory Ltd
1007 */
1008 public static function getTermsToEdit($taxonomy = 'post_tag', $post_id = 0)
1009 {
1010 $post_id = (int) $post_id;
1011 if (!$post_id) {
1012 return '';
1013 }
1014
1015 $is_mass_edit_page = isset($_GET['page']) && $_GET['page'] === 'st_mass_terms';
1016 $show_slug = SimpleTags_Plugin::get_option_value('enable_mass-edit_terms_slug');
1017
1018 if ($is_mass_edit_page) {
1019 $term_objects = wp_get_post_terms($post_id, $taxonomy);
1020 if (empty($term_objects) || is_wp_error($term_objects)) {
1021 return '';
1022 }
1023
1024 $terms = array();
1025 foreach ($term_objects as $term) {
1026 if ($show_slug) {
1027 if (!empty($term->slug)) {
1028 $terms[] = $term->name . ' (' . $term->slug . ')';
1029 } else {
1030 $terms[] = $term->name;
1031 }
1032 } else {
1033 $terms[] = $term->name;
1034 }
1035 }
1036
1037 $terms = join(', ', $terms);
1038 } else {
1039 $terms = wp_get_post_terms($post_id, $taxonomy, array('fields' => 'names'));
1040 if (empty($terms) || is_wp_error($terms)) {
1041 return '';
1042 }
1043
1044 $terms = array_unique($terms);
1045 $terms = join(', ', $terms);
1046 }
1047
1048 $terms = esc_attr($terms);
1049 $terms = apply_filters('tags_to_edit', $terms);
1050
1051 return $terms;
1052 }
1053
1054 /**
1055 * Default content for meta box of PublishPress Taxonomies
1056 *
1057 * @return string
1058 * @author WebFactory Ltd
1059 */
1060 public static function getDefaultContentBox()
1061 {
1062 if ((int) wp_count_terms(array('taxonomy' => 'post_tag', 'hide_empty' => false)) == 0) { // TODO: Custom taxonomy
1063 return esc_html__('This feature requires at least 1 tag to work. Begin by adding tags!', 'simple-tags');
1064 } else {
1065 return esc_html__('This feature works only with activated JavaScript. Activate it in your Web browser so you can!', 'simple-tags');
1066 }
1067 }
1068
1069 /**
1070 * A short public static function for display the same copyright on all admin pages
1071 *
1072 * @return void
1073 * @author WebFactory Ltd
1074 */
1075 public static function printAdminFooter()
1076 {
1077 /* ?>
1078 <p class="footer_st"><?php printf( __( 'Thanks for using PublishPress Taxonomies | <a href="https://taxopress.com/">TaxoPress.com</a> | Version %s', 'simple-tags' ), STAGS_VERSION ); ?></p>
1079 <?php */
1080 }
1081
1082 /**
1083 * Mark PublishPress Taxonomies screens so the expanded footer uses normal flow.
1084 *
1085 * @param string $classes Existing admin body classes.
1086 * @return string
1087 */
1088 public static function taxopress_admin_body_class($classes)
1089 {
1090 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Used only to identify the current admin page.
1091 $current_page = isset($_GET['page']) && is_string($_GET['page']) ? sanitize_key(wp_unslash($_GET['page'])) : '';
1092
1093 if (in_array($current_page, taxopress_admin_pages(), true)) {
1094 $classes .= ' taxopress-admin-page';
1095 }
1096
1097 return $classes;
1098 }
1099
1100 /**
1101 * A short public static function for display the same copyright on all PublishPress Taxonomies admin pages
1102 *
1103 * @return void
1104 * @author Olatechpro
1105 */
1106 public static function taxopress_admin_footer()
1107 {
1108 $taxopress_pages = taxopress_admin_pages();
1109 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Used only to determine whether to render the footer.
1110 $current_page = isset($_GET['page']) && is_string($_GET['page']) ? sanitize_key(wp_unslash($_GET['page'])) : '';
1111
1112 if (! in_array($current_page, $taxopress_pages, true)) {
1113 return;
1114 }
1115
1116 $rating_stars = str_repeat('<span class="dashicons dashicons-star-filled"></span>', 5);
1117 ?>
1118 <div class="pressshack-admin-wrapper taxopress-admin-footer">
1119 <footer>
1120 <div class="taxopress-rating">
1121 <a href="https://wordpress.org/support/plugin/simple-tags/reviews/#new-post" target="_blank" rel="noopener noreferrer">
1122 <?php
1123 printf(
1124 /* translators: %1$s: plugin name, %2$s: five-star rating icons. */
1125 esc_html__('If you like %1$s please leave us a %2$s rating. Thank you!', 'simple-tags'),
1126 '<strong>' . esc_html__('PublishPress Taxonomies', 'simple-tags') . '</strong>',
1127 $rating_stars // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Trusted dashicon markup generated above.
1128 );
1129 ?>
1130 </a>
1131 </div>
1132 <hr>
1133 <nav aria-label="<?php echo esc_attr__('PublishPress Taxonomies resources', 'simple-tags'); ?>">
1134 <ul>
1135 <li><a href="https://publishpress.com/taxonomies/" target="_blank" rel="noopener noreferrer"><?php esc_html_e('About', 'simple-tags'); ?></a></li>
1136 <li><a href="https://publishpress.com/knowledge-base/start-publishpress-taxonomies/" target="_blank" rel="noopener noreferrer"><?php esc_html_e('Documentation', 'simple-tags'); ?></a></li>
1137 <li><a href="https://publishpress.com/publishpress-support/" target="_blank" rel="noopener noreferrer"><?php esc_html_e('Contact', 'simple-tags'); ?></a></li>
1138 </ul>
1139 </nav>
1140 <div class="taxopress-publishpress-logo">
1141 <a href="https://publishpress.com/" target="_blank" rel="noopener noreferrer">
1142 <img src="<?php echo esc_url(STAGS_URL . '/assets/images/publishpress-logo.png'); ?>" alt="<?php echo esc_attr__('PublishPress', 'simple-tags'); ?>">
1143 </a>
1144 </div>
1145 </footer>
1146 </div>
1147 <?php
1148 }
1149
1150 /**
1151 * Ouput formatted options
1152 *
1153 * @param array $option_data
1154 *
1155 * @return string
1156 * @author WebFactory Ltd
1157 */
1158 public static function print_options($option_data)
1159 {
1160 // Get options
1161 $option_actual = SimpleTags_Plugin::get_option();
1162
1163 // Generate output
1164 $output = '';
1165 foreach ($option_data as $section => $options) {
1166 $colspan = count($options) > 1 ? 'colspan="2"' : '';
1167
1168 if ($section === 'legacy') {
1169 $table_sub_tab = '<div class="st-legacy-subtab">
1170 <span class="active" data-content=".legacy-tag-cloud-content">' . esc_html__("Tag Cloud", "simple-tags") . '</span> |
1171 <span data-content=".legacy-post-tags-content">' . esc_html__("Tags for Current Post", "simple-tags") . '</span> |
1172 <span data-content=".legacy-related-posts-content">' . esc_html__("Related Posts", "simple-tags") . '</span> |
1173 <span data-content=".legacy-auto-link-content">' . esc_html__("Auto Links", "simple-tags") . '</span>
1174 </div>' . PHP_EOL;
1175 } elseif ($section === 'taxopress-ai') {
1176 $table_sub_tab_lists = [];
1177 $pt_index = 0;
1178 foreach (TaxoPressAiUtilities::get_post_types_options() as $post_type => $post_type_object) {
1179 if (!in_array($post_type, ['attachment'])) {
1180 $active_pt = ($pt_index === 0) ? 'active' : '';
1181 $table_sub_tab_lists[] = '<span class="' . $active_pt . '" data-content=".taxopress-ai-' . $post_type . '-content">' . esc_html($post_type_object->labels->name) . '</span>';
1182 $pt_index++;
1183 }
1184 }
1185 $table_sub_tab = '<div class="st-taxopress-ai-subtab">' . join(' | ', $table_sub_tab_lists) . '</div>' . PHP_EOL;
1186 } elseif ($section === 'metabox') {
1187 $table_sub_tab_lists = [];
1188 $pt_index = 0;
1189 foreach (taxopress_get_all_wp_roles() as $role_name => $role_info) {
1190 $active_pt = ($pt_index === 0) ? 'active' : '';
1191 $table_sub_tab_lists[] = '<span class="' . $active_pt . '" data-content=".metabox-' . $role_name . '-content">' . esc_html(translate_user_role($role_info['name'])) . '</span>';
1192 $pt_index++;
1193 }
1194 $table_sub_tab = '<div class="st-metabox-subtab">' . join(' | ', $table_sub_tab_lists) . '</div>' . PHP_EOL;
1195 } else {
1196 $table_sub_tab = '';
1197 }
1198
1199 $output .= '<div class="group" id="' . sanitize_title($section) . '">' . PHP_EOL;
1200 $output .= $table_sub_tab;
1201 $output .= '<fieldset class="options">' . PHP_EOL;
1202 $output .= '<legend>' . self::getNiceTitleOptions($section) . '</legend>' . PHP_EOL;
1203 $output .= '<table class="form-table">' . PHP_EOL;
1204 foreach ((array) $options as $option) {
1205 $class = '';
1206 if (in_array($section, ['legacy', 'taxopress-ai', 'metabox'])) {
1207 $class = $option[5];
1208 }
1209
1210 // Helper
1211 if ($option[2] == 'helper') {
1212 $output .= '<tr style="vertical-align: middle;" class="' . $class . '"><td class="helper stpexplan" ' . $colspan . '>' . stripslashes($option[4]) . '</td></tr>' . PHP_EOL;
1213 continue;
1214 }
1215
1216 // Fix notices
1217 if (!isset($option_actual[$option[0]])) {
1218 $option_actual[$option[0]] = '';
1219 }
1220
1221 // Add our custom core_terms_promo type
1222 if ($option[2] == 'core_terms_promo') {
1223 if (isset($option[4]) && !empty($option[4])) {
1224 $output .= '<tr style="vertical-align: middle;" class="' . $class . '"><td class="helper" ' . $colspan . '>' . apply_filters('taxopress_admin_manage_' . $option[0], $option[4]) . '</td></tr>' . PHP_EOL;
1225 }
1226 continue;
1227 }
1228
1229 $input_type = '';
1230 $desc_html_tag = 'div';
1231 switch ($option[2]) {
1232 case 'radio':
1233 $input_type = array();
1234 foreach ($option[3] as $value => $text) {
1235 $input_type[] = '<label><input type="radio" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr($value) . '" ' . checked($value, $option_actual[$option[0]], false) . ' /> ' . $text . '</label>' . PHP_EOL;
1236 }
1237 $input_type = implode('<br />', $input_type);
1238 break;
1239
1240 case 'checkbox':
1241 $desc_html_tag = 'span';
1242 $input_type = '<input type="checkbox" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr($option[3]) . '" ' . (($option_actual[$option[0]]) ? 'checked="checked"' : '') . ' />' . PHP_EOL;
1243 break;
1244
1245 case 'multiselect':
1246 $desc_html_tag = 'div';
1247 $input_type = array();
1248 foreach ($option[3] as $field_name => $text) {
1249 $selected_option = (is_array($option_actual[$option[0]]) && in_array($field_name, $option_actual[$option[0]])) ? true : false;
1250 $input_type[] = '<label><input type="checkbox" id="' . $option[0] . '-' . $field_name . '" name="' . $option[0] . '[]" value="' . $field_name . '" ' . checked($selected_option, true, false) . ' /> ' . $text . '</label> <br />' . PHP_EOL;
1251 }
1252 $input_type = implode('<br />', $input_type);
1253 break;
1254
1255 case 'sub_multiple_checkbox':
1256 $desc_html_tag = 'div';
1257 $input_type = array();
1258 foreach ($option[3] as $field_name => $field_option) {
1259 $checked_option = !empty($option_actual[$field_name]) ? (int) $option_actual[$field_name] : 0;
1260 $selected_option = ($checked_option > 0) ? true : false;
1261 $field_description = !empty($field_option['description']) ? '<br /><span class="description stpexplan">' . $field_option['description'] . '</span>' : '';
1262 $input_type[] = '<label><input type="checkbox" id="' . $option[0] . '" name="' . $field_name . '" value="1" ' . checked($selected_option, true, false) . ' /> ' . $field_option['label'] . '</label> ' . $field_description . '<br />' . PHP_EOL;
1263 }
1264 $input_type = implode('<br />', $input_type);
1265 break;
1266
1267 case 'dropdown':// legacy
1268 $selopts = explode('/', $option[3]);
1269 $seldata = '';
1270 foreach ((array) $selopts as $sel) {
1271 $seldata .= '<option value="' . esc_attr($sel) . '" ' . ((isset($option_actual[$option[0]]) && $option_actual[$option[0]] == $sel) ? 'selected="selected"' : '') . ' >' . ucfirst($sel) . '</option>' . PHP_EOL;
1272 }
1273 $input_type = '<select id="' . $option[0] . '" name="' . $option[0] . '">' . $seldata . '</select>' . PHP_EOL;
1274 break;
1275
1276
1277 case 'select':
1278 $selopts = $option[3];
1279 $seldata = '';
1280 foreach ((array) $selopts as $sel_key => $sel_label) {
1281 $seldata .= '<option value="' . esc_attr($sel_key) . '" ' . ((isset($option_actual[$option[0]]) && $option_actual[$option[0]] == $sel_key) ? 'selected="selected"' : '') . ' >' . ucfirst($sel_label) . '</option>' . PHP_EOL;
1282 }
1283 $input_type = '<select id="' . $option[0] . '" name="' . $option[0] . '">' . $seldata . '</select>' . PHP_EOL;
1284 break;
1285
1286 case 'select_with_icon':
1287 $selopts = $option[3];
1288 $seldata = '';
1289 foreach ((array) $selopts as $sel_key => $sel_label) {
1290 $seldata .= '<option value="' . esc_attr($sel_key) . '" ' . ((isset($option_actual[$option[0]]) && $option_actual[$option[0]] == $sel_key) ? 'selected="selected"' : '') . ' >' . ucfirst($sel_label) . '</option>' . PHP_EOL;
1291 }
1292
1293 $icon_class = isset($option[6]['icon']) ? $option[6]['icon'] : 'dashicons-lock';
1294 $modal_content = isset($option[6]['modal']) ? $option[6]['modal'] : '';
1295 $disabled = !empty($option[8]) && isset($option[8]['disabled']) ? 'disabled="disabled"' : '';
1296 $class_attr = isset($option[5]) ? esc_attr($option[5]) : '';
1297 $icon_wrapper_class = isset($option[6]['icon_wrapper_class']) ? esc_attr($option[6]['icon_wrapper_class']) : 'taxopress-select-icon';
1298 $modal_wrapper_class = isset($option[6]['modal_wrapper_class']) ? esc_attr($option[6]['modal_wrapper_class']) : 'taxopress-select-icon-modal';
1299
1300 $input_type = '<div class="' . $class_attr . '">
1301 <select id="' . $option[0] . '" name="' . $option[0] . '" ' . $disabled . '>' . $seldata . '</select>
1302 <span class="' . $icon_wrapper_class . ' dashicons ' . esc_attr($icon_class) . '">
1303 <div class="' . $modal_wrapper_class . '">' . $modal_content . '</div>
1304 </span>
1305 </div>' . PHP_EOL;
1306 break;
1307
1308 case 'multiselect_with_desc_top':
1309 $desc_html_tag = 'div';
1310 $input_type_array = array();
1311 $prefix = !empty($field_description) ? '<' . $desc_html_tag . ' class="stpexplan">' . $field_description . '</' . $desc_html_tag . '>' : '';
1312 foreach ($field_options as $option_key => $option_label) {
1313 $field_value = isset($option_actual[$field_id]) ? $option_actual[$field_id] : array();
1314 $selected_option = (is_array($field_value) && in_array($option_key, $field_value)) ? true : false;
1315 $input_type_array[] = '<label><input type="checkbox" id="' . esc_attr($field_id . '-' . $option_key) . '" name="' . esc_attr($field_id) . '[]" value="' . esc_attr($option_key) . '" ' . checked($selected_option, true, false) . ' /> ' . esc_html($option_label) . '</label><br />';
1316 }
1317 $input_type = $prefix . implode('', $input_type_array);
1318 $field_description = '';
1319 break;
1320
1321 case 'text-color':
1322 $input_type = '<input type="text" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr($option_actual[$option[0]]) . '" class="text-color ' . $option[3] . '" />' . PHP_EOL;
1323 break;
1324
1325 case 'text':
1326 $input_type = '<input type="text" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr($option_actual[$option[0]]) . '" class="' . $option[3] . '" />' . PHP_EOL;
1327 break;
1328
1329 case 'licence_field':
1330 $input_type = '<input type="text" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr($option[3]) . '" class="' . $option[5] . '" />' . PHP_EOL;
1331 break;
1332
1333 case 'number':
1334 $min_attr = isset($option[6]) ? ' min="' . esc_attr($option[6]) . '"' : '';
1335 $input_type = '<input type="number" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr($option_actual[$option[0]]) . '" class="' . $option[3] . '"' . $min_attr . ' />' . PHP_EOL;
1336 break;
1337
1338 case 'textarea':
1339 $rows_attr = isset($option[7]['rows']) ? ' rows="' . esc_attr($option[7]['rows']) . '"' : ' rows="4"';
1340 $placeholder_attr = isset($option[7]['placeholder']) ? ' placeholder="' . esc_attr($option[7]['placeholder']) . '"' : '';
1341 $width_attr = (!empty($option[7]['width'])) ? ' style="width:' . esc_attr($option[7]['width']) . ';"' : ' style="width:100%; max-width:600px;"';
1342 $input_type = '<textarea id="' . $option[0] . '" name="' . $option[0] . '"' . $rows_attr . $placeholder_attr . $width_attr . ' class="' . $option[3] . '">' . esc_textarea($option_actual[$option[0]]) . '</textarea>' . PHP_EOL;
1343 break;
1344 }
1345
1346 if (is_array($option[2])) {
1347 $input_type = '<input type="' . $option[2]["type"] . '" id="' . $option[0] . '" name="' . $option[0] . '" value="' . esc_attr($option_actual[$option[0]]) . '" class="' . $option[3] . '" ' . $option[2]["attr"] . ' />' . PHP_EOL;
1348 }
1349
1350 // Additional Information
1351 $extra_prefix = '';
1352 $extra_suffix = '';
1353 if (!empty($option[4])) {
1354 if ($option[2] == 'sub_multiple_checkbox') {
1355 $extra_prefix = '<' . $desc_html_tag . ' class="stpexplan">' . $option[4] . '</' . $desc_html_tag . '>' . PHP_EOL;
1356 } else {
1357 $extra_suffix = '<' . $desc_html_tag . ' class="stpexplan">' . $option[4] . '</' . $desc_html_tag . '>' . PHP_EOL;
1358 }
1359 }
1360
1361 // Output
1362 $output .= '<tr style="vertical-align: top;" class="' . $class . '"><th scope="row"><label for="' . $option[0] . '">' . $option[1] . '</label></th><td>' . $extra_prefix . ' ' . $input_type . ' ' . $extra_suffix . '</td></tr>' . PHP_EOL;
1363 }
1364 $output .= '</table>' . PHP_EOL;
1365 $output .= '</fieldset>' . PHP_EOL;
1366 $output .= '</div>' . PHP_EOL;
1367 }
1368
1369 return $output;
1370 }
1371
1372 /**
1373 * Get nice title for tabs title option
1374 *
1375 * @param string $id
1376 *
1377 * @return string
1378 */
1379 public static function getNiceTitleOptions($id = '')
1380 {
1381 switch ($id) {
1382 case 'administration':
1383 return esc_html__('Administration', 'simple-tags');
1384 case 'auto-links':
1385 return esc_html__('Auto link', 'simple-tags');
1386 case 'features':
1387 return esc_html__('Features', 'simple-tags');
1388 case 'embeddedtags':
1389 return esc_html__('Embedded Tags', 'simple-tags');
1390 case 'tagspost':
1391 return esc_html__('Tags for Current Post', 'simple-tags');
1392 case 'relatedposts':
1393 return esc_html__('Related Posts', 'simple-tags');
1394 case 'legacy':
1395 return esc_html__('Legacy', 'simple-tags');
1396 case 'posts':
1397 return esc_html__('Posts', 'simple-tags');
1398 case 'taxopress-ai':
1399 return esc_html__('Metaboxes', 'simple-tags');
1400 case 'metabox':
1401 return esc_html__('Metabox Access', 'simple-tags');
1402 case 'linked_terms':
1403 return esc_html__('Linked Terms', 'simple-tags');
1404 case 'synonyms':
1405 return esc_html__('Term Synonyms', 'simple-tags');
1406 case 'licence':
1407 return esc_html__('License', 'simple-tags');
1408 case 'hidden_terms':
1409 return esc_html__('Hidden Terms', 'simple-tags');
1410 case 'frontend_scripts':
1411 return esc_html__('Frontend Scripts', 'simple-tags');
1412 case 'manage_terms':
1413 return esc_html__('Manage Terms', 'simple-tags');
1414 case 'mass_edit_terms':
1415 return esc_html__('Mass Edit Terms', 'simple-tags');
1416 case 'core_linked_terms':
1417 return esc_html__('Linked Terms', 'simple-tags');
1418 case 'core_synonyms_terms':
1419 return esc_html__('Term Synonyms', 'simple-tags');
1420 case 'legacy_ai_sources':
1421 return esc_html__('Auto Terms', 'simple-tags');
1422 }
1423
1424 return '';
1425 }
1426
1427 /**
1428 * This method allow to check if the DB is up to date, and if a upgrade is need for options
1429 * TODO, useful or delete ?
1430 *
1431 * @return void
1432 * @author WebFactory Ltd
1433 */
1434 public static function upgrade()
1435 {
1436 // Get current version number
1437 $current_version = get_option(STAGS_OPTIONS_NAME . '-version');
1438
1439 // Upgrade needed ?
1440 if ($current_version == false || version_compare($current_version, STAGS_VERSION, '<')) {
1441 $current_options = get_option(STAGS_OPTIONS_NAME);
1442 if (! is_array($current_options)) {
1443 $current_options = [];
1444 }
1445
1446 $default_options = (array) include(STAGS_DIR . '/inc/helper.options.default.php');
1447
1448 // Add new options
1449 foreach ($default_options as $key => $default_value) {
1450 if (!isset($current_options[$key])) {
1451 $current_options[$key] = $default_value;
1452 }
1453 }
1454
1455 // Remove old options
1456 /*foreach ($current_options as $key => $current_value) {
1457 if (!isset($default_options[$key])) {
1458 unset($current_options[$key]);
1459 }
1460 }*/
1461
1462 update_option(STAGS_OPTIONS_NAME . '-version', STAGS_VERSION);
1463 update_option(STAGS_OPTIONS_NAME, $current_options);
1464 }
1465 }
1466
1467 /**
1468 * Make a simple SQL query with some args for get terms for ajax display
1469 *
1470 * @param string $taxonomy
1471 * @param string $search
1472 * @param string $order_by
1473 * @param string $order
1474 *
1475 * @return array
1476 * @author WebFactory Ltd
1477 */
1478 public static function getTermsForAjax($taxonomy = 'post_tag', $search = '', $order_by = 'name', $order = 'ASC', $limit = 0)
1479 {
1480 global $wpdb;
1481
1482 $order = strtoupper($order);
1483 if (!in_array($order, ['ASC', 'DESC'], true)) {
1484 $order = 'ASC';
1485 }
1486
1487 $allowed_orderby = [
1488 'name' => 't.name',
1489 'count' => 'tt.count',
1490 'random' => 'RAND()',
1491 ];
1492
1493 if (isset($allowed_orderby[$order_by])) {
1494 $order_by_sql = $allowed_orderby[$order_by];
1495 } else {
1496 $order_by_sql = $allowed_orderby['name'];
1497 }
1498
1499 $limit_sql = '';
1500 $limit = (int) $limit;
1501 if ($limit > 0) {
1502 $limit_sql = $wpdb->prepare('LIMIT 0, %d', $limit);
1503 }
1504
1505 if ($taxonomy == 'linked_term_taxonomies') {
1506 $taxonomies = SimpleTags_Plugin::get_option_value('linked_terms_taxonomies');
1507 if (empty($taxonomies) || !is_array($taxonomies)) {
1508 $taxonomies = ['category', 'post_tag'];
1509 }
1510 $taxonomies_list = "'" . implode("', '", $taxonomies) . "'";
1511 }
1512
1513 if (!empty($search)) {
1514 if ($taxonomy == 'linked_term_taxonomies') {
1515 $query = $wpdb->prepare(
1516 "
1517 SELECT DISTINCT t.name, t.term_id, tt.taxonomy
1518 FROM {$wpdb->terms} AS t
1519 INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id
1520 WHERE tt.taxonomy IN ($taxonomies_list)
1521 AND t.name LIKE %s
1522 ORDER BY $order_by_sql $order $limit_sql
1523 ",
1524 '%' . $wpdb->esc_like($search) . '%'
1525 );
1526 } else {
1527 $query = $wpdb->prepare(
1528 "
1529 SELECT DISTINCT t.name, t.slug, t.term_id, tt.taxonomy
1530 FROM {$wpdb->terms} AS t
1531 INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id
1532 WHERE tt.taxonomy = %s
1533 AND t.name LIKE %s
1534 ORDER BY $order_by_sql $order $limit_sql
1535 ",
1536 $taxonomy,
1537 '%' . $wpdb->esc_like($search) . '%'
1538 );
1539 }
1540 return $wpdb->get_results($query);
1541 } else {
1542 if ($taxonomy == 'linked_term_taxonomies') {
1543 $query = "
1544 SELECT DISTINCT t.name, t.term_id, tt.taxonomy
1545 FROM {$wpdb->terms} AS t
1546 INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id
1547 WHERE tt.taxonomy IN ($taxonomies_list)
1548 ORDER BY $order_by_sql $order $limit_sql
1549 ";
1550 } else {
1551 $query = $wpdb->prepare("
1552 SELECT DISTINCT t.name, t.slug, t.term_id, tt.taxonomy
1553 FROM {$wpdb->terms} AS t
1554 INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id
1555 WHERE tt.taxonomy = %s
1556 ORDER BY $order_by_sql $order $limit_sql
1557 ", $taxonomy);
1558 }
1559
1560 return $wpdb->get_results($query);
1561 }
1562 }
1563
1564 /**
1565 * Plugin installer/uograde code
1566 *
1567 * @return void
1568 */
1569 public static function plugin_installer_upgrade_code()
1570 {
1571 if (!get_option('taxopress_3_23_0_upgrade_completed')) {
1572 $options = SimpleTags_Plugin::get_option();
1573
1574 // add metabox default values
1575 $tax_names = array_keys(get_taxonomies([], 'names'));
1576 foreach (taxopress_get_all_wp_roles() as $role_name => $role_info) {
1577 if (in_array($role_name, ['administrator', 'editor', 'author', 'contributor'])) {
1578 $enable_acess_default_value = 1;
1579 } else {
1580 $enable_acess_default_value = 0;
1581 }
1582 $options['enable_' . $role_name . '_metabox'] = $enable_acess_default_value;
1583 $options['enable_metabox_' . $role_name . ''] = $tax_names;
1584 $options['remove_taxonomy_metabox_' . $role_name . ''] = [];
1585 }
1586
1587 SimpleTags_Plugin::set_option($options);
1588
1589 update_option('taxopress_3_23_0_upgrade_completed', true);
1590 } elseif (!get_option('taxopress_3_28_0_upgrade_completed')) {
1591 if (function_exists('taxopress_get_autoterm_data')) {
1592 $autoterms = taxopress_get_autoterm_data();
1593 foreach ($autoterms as $autoterm_index => $autoterm) {
1594 //enable when to fields
1595 $autoterms[$autoterm_index]['autoterm_for_post'] = 1;
1596 $autoterms[$autoterm_index]['autoterm_for_schedule'] = 1;
1597 $autoterms[$autoterm_index]['autoterm_for_existing_content'] = 1;
1598 $autoterms[$autoterm_index]['autoterm_for_metaboxes'] = 1;
1599 // update new cloned fields for other groups
1600 $autoterms[$autoterm_index]['schedule_terms_limit'] = !empty($autoterm['terms_limit']) ? $autoterm['terms_limit'] : 5;
1601 $autoterms[$autoterm_index]['schedule_autoterm_target'] = !empty($autoterm['autoterm_target']) ? $autoterm['autoterm_target'] : 0;
1602 $autoterms[$autoterm_index]['schedule_autoterm_word'] = !empty($autoterm['autoterm_word']) ? $autoterm['autoterm_word'] : 0;
1603 $autoterms[$autoterm_index]['schedule_autoterm_hash'] = !empty($autoterm['autoterm_hash']) ? $autoterm['autoterm_hash'] : 0;
1604
1605 $autoterms[$autoterm_index]['existing_content_terms_limit'] = !empty($autoterm['terms_limit']) ? $autoterm['terms_limit'] : 5;
1606 }
1607 update_option('taxopress_autoterms', $autoterms);
1608 }
1609 update_option('taxopress_3_28_0_upgrade_completed', true);
1610 }
1611 }
1612
1613 /**
1614 * Redirect user on plugin activation
1615 *
1616 * @return void
1617 */
1618 public static function redirect_on_activate()
1619 {
1620 if (get_option('taxopress_activate')) {
1621 delete_option('taxopress_activate');
1622 wp_redirect(admin_url("admin.php?page=st_dashboard&welcome"));
1623 exit;
1624 }
1625 }
1626 }
1627