PluginProbe
Tag Groups is the Advanced Way to Display Your Taxonomy Terms / trunk
Tag Groups is the Advanced Way to Display Your Taxonomy Terms vtrunk
2.2.2 2.2.1 2.2.0 trunk 1.40.0 1.40.2 1.41.0 1.42.1 1.43.0 1.43.1 1.43.10 1.43.10.1 1.43.2 1.43.3 1.43.4 1.43.5 1.43.6 1.43.7 1.43.9 1.44.0 1.44.1 1.44.3 1.44.3.1 2.0.0 2.0.1 All 36 releases
tag-groups / include / admin / class.settings.php

class.settings.php in Tag Groups is the Advanced Way to Display Your Taxonomy Terms trunk, at include/admin/class.settings.php

1,078 lines 53.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @package Tag Groups
5 * @author Christoph Amthor
6 * @copyright 2018 Christoph Amthor (@ Chatty Mango, chattymango.com)
7 * @license GPL-3.0+
8 */
9
10 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace, Squiz.Classes.ValidClassName.NotCamelCaps, PSR1.Methods.CamelCapsMethodName.NotCamelCaps
11 if (!class_exists('TagGroups_Settings')) {
12 /**
13 *
14 */
15 class TagGroups_Settings
16 {
17 /**
18 * renders the top of all setting pages
19 *
20 * @param void
21 * @return void
22 */
23 public static function add_header()
24 {
25 $view = new TagGroups_View('admin/settings_header');
26 $view->set('admin_page_title', get_admin_page_title());
27 $view->render();
28 }
29
30 /**
31 * renders the bottom of all settings pages
32 *
33 * @param void
34 * @return void
35 */
36 public static function add_footer()
37 {
38 $view = new TagGroups_View('admin/settings_footer');
39 $view->render();
40 }
41
42 /**
43 * gets the slug of the currently selected tab
44 *
45 * @param string $default
46 * @return string
47 */
48 public static function get_active_tab($tabs)
49 {
50
51 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only tab selection
52 if (isset($_GET['active-tab'])) {
53 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only tab selection
54 return sanitize_title(wp_unslash($_GET['active-tab']));
55 } else {
56 $keys = array_keys($tabs);
57 return reset($keys);
58 }
59 }
60
61 /**
62 * gets the HTML of the header of tabbed view
63 *
64 * @param string $default
65 * @return string
66 */
67 public static function add_tabs($page, $tabs, $active_tab)
68 {
69 if (count($tabs) < 2) {
70 return ( empty($label) ? '' : '<h2>' . $label . '</h2>' );
71 }
72 $view = new TagGroups_View('admin/settings_tabs');
73 $view->set(array(
74 'tabs' => $tabs,
75 'page' => $page,
76 'active_tab' => $active_tab,
77 ));
78 $view->render();
79 }
80
81
82 /**
83 * renders a settings page: home
84 *
85 * @param void
86 * @return void
87 */
88 public static function settings_page_home()
89 {
90 global $tag_group_groups ;
91 // Make very sure that only administrators can access this page
92 if (!current_user_can('manage_options')) {
93 wp_die("Capability check failed");
94 }
95 $enabled_taxonomies = TagGroups_Taxonomy::get_enabled_taxonomies();
96 $public_taxonomies = TagGroups_Taxonomy::get_public_taxonomies();
97 self::add_header();
98 $html = '';
99 self::add_settings_help();
100 $tabs = array();
101 $tabs['taxonomies'] = '';
102 $tabs = apply_filters('tag_groups_settings', $tabs);
103 $active_tab = self::get_active_tab($tabs);
104 ?>
105 <div class="pp-columns-wrapper<?php echo (!TagGroups_Utilities::is_premium_plan()) ? ' pp-enable-sidebar' : '' ?>">
106 <div class="pp-column-left">
107 <?php
108 self::add_tabs('tag-groups-settings', $tabs, $active_tab);
109 switch ($active_tab) {
110 case 'taxonomies':
111 $view = new TagGroups_View('admin/settings_taxonomies');
112 $view->set(array(
113 'public_taxonomies' => $public_taxonomies,
114 'enabled_taxonomies' => $enabled_taxonomies,
115 ));
116 $view->render();
117 break;
118 default:
119 if (class_exists('TagGroups_Premium_Settings')) {
120 TagGroups_Premium_Settings::get_content($active_tab);
121 }
122 break;
123 }
124 ?>
125 </div>
126 <?php if (!TagGroups_Utilities::is_premium_plan()) : ?>
127 <div class="pp-column-right">
128 <?php do_action('tag_groups_settings_right_sidebar'); ?>
129 </div>
130 <?php endif; ?>
131 </div>
132 <?php
133 self::add_footer();
134 }
135 /**
136 * renders a settings page: back end
137 *
138 * @param void
139 * @return void
140 */
141 public static function settings_page_back_end()
142 {
143 // Make very sure that only administrators can access this page
144 if (!current_user_can('manage_options')) {
145 wp_die("Capability check failed");
146 }
147 self::add_header();
148 self::add_settings_help();
149 $tabs = array();
150 $tabs = apply_filters('tag_groups_settings_back_end_tabs', $tabs);
151 $tabs['filters'] = __('Filters', 'tag-groups');
152 if (TagGroups_Gutenberg::is_gutenberg_active()) {
153 $tabs['gutenberg'] = __('Gutenberg', 'tag-groups');
154 }
155 if (TagGroups_WPML::is_multilingual()) {
156 $tabs['multilingual'] = __('Multilingual', 'tag-groups');
157 }
158 $active_tab = self::get_active_tab($tabs);
159 ?>
160 <div class="pp-columns-wrapper<?php echo (!TagGroups_Utilities::is_premium_plan()) ? ' pp-enable-sidebar' : '' ?>">
161 <div class="pp-column-left">
162 <?php
163 self::add_tabs('tag-groups-settings-back-end', $tabs, $active_tab);
164 switch ($active_tab) {
165 case 'filters':
166 $show_filter_posts = TagGroups_Options::get_option('tag_group_show_filter', 0);
167 $show_filter_tags = TagGroups_Options::get_option('tag_group_show_filter_tags', 0);
168 $view = new TagGroups_View('admin/settings_back_end_filters');
169 $view->set(array(
170 'show_filter_posts' => $show_filter_posts,
171 'show_filter_tags' => $show_filter_tags,
172 ));
173 $view->render();
174 break;
175 // filters
176 // filters
177 case 'gutenberg':
178 $tag_group_server_side_render = TagGroups_Options::get_option('tag_group_server_side_render', 1);
179 $view = new TagGroups_View('admin/settings_back_end_gutenberg');
180 $view->set(array(
181 'tag_group_server_side_render' => $tag_group_server_side_render,
182 ));
183 $view->render();
184 break;
185 // gutenberg
186 // gutenberg
187 case 'multilingual':
188 $tag_group_multilingual_sync_groups = TagGroups_Options::get_option('tag_group_multilingual_sync_groups', 1);
189 $view = new TagGroups_View('admin/settings_back_end_multilingual');
190 $view->set(array(
191 'tag_group_multilingual_sync_groups' => $tag_group_multilingual_sync_groups,
192 ));
193 $view->render();
194 break;
195 // gutenberg
196 // gutenberg
197 default:
198 if (class_exists('TagGroups_Premium_Settings')) {
199 TagGroups_Premium_Settings::get_content($active_tab);
200 }
201 break;
202 }
203 ?>
204 </div>
205 <?php if (!TagGroups_Utilities::is_premium_plan()) : ?>
206 <div class="pp-column-right">
207 <?php do_action('tag_groups_settings_right_sidebar'); ?>
208 </div>
209 <?php endif; ?>
210 </div>
211 <?php
212 self::add_footer();
213 }
214
215 /**
216 * renders a settings page: front end
217 *
218 * @param void
219 * @return void
220 */
221 public static function settings_page_front_end()
222 {
223 // Make very sure that only administrators can access this page
224 if (!current_user_can('manage_options')) {
225 wp_die("Capability check failed");
226 }
227 $default_themes = explode(',', TAG_GROUPS_BUILT_IN_THEMES);
228 $tag_group_theme = TagGroups_Options::get_option('tag_group_theme', TAG_GROUPS_STANDARD_THEME);
229 $tag_group_mouseover = TagGroups_Options::get_option('tag_group_mouseover', 0);
230 $tag_group_collapsible = TagGroups_Options::get_option('tag_group_collapsible', 0);
231 $tag_group_enqueue_jquery = TagGroups_Options::get_option('tag_group_enqueue_jquery', 1);
232 $tag_group_html_description = TagGroups_Options::get_option('tag_group_html_description', 0);
233 $tag_group_shortcode_widget = TagGroups_Options::get_option('tag_group_shortcode_widget');
234 $tag_group_shortcode_enqueue_always = TagGroups_Options::get_option('tag_group_shortcode_enqueue_always', 1);
235 self::add_header();
236 self::add_settings_help();
237 $tabs = array();
238 $tabs['shortcodes'] = __('Shortcodes', 'tag-groups');
239 $tabs['themes'] = __('Themes and Appearance', 'tag-groups');
240 $tabs = apply_filters('tag_groups_settings_front_end_tabs', $tabs);
241 $active_tab = self::get_active_tab($tabs);
242 ?>
243 <div class="pp-columns-wrapper<?php echo (!TagGroups_Utilities::is_premium_plan()) ? ' pp-enable-sidebar' : '' ?>">
244 <div class="pp-column-left">
245 <?php
246 self::add_tabs('tag-groups-settings-front-end', $tabs, $active_tab);
247 switch ($active_tab) {
248 case 'shortcodes':
249 /**
250 * Let the premium plugin add own shortcode information.
251 */
252 $premium_shortcode_info = apply_filters('tag_groups_hook_shortcodes', '');
253 $view = new TagGroups_View('admin/settings_front_end_shortcodes');
254 $gutenberg_documentation_link = '';
255 $view->set(array(
256 'premium_shortcode_info' => $premium_shortcode_info,
257 'tag_group_shortcode_enqueue_always' => $tag_group_shortcode_enqueue_always,
258 'tag_group_shortcode_widget' => $tag_group_shortcode_widget,
259 'gutenberg_documentation_link' => $gutenberg_documentation_link,
260 ));
261 $view->render();
262 break;
263 case 'themes':
264 $tag_group_html_description_options = array(
265 0 => __('remove', 'tag-groups') . ' ' . __('(recommended)', 'tag-groups'),
266 1 => __('keep', 'tag-groups'),
267 2 => __('use unfiltered_html filter', 'tag-groups'),
268 );
269 $view = new TagGroups_View('admin/settings_front_end_themes');
270 $view->set(array(
271 'default_themes' => $default_themes,
272 'tag_group_theme' => $tag_group_theme,
273 'tag_group_enqueue_jquery' => $tag_group_enqueue_jquery,
274 'tag_group_mouseover' => $tag_group_mouseover,
275 'tag_group_collapsible' => $tag_group_collapsible,
276 'tag_group_html_description' => $tag_group_html_description,
277 'tag_group_html_description_options' => $tag_group_html_description_options,
278 ));
279 $view->render();
280 break;
281 default:
282 if (class_exists('TagGroups_Premium_Settings')) {
283 TagGroups_Premium_Settings::get_content($active_tab);
284 }
285 break;
286 }
287 ?>
288 </div>
289 <?php if (!TagGroups_Utilities::is_premium_plan()) : ?>
290 <div class="pp-column-right">
291 <?php do_action('tag_groups_settings_right_sidebar'); ?>
292 </div>
293 <?php endif; ?>
294 </div>
295 <?php
296 self::add_footer();
297 }
298
299 /**
300 * renders a settings page: general
301 *
302 * @param void
303 * @return void
304 */
305 public static function settings_page_general()
306 {
307 global $tag_group_groups;
308
309 // Make very sure that only administrators can access this page
310 if (!current_user_can('manage_options')) {
311 wp_die("Capability check failed");
312 }
313 $tag_group_reset_when_uninstall = TagGroups_Options::get_option('tag_group_reset_when_uninstall', 0);
314 self::add_header();
315 self::add_settings_help();
316 $tabs = array();
317 $tabs['first-aid'] = __('First Aid', 'tag-groups');
318 $tabs['rest-api'] = __('REST API', 'tag-groups');
319 $tabs['system'] = __('System Information', 'tag-groups');
320 $tabs['debug'] = __('Debugging', 'tag-groups');
321 $tabs['export_import'] = __('Export/Import', 'tag-groups');
322 $tabs['reset'] = __('Reset', 'tag-groups');
323 if (TagGroups_Utilities::is_premium_plan()) {
324 $tabs['licences'] = __('Licences', 'tag-groups');
325 }
326 $tabs = apply_filters('tag_groups_settings_general_tabs', $tabs);
327 $active_tab = self::get_active_tab($tabs);
328 ?>
329 <div class="pp-columns-wrapper<?php echo (!TagGroups_Utilities::is_premium_plan()) ? ' pp-enable-sidebar' : '' ?>">
330 <div class="pp-column-left">
331 <?php
332 self::add_tabs('tag-groups-settings-general', $tabs, $active_tab);
333 switch ($active_tab) {
334 case 'first-aid':
335 if (
336 !empty($_POST['process-tasks']) &&
337 !empty($_POST['nonce']) &&
338 wp_verify_nonce(sanitize_key(wp_unslash($_POST['nonce'])), 'tag-groups-first-aid-nonce')
339 ) {
340 self::add_html_process();
341 } else {
342 $view = new TagGroups_View('admin/settings_troubleshooting_first_aid');
343 $view->set('tasks_migration', 'migratetermmeta');
344 $view->set('tasks_maintenance', 'fixgroups,fixmissinggroups,sortgroups');
345 $view->set('tag_group_show_filter_tags', TagGroups_Options::get_option('tag_group_show_filter_tags', 0));
346 $view->render();
347 }
348
349 break;
350
351 case 'licences':
352 if (class_exists('TagGroups_Premium_Settings') && method_exists('TagGroups_Premium_Settings', 'settings_page_licence')) {
353 TagGroups_Premium_Settings::settings_page_licence();
354 }
355
356
357 break;
358
359 case 'rest-api':
360 $view = new TagGroups_View('admin/settings_rest_api');
361 $view->set('group_public_api_access', TagGroups_Options::get_option('tag_group_enable_group_public_api_access', 0));
362 $view->set('terms_public_api_access', TagGroups_Options::get_option('tag_group_enable_terms_public_api_access', 0));
363 $view->render();
364
365 break;
366 case 'system':
367 $phpversion = phpversion();
368
369 if (version_compare($phpversion, '7.0.0', '<')) {
370 $php_upgrade_recommendation = true;
371 } else {
372 $php_upgrade_recommendation = false;
373 }
374
375 $active_theme = wp_get_theme();
376 $protocol = ( isset($_SERVER['HTTPS']) ? 'https://' : 'http://' );
377 $ajax_test_url = admin_url('admin-ajax.php', $protocol);
378 /* constants */
379 $wp_constants = array(
380 'WP_DEBUG',
381 'WP_DEBUG_DISPLAY',
382 'WP_DEBUG_LOG',
383 'ABSPATH',
384 // phpcs:ignore Squiz.PHP.CommentedOutCode.Found
385 // 'WP_HOME',
386 'MULTISITE',
387 'WP_CACHE',
388 'COMPRESS_SCRIPTS',
389 // phpcs:ignore Squiz.PHP.CommentedOutCode.Found
390 // 'FS_CHMOD_DIR',
391 // 'FS_CHMOD_FILE',
392 'FORCE_SSL_ADMIN',
393 'CM_UPDATE_CHECK',
394 'WP_MEMORY_LIMIT',
395 'WP_MAX_MEMORY_LIMIT',
396 );
397 sort($wp_constants);
398 $constants = get_defined_constants();
399 foreach ($constants as &$constant) {
400 if (isset($constant)) {
401 $constant = self::echo_var($constant);
402 }
403 }
404 ksort($constants);
405 $benchmarks = array();
406 $benchmark['name'] = 'Database: tags (1000x read)';
407 $group_ids = $tag_group_groups->get_group_ids();
408 $enabled_taxonomies = TagGroups_Taxonomy::get_enabled_taxonomies();
409 $start_time = microtime(true);
410 for ($i = 0; $i < 1000; $i++) {
411 $group_id = $group_ids[array_rand($group_ids)];
412 $tg_group = new TagGroups_Group($group_id);
413 $group_terms_ids_dummy = $tg_group->get_group_terms($enabled_taxonomies, false, 'ids');
414 }
415 $benchmark['value'] = sprintf('%d ms', 1000 * (microtime(true) - $start_time));
416 $benchmarks[] = $benchmark;
417 /**
418 * Prepare the cache here so that we can test if it persists beyond seesions
419 */
420 $tag_group_object_cache = TagGroups_Options::get_option('tag_group_object_cache', TagGroups_Object_Cache::WP_TRANSIENTS);
421 $object_cache_options = array(
422 1 => __('Transients', 'tag-groups'),
423 2 => __('Database', 'tag-groups'),
424 3 => __('Filesystem', 'tag-groups'),
425 9 => __('WP Object Cache', 'tag-groups'),
426 );
427 $cache_key = md5('benchmark');
428 foreach ($object_cache_options as $object_cache_option_id => $object_cache_option_name) {
429 TagGroups_Options::update_option('tag_group_object_cache', $object_cache_option_id);
430 do_action('tag_groups_hook_cache_set', $cache_key . '-efficacy-test', '');
431 }
432 TagGroups_Options::update_option('tag_group_object_cache', $tag_group_object_cache);
433 if (!defined('TAG_GROUPS_PLUGIN_IS_FREE') || !TAG_GROUPS_PLUGIN_IS_FREE) {
434 }
435 global $wpdb ;
436 $db_info = $wpdb->db_server_info();
437 if (empty($db_info)) {
438 $db_info = 'unknown';
439 }
440 $view = new TagGroups_View('admin/settings_troubleshooting_system');
441 $view->set(array(
442 'phpversion' => $phpversion,
443 'php_upgrade_recommendation' => $php_upgrade_recommendation,
444 'db_info' => $db_info,
445 'wp_constants' => $wp_constants,
446 'constants' => $constants,
447 'ajax_test_url' => $ajax_test_url,
448 'active_theme' => $active_theme,
449 'benchmarks' => $benchmarks
450 ));
451 $view->render();
452 break;
453 case 'debug':
454 $help_url = 'https://taxopress.com/docs/how-to-use-the-debug-log/';
455 $view = new TagGroups_View('admin/settings_troubleshooting_debug');
456 $verbose_is_on_hardcoded = defined('CM_DEBUG') && strtolower(CM_DEBUG) == 'verbose';
457 $verbose_is_on_option = (bool) TagGroups_Options::get_option('tag_group_verbose_debug', 0);
458 $view->set(array(
459 'debug_is_on' => defined('WP_DEBUG') && WP_DEBUG,
460 'verbose_is_on' => defined('CM_DEBUG') && $verbose_is_on_hardcoded || $verbose_is_on_option,
461 'help_url' => $help_url,
462 'verbose_is_on_hardcoded' => $verbose_is_on_hardcoded,
463 ));
464 $view->render();
465 break;
466 case 'export_import':
467 $view = new TagGroups_View('admin/settings_tools_export_import');
468 $view->render();
469 break;
470 case 'reset':
471 $view = new TagGroups_View('admin/settings_tools_reset');
472 $view->set('tag_group_reset_when_uninstall', $tag_group_reset_when_uninstall);
473 $view->render();
474 break;
475 default:
476 if (class_exists('TagGroups_Premium_Settings')) {
477 TagGroups_Premium_Settings::get_content($active_tab);
478 }
479 break;
480 }
481 ?>
482 </div>
483 <?php if (!TagGroups_Utilities::is_premium_plan()) : ?>
484 <div class="pp-column-right">
485 <?php do_action('tag_groups_settings_right_sidebar'); ?>
486 </div>
487 <?php endif; ?>
488 </div>
489 <?php
490 self::add_footer();
491 }
492
493 /**
494 * Processes form submissions from the settings page
495 *
496 * @param void
497 * @return void
498 */
499 public static function settings_page_actions()
500 {
501 global $tag_group_groups ;
502
503 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verified in switch cases
504 if (!empty($_REQUEST['tg_action'])) {
505 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Recommended -- Sanitized in switch statement
506 $tg_action = sanitize_key(wp_unslash($_REQUEST['tg_action']));
507 } else {
508 return;
509 }
510
511 // Make very sure that only administrators can do actions
512 if (!current_user_can('manage_options')) {
513 wp_die("Capability check failed");
514 }
515
516 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce verified in switch cases
517 if (isset($_POST['ok'])) {
518 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing -- Sanitized below
519 $ok = sanitize_key(wp_unslash($_POST['ok']));
520 } else {
521 $ok = '';
522 }
523
524 switch ($tg_action) {
525 case 'shortcode':
526 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce verification
527 if (!isset($_POST['tag-groups-shortcode-nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['tag-groups-shortcode-nonce'])), 'tag-groups-shortcode')) {
528 die("Security check");
529 }
530 // Make sure that only administrators can save settings
531 if (!current_user_can('manage_options')) {
532 wp_die("Capability check failed");
533 }
534
535 if (isset($_POST['widget']) && $_POST['widget'] == '1') {
536 update_option('tag_group_shortcode_widget', 1);
537 } else {
538 update_option('tag_group_shortcode_widget', 0);
539 }
540
541
542 if (isset($_POST['enqueue']) && $_POST['enqueue'] == '1') {
543 update_option('tag_group_shortcode_enqueue_always', 1);
544 } else {
545 update_option('tag_group_shortcode_enqueue_always', 0);
546 }
547
548 TagGroups_Admin_Notice::add('success', __('Your settings have been saved.', 'tag-groups'));
549 break;
550 case 'rest_api':
551 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce verification
552 if (!isset($_POST['tag-groups-rest-api-nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['tag-groups-rest-api-nonce'])), 'tag-groups-rest-api')) {
553 die("Security check");
554 }
555 // Make sure that only administrators can save settings
556 if (!current_user_can('manage_options')) {
557 wp_die("Capability check failed");
558 }
559
560 $group_public_api_access = ( isset($_POST['group_public_api_access']) ? 1 : 0 );
561 TagGroups_Options::update_option('tag_group_enable_group_public_api_access', $group_public_api_access);
562
563 $terms_public_api_access = ( isset($_POST['terms_public_api_access']) ? 1 : 0 );
564 TagGroups_Options::update_option('tag_group_enable_terms_public_api_access', $terms_public_api_access);
565
566 TagGroups_Admin_Notice::add('success', __('Your settings has been saved.', 'tag-groups'));
567 break;
568 case 'reset':
569 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce verification
570 if (!isset($_POST['tag-groups-reset-nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['tag-groups-reset-nonce'])), 'tag-groups-reset')) {
571 die("Security check");
572 }
573 // Make sure that only administrators can save settings
574 if (!current_user_can('manage_options')) {
575 wp_die("Capability check failed");
576 }
577
578 if ($ok == 'yes') {
579 $tag_group_groups->reset_groups();
580 /**
581 * Remove filters
582 */
583 delete_option('tag_group_tags_filter');
584 TagGroups_Admin_Notice::add('success', __('All groups have been deleted and assignments reset.', 'tag-groups'));
585 }
586
587 break;
588 case 'uninstall':
589 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce verification
590 if (!isset($_POST['tag-groups-uninstall-nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['tag-groups-uninstall-nonce'])), 'tag-groups-uninstall')) {
591 die("Security check");
592 }
593 // Make sure that only administrators can save settings
594 if (!current_user_can('manage_options')) {
595 wp_die("Capability check failed");
596 }
597
598 if ($ok == 'yes') {
599 update_option('tag_group_reset_when_uninstall', 1);
600 } else {
601 update_option('tag_group_reset_when_uninstall', 0);
602 }
603
604 TagGroups_Admin_Notice::add('success', __('Your settings have been saved.', 'tag-groups'));
605 break;
606 case 'theme':
607 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce verification
608 if (!isset($_POST['tag-groups-settings-nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['tag-groups-settings-nonce'])), 'tag-groups-settings')) {
609 die("Security check");
610 }
611 // Make sure that only administrators can save settings
612 if (!current_user_can('manage_options')) {
613 wp_die("Capability check failed");
614 }
615 $theme = '';
616 if (isset($_POST['theme'])) {
617 switch (sanitize_key(wp_unslash($_POST['theme']))) {
618 case 'own':
619 if (isset($_POST['theme-name'])) {
620 $theme = sanitize_text_field(wp_unslash($_POST['theme-name']));
621 }
622 break;
623 case 'none':
624 $theme = '';
625 break;
626 default:
627 $theme = sanitize_text_field(wp_unslash($_POST['theme']));
628 break;
629 }
630 }
631 TagGroups_Options::update_option('tag_group_theme', $theme);
632 $mouseover = ( isset($_POST['mouseover']) && $_POST['mouseover'] == '1' ? 1 : 0 );
633 $collapsible = ( isset($_POST['collapsible']) && $_POST['collapsible'] == '1' ? 1 : 0 );
634 $html_description = ( isset($_POST['html_description']) ? (int) $_POST['html_description'] : 0 );
635 TagGroups_Options::update_option('tag_group_mouseover', $mouseover);
636 TagGroups_Options::update_option('tag_group_collapsible', $collapsible);
637 TagGroups_Options::update_option('tag_group_html_description', $html_description);
638 $tag_group_enqueue_jquery = ( isset($_POST['enqueue-jquery']) && $_POST['enqueue-jquery'] == '1' ? 1 : 0 );
639 TagGroups_Options::update_option('tag_group_enqueue_jquery', $tag_group_enqueue_jquery);
640 // phpcs:ignore Squiz.PHP.CommentedOutCode.Found
641 // TagGroups_Admin::clear_cache();
642 TagGroups_Admin_Notice::add('success', __('Your settings have been saved.', 'tag-groups'));
643 do_action('tag_groups_theme_saved');
644 break;
645 case 'taxonomy':
646 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce verification
647 if (!isset($_POST['tag-groups-taxonomy-nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['tag-groups-taxonomy-nonce'])), 'tag-groups-taxonomy')) {
648 die("Security check");
649 }
650 // Make sure that only administrators can save settings
651 if (!current_user_can('manage_options')) {
652 wp_die("Capability check failed");
653 }
654
655 if (isset($_POST['taxonomies'])) {
656 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below
657 $taxonomies = wp_unslash($_POST['taxonomies']);
658
659 if (is_array($taxonomies)) {
660 $taxonomies = array_map('sanitize_text_field', $taxonomies);
661 } else {
662 $taxonomies = array( 'post_tag' );
663 }
664 } else {
665 $taxonomies = array( 'post_tag' );
666 }
667
668 $public_taxonomies = TagGroups_Taxonomy::get_public_taxonomies();
669 foreach ($taxonomies as $taxonomy_item) {
670 if (!in_array($taxonomy_item, $public_taxonomies)) {
671 die("Security check: taxonomies");
672 }
673 }
674 TagGroups_Taxonomy::update_enabled($taxonomies);
675 TagGroups_Admin_Notice::add('success', __('Your settings have been saved.', 'tag-groups'));
676 break;
677 case 'backend':
678 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce verification
679 if (!isset($_POST['tag-groups-backend-nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['tag-groups-backend-nonce'])), 'tag-groups-backend')) {
680 die("Security check");
681 }
682 // Make sure that only administrators can save settings
683 if (!current_user_can('manage_options')) {
684 wp_die("Capability check failed");
685 }
686 $show_filter_posts = ( isset($_POST['filter_posts']) ? 1 : 0 );
687 TagGroups_Options::update_option('tag_group_show_filter', $show_filter_posts);
688 $show_filter_tags = ( isset($_POST['filter_tags']) ? 1 : 0 );
689 TagGroups_Options::update_option('tag_group_show_filter_tags', $show_filter_tags);
690 TagGroups_Admin_Notice::add('success', __('Your settings have been saved.', 'tag-groups'));
691 break;
692 case 'gutenberg':
693 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce verification
694 if (!isset($_POST['tag-groups-gutenberg-nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['tag-groups-gutenberg-nonce'])), 'tag-groups-gutenberg')) {
695 die("Security check");
696 }
697 // Make sure that only administrators can save settings
698 if (!current_user_can('manage_options')) {
699 wp_die("Capability check failed");
700 }
701 $tag_group_server_side_render = ( isset($_POST['tag_group_server_side_render']) ? 1 : 0 );
702 TagGroups_Options::update_option('tag_group_server_side_render', $tag_group_server_side_render);
703 TagGroups_Admin_Notice::add('success', __('Your settings have been saved.', 'tag-groups'));
704 break;
705 case 'multilingual':
706 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce verification
707 if (!isset($_POST['tag-groups-multilingual-nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['tag-groups-multilingual-nonce'])), 'tag-groups-multilingual')) {
708 die("Security check");
709 }
710 // Make sure that only administrators can save settings
711 if (!current_user_can('manage_options')) {
712 wp_die("Capability check failed");
713 }
714 $tag_group_multilingual_sync_groups = ( isset($_POST['tag_group_multilingual_sync_groups']) ? 1 : 0 );
715 TagGroups_Options::update_option('tag_group_multilingual_sync_groups', $tag_group_multilingual_sync_groups);
716 TagGroups_Admin_Notice::add('success', __('Your settings have been saved.', 'tag-groups'));
717 break;
718 case 'reset-tag-filter':
719 // check nonce
720 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce verification
721 if (!isset($_POST['tag-groups-reset-tag-filter-nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['tag-groups-reset-tag-filter-nonce'])), 'tag-groups-reset-tag-filter')) {
722 die("Security check");
723 }
724 // Make sure that only administrators can save settings
725 if (!current_user_can('manage_options')) {
726 wp_die("Capability check failed");
727 }
728 /**
729 * Reset the group filter above the tags list
730 */
731 update_option('tag_group_tags_filter', array());
732 TagGroups_Admin_Notice::add('success', __('The filter on the tags page has been reset to show all tags.', 'tag-groups'));
733 break;
734 case 'export':
735 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce verification
736 if (!isset($_POST['tag-groups-export-nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['tag-groups-export-nonce'])), 'tag-groups-export')) {
737 die("Security check");
738 }
739 // Make sure that only administrators can save settings
740 if (!current_user_can('manage_options')) {
741 wp_die("Capability check failed");
742 }
743 $export = new TagGroups_Export();
744 $export->process_options_for_export();
745 $export->process_terms_for_export();
746 $export->write_files();
747 $export->show_download_links();
748 break;
749 case 'import':
750 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce verification
751 if (!isset($_POST['tag-groups-import-nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['tag-groups-import-nonce'])), 'tag-groups-import')) {
752 die("Security check");
753 }
754 // Make very sure that only administrators can upload stuff
755 if (!current_user_can('manage_options')) {
756 wp_die("Capability check failed");
757 }
758 if (!function_exists('wp_handle_upload')) {
759 require_once ABSPATH . 'wp-admin/includes/file.php';
760 }
761 $import = new TagGroups_Import();
762 $import->determine_file_type();
763 $import->read_file();
764 $import->parse_and_save();
765 break;
766 case 'debug':
767 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce verification
768 if (!isset($_POST['tag-groups-debug-nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['tag-groups-debug-nonce'])), 'tag-groups-debug')) {
769 die("Security check");
770 }
771 // Make sure that only administrators can save settings
772 if (!current_user_can('manage_options')) {
773 wp_die("Capability check failed");
774 }
775 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated -- Validated below
776 $verbose_debug = ( '1' == $_POST['verbose_debug'] ? 1 : 0 );
777 TagGroups_Options::update_option('tag_group_verbose_debug', $verbose_debug);
778
779 if ($verbose_debug) {
780 TagGroups_Error::log('[Tag Groups] Verbose logging has been turned on.');
781 } else {
782 TagGroups_Error::log('[Tag Groups] Verbose logging has been turned off.');
783 }
784
785 TagGroups_Admin_Notice::add('success', __('Your settings have been saved.', 'tag-groups'));
786 break;
787 default:
788 // hook for premium plugin
789 do_action('tag_groups_hook_settings_action', $tg_action);
790 break;
791 }
792 }
793
794 /**
795 * Prepares variable for echoing as string
796 *
797 *
798 * @param mixed $var Mixed type that needs to be echoed as string.
799 * @return return string
800 */
801 private static function echo_var($var = null)
802 {
803
804 if (is_bool($var)) {
805 return ( $var ? 'true' : 'false' );
806 } elseif (is_array($var)) {
807 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- Debug output for admin
808 return print_r($var, true);
809 } else {
810 return (string) $var;
811 }
812 }
813
814 /**
815 * Returns an array that contains topics covered in the settings
816 *
817 * @param void
818 * @return array
819 */
820 public static function get_setting_topics()
821 {
822 $public_taxonomies_slugs = TagGroups_Taxonomy::get_public_taxonomies();
823 $public_taxonomies_names = array_map(array( 'TagGroups_Taxonomy', 'get_name_from_slug' ), $public_taxonomies_slugs);
824 $topics = array(
825 'taxonomies' => array(
826 'title' => __('Taxonomies', 'tag-groups'),
827 'page' => 'tag-groups-settings',
828 'keywords' => array_merge(array_keys($public_taxonomies_names), array_values($public_taxonomies_names), array( __('tag groups', 'tag-groups') )),
829 ),
830 'shortcodes' => array(
831 'title' => __('Shortcodes', 'tag-groups'),
832 'page' => 'tag-groups-settings-front-end',
833 'keywords' => array(
834 __('tag cloud', 'tag-groups'),
835 __('group info', 'tag-groups'),
836 __('sidebar widget', 'tag-groups'),
837 __('accordion', 'tag-groups'),
838 __('tabs', 'tag-groups'),
839 __('alphabetical', 'tag-groups'),
840 __('post list', 'tag-groups'),
841 'Gutenberg'
842 ),
843 ),
844 'themes' => array(
845 'title' => __('Themes and Appearance', 'tag-groups'),
846 'page' => 'tag-groups-settings-front-end',
847 'keywords' => array(
848 __('tag cloud', 'tag-groups'),
849 'CSS',
850 'style',
851 'HTML',
852 __('colors', 'tag-groups'),
853 __('tag description', 'tag-groups')
854 ),
855 ),
856 'filters' => array(
857 'title' => __('Filters', 'tag-groups'),
858 'page' => 'tag-groups-settings-back-end',
859 'keywords' => array( __('tag filter', 'tag-groups'), __('post filter', 'tag-groups') ),
860 ),
861 'export_import' => array(
862 'title' => __('Export/Import', 'tag-groups'),
863 'page' => 'tag-groups-settings-general',
864 'keywords' => array( __('backup', 'tag-groups') ),
865 ),
866 'reset' => array(
867 'title' => __('Reset', 'tag-groups'),
868 'page' => 'tag-groups-settings-general',
869 'keywords' => array( __('remove plugin', 'tag-groups'), __('remove data', 'tag-groups'), __('delete groups', 'tag-groups') ),
870 ),
871 'system' => array(
872 'title' => __('System Information', 'tag-groups'),
873 'page' => 'tag-groups-settings-general',
874 'keywords' => array(
875 __('debugging', 'tag-groups'),
876 __('PHP Version', 'tag-groups'),
877 __('Ajax Test', 'tag-groups'),
878 __('troubleshooting', 'tag-groups'),
879 __('benchmarks', 'tag-groups'),
880 __('speed test', 'tag-groups'),
881 __('error', 'tag-groups'),
882 __('testing', 'tag-groups')
883 ),
884 ),
885 'debug' => array(
886 'title' => __('Debugging', 'tag-groups'),
887 'page' => 'tag-groups-settings-general',
888 'keywords' => array(
889 __('debugging', 'tag-groups'),
890 __('troubleshooting', 'tag-groups'),
891 __('error', 'tag-groups'),
892 __('testing', 'tag-groups'),
893 __('help', 'tag-groups')
894 ),
895 ),
896 'premium' => array(
897 'title' => __('Tag Groups Pro', 'tag-groups'),
898 'page' => 'tag-groups-settings-premium',
899 'keywords' => array(
900 __('upgrade', 'tag-groups'),
901 __('more groups', 'tag-groups'),
902 __('posts', 'tag-groups'),
903 __('tag cloud', 'tag-groups'),
904 __('filter', 'tag-groups'),
905 __('animated', 'tag-groups'),
906 __('searchable', 'tag-groups'),
907 'Shuffle Box',
908 'Toggle Post Filter',
909 'Dynamic Post Filter',
910 'WooCommerce'
911 ),
912 ),
913 'info' => array(
914 'title' => __('Info', 'tag-groups'),
915 'page' => 'tag-groups-settings-about',
916 'keywords' => array(
917 __('author', 'tag-groups'),
918 __('version', 'tag-groups'),
919 __('contact', 'tag-groups'),
920 __('about', 'tag-groups')
921 ),
922 ),
923 'licenses' => array(
924 'title' => __('Licenses', 'tag-groups'),
925 'page' => 'tag-groups-settings-about',
926 'keywords' => array( __('Credits', 'tag-groups') ),
927 ),
928 'news' => array(
929 'title' => __('Development News', 'tag-groups'),
930 'page' => 'tag-groups-settings-about',
931 'keywords' => array( __('blog', 'tag-groups'), __('updates', 'tag-groups') ),
932 ),
933 'getting_started' => array(
934 'title' => __('First Steps', 'tag-groups'),
935 'page' => 'tag-groups-settings-first-steps',
936 'keywords' => array( __('getting started', 'tag-groups'), __('introduction', 'tag-groups'), __('help', 'tag-groups') ),
937 ),
938 'setup_wizard' => array(
939 'title' => __('Setup Wizard', 'tag-groups'),
940 'page' => 'tag-groups-settings-setup-wizard',
941 'keywords' => array( __('getting started', 'tag-groups'), __('introduction', 'tag-groups'), __('sample', 'tag-groups') ),
942 ),
943 'first-aid' => array(
944 'title' => __('First Aid', 'tag-groups'),
945 'page' => 'tag-groups-settings-general',
946 'keywords' => array(
947 __('troubleshooting', 'tag-groups'),
948 __('migrate', 'tag-groups'),
949 __('help', 'tag-groups'),
950 __('problem', 'tag-groups'),
951 __('tag filter', 'tag-groups')
952 ),
953 ),
954 );
955 if (TagGroups_Gutenberg::is_gutenberg_active()) {
956 $topics['gutenberg'] = array(
957 'title' => __('Gutenberg', 'tag-groups'),
958 'page' => 'tag-groups-settings-back-end',
959 'keywords' => array( __('live block preview', 'tag-groups') ),
960 );
961 }
962 if (TagGroups_WPML::is_multilingual()) {
963 $topics['multilingual'] = array(
964 'title' => __('Multilingual', 'tag-groups'),
965 'page' => 'tag-groups-settings-back-end',
966 'keywords' => array( 'WPML', 'Polylang', __('translation', 'tag-groups') ),
967 );
968 }
969 $topics = apply_filters('tag_groups_setting_topics', $topics);
970 return $topics;
971 }
972
973 /**
974 * Renders the widget where you can search for help
975 *
976 * @param void
977 * @return void
978 */
979 public static function add_settings_help()
980 {
981 $topics = self::get_setting_topics();
982 asort($topics);
983 $view = new TagGroups_View('admin/settings_help');
984 $view->set('topics', $topics);
985 $view->render();
986 }
987
988 /**
989 * adds the processing of tasks
990 *
991 * @param void
992 * @return string
993 */
994 public static function add_html_process()
995 {
996 $tasks_whitelist = array(
997 'migratetermmeta' => __('Migrating the term meta', 'tag-groups'),
998 'fixgroups' => __('Fixing incorrect tag groups', 'tag-groups'),
999 'fixmissinggroups' => __('Fixing incorrect groups in term meta', 'tag-groups'),
1000 'sortgroups' => __('Sorting groups in term meta', 'tag-groups'),
1001 'checkbadterms' => __('Checking the tag names', 'tag-groups'),
1002 );
1003 $totals = array();
1004 $languages = array();
1005 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated -- Sanitized below
1006 $tasks = explode(',', wp_unslash($_POST['process-tasks']));
1007 $tasks = array_map('sanitize_title', $tasks);
1008 $tasks = array_intersect($tasks, array_keys($tasks_whitelist));
1009
1010 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Admin context
1011 if (!empty($_POST['task-set-name'])) {
1012 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Admin context
1013 $task_set_name = sanitize_text_field(wp_unslash($_POST['task-set-name']));
1014 } else {
1015 $task_set_name = '';
1016 }
1017
1018 $task_html = '';
1019 foreach ($tasks as $key => $task) {
1020 $totals[$task] = TagGroups_Process::get_task_total($task);
1021 $view = new TagGroups_View('admin/settings_troubleshooting_process_task_no_language');
1022 $view->set(array(
1023 'task' => $task,
1024 'tasks_whitelist' => $tasks_whitelist,
1025 ));
1026 $task_html .= $view->return_html();
1027 }
1028 /**
1029 * Add the Javascript part that loops through the tasks and through the chunks within each task
1030 *
1031 * Keep some timeout between the calls so that we don't block the browser
1032 * Parameters: chunk length and timeouts for chunk and task
1033 */
1034 $protocol = ( isset($_SERVER['HTTPS']) ? 'https://' : 'http://' );
1035 $ajax_link = admin_url('admin-ajax.php', $protocol);
1036
1037 if (defined('TAG_GROUPS_CHUNK_SIZE')) {
1038 $chunk_length = (int) TAG_GROUPS_CHUNK_SIZE;
1039 } else {
1040 $chunk_length = 30;
1041 }
1042
1043
1044 if (defined('TAG_GROUPS_CHUNK_TIMEOUT')) {
1045 $timeout_chunk = (int) TAG_GROUPS_CHUNK_TIMEOUT;
1046 } else {
1047 $timeout_chunk = 10 * 1000;
1048 // 10 seconds - for really slow networks
1049 }
1050
1051
1052 if (defined('TAG_GROUPS_TASK_TIMEOUT')) {
1053 $timeout_task = (int) TAG_GROUPS_TASK_TIMEOUT;
1054 } else {
1055 $timeout_task = 5 * 60 * 1000;
1056 // 5 minutes - can be long, but user needs to keep window open
1057 }
1058
1059 /**
1060 * The result messages will be revealed by the Javascript routine
1061 */
1062 $view = new TagGroups_View('admin/settings_troubleshooting_process');
1063 $view->set(array(
1064 'task_html' => $task_html,
1065 'ajax_link' => $ajax_link,
1066 'tasks' => $tasks,
1067 'totals' => $totals,
1068 'languages' => $languages,
1069 'timeout_task' => $timeout_task,
1070 'timeout_chunk' => $timeout_chunk,
1071 'chunk_length' => $chunk_length,
1072 'task_set_name' => $task_set_name,
1073 ));
1074 $view->render();
1075 }
1076 }
1077 }
1078