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

post-tags.php in Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms 3.50.0, at inc/post-tags.php

1,111 lines 70.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class SimpleTags_Post_Tags
4 {
5 public const MENU_SLUG = 'st_options';
6
7 // class instance
8 public static $instance;
9
10 // WP_List_Table object
11 public $terms_table;
12
13 /**
14 * Constructor
15 *
16 * @return void
17 * @author Olatechpro
18 */
19 public function __construct()
20 {
21
22 add_filter('set-screen-option', [__CLASS__, 'set_screen'], 10, 3);
23 // Admin menu
24 add_action('admin_menu', [$this, 'admin_menu']);
25
26 // Javascript
27 add_action('admin_enqueue_scripts', [__CLASS__, 'admin_enqueue_scripts'], 11);
28
29 add_action('wp_ajax_taxopress_posttags_preview', [$this, 'handle_posttags_preview']);
30 }
31
32 /**
33 * Init somes JS and CSS need for this feature
34 *
35 * @return void
36 * @author Olatechpro
37 */
38 public static function admin_enqueue_scripts()
39 {
40
41 // add JS for manage click tags
42 if (isset($_GET['page']) && $_GET['page'] == 'st_post_tags') {
43 wp_enqueue_style('st-taxonomies-css');
44 }
45 }
46
47 public static function set_screen($status, $option, $value)
48 {
49 return $value;
50 }
51
52 /** Singleton instance */
53 public static function get_instance()
54 {
55 if (!isset(self::$instance)) {
56 self::$instance = new self();
57 }
58
59 return self::$instance;
60 }
61
62 /**
63 * Add WP admin menu for Tags
64 *
65 * @return void
66 * @author Olatechpro
67 */
68 public function admin_menu()
69 {
70 $hook = add_submenu_page(
71 self::MENU_SLUG,
72 esc_html__('Terms for Current Post', 'simple-tags'),
73 esc_html__('Current Post', 'simple-tags'),
74 'simple_tags',
75 'st_post_tags',
76 [
77 $this,
78 'page_manage_posttags',
79 ]
80 );
81
82 if (taxopress_is_screen_main_page()) {
83 add_action("load-$hook", [$this, 'screen_option']);
84 }
85 }
86
87 /**
88 * Screen options
89 */
90 public function screen_option()
91 {
92
93 $option = 'per_page';
94 $args = [
95 'label' => esc_html__('Number of items per page', 'simple-tags'),
96 'default' => 20,
97 'option' => 'st_post_tags_per_page'
98 ];
99
100 add_screen_option($option, $args);
101
102 $this->terms_table = new PostTags_List();
103 }
104
105 /**
106 * Method for build the page HTML manage tags
107 *
108 * @return void
109 * @author Olatechpro
110 */
111 public function page_manage_posttags()
112 {
113 // Default order
114 if (!isset($_GET['order'])) {
115 $_GET['order'] = 'name-asc';
116 }
117
118 settings_errors(__CLASS__);
119
120 if (!isset($_GET['add'])) {
121 //all tax
122 ?>
123 <div class="wrap st_wrap st-manage-taxonomies-page">
124
125 <div id="">
126 <h1 class="wp-heading-inline"><?php esc_html_e('Terms for Current Post', 'simple-tags'); ?></h1>
127 <a href="<?php echo esc_url(admin_url('admin.php?page=st_post_tags&add=new_item')); ?>"
128 class="page-title-action taxopress">
129 <span class="dashicons dashicons-lock"></span>
130 <?php esc_html_e('Add New Terms for Current Post', 'simple-tags'); ?>
131 </a>
132
133 <div class="taxopress-description"><?php esc_html_e('This feature allows you create a customizable display of all the terms assigned to the current post.', 'simple-tags'); ?></div>
134
135
136 <?php
137 if (isset($_REQUEST['s']) && $search = sanitize_text_field(wp_unslash($_REQUEST['s']))) {
138 /* translators: %s: search keywords */
139 printf(' <span class="subtitle">' . esc_html__('Search results for &#8220;%s&#8221;', 'simple-tags') . '</span>', esc_html($search));
140 }
141 ?>
142 <?php
143
144 //the terms table instance
145 $this->terms_table->prepare_items();
146 ?>
147
148
149 <hr class="wp-header-end">
150 <div id="ajax-response"></div>
151 <form class="search-form wp-clearfix st-taxonomies-search-form" method="get">
152 <?php $this->terms_table->search_box(esc_html__('Search Terms for Current Post', 'simple-tags'), 'term'); ?>
153 </form>
154 <div class="clear"></div>
155
156 <div id="col-container" class="wp-clearfix">
157
158 <div class="col-wrap">
159 <form action="<?php echo esc_url(add_query_arg('', '')); ?>" method="post">
160 <?php $this->terms_table->display(); //Display the table
161 ?>
162 </form>
163 <div class="form-wrap edit-term-notes">
164 <p><?php esc_html__('Description here.', 'simple-tags') ?></p>
165 </div>
166 </div>
167
168
169 </div>
170
171
172 </div>
173 <?php } else {
174 if ($_GET['add'] == 'new_item') {
175 //add/edit taxonomy
176 $this->taxopress_manage_posttags();
177 echo '<div>';
178 }
179 } ?>
180
181
182 <?php SimpleTags_Admin::printAdminFooter(); ?>
183 </div>
184 <?php
185 }
186
187
188 /**
189 * Create our settings page output.
190 *
191 * @internal
192 */
193 public function taxopress_manage_posttags()
194 {
195
196 $tab = (!empty($_GET) && !empty($_GET['action']) && 'edit' == $_GET['action']) ? 'edit' : 'new';
197 $tab_class = 'taxopress-' . $tab;
198 $current = null;
199
200 ?>
201
202 <div class="wrap <?php echo esc_attr($tab_class); ?>">
203
204 <?php
205
206 $posttags = taxopress_get_posttags_data();
207 $post_tags_edit = false;
208 $post_tags_limit = false;
209
210 if ('edit' === $tab) {
211
212
213 $selected_posttags = taxopress_get_current_posttags();
214
215 if ($selected_posttags && array_key_exists($selected_posttags, $posttags)) {
216 $current = $posttags[$selected_posttags];
217 $post_tags_edit = true;
218 }
219 }
220
221
222 if (!isset($current['title']) && count($posttags) > 0 && apply_filters(
223 'taxopress_post_tags_create_limit',
224 true
225 )) {
226 $post_tags_limit = true;
227 }
228
229
230 $ui = new taxopress_admin_ui();
231 ?>
232
233
234 <div class="wrap <?php echo esc_attr($tab_class); ?>">
235 <h1><?php echo esc_html__('Manage Terms for Current Post', 'simple-tags'); ?></h1>
236 <div class="wp-clearfix"></div>
237
238 <form method="post" action="">
239
240
241 <div class="tagcloudui st-tabbed">
242
243 <?php
244 if (isset($_GET['action']) && $_GET['action'] === 'edit') : ?>
245 <div class="posttags-preview-container">
246 <div id="poststuff" class="taxopress-preview-box">
247 <div class="taxopress-section postbox">
248 <div class="postbox-header">
249 <h2 class="hndle ui-sortable-handle">
250 <?php echo esc_html__('Preview Terms for Current Post', 'simple-tags'); ?></h2>
251 <span class="taxopress-move-up dashicons dashicons-arrow-up-alt2"></span>
252 <span class="taxopress-move-down dashicons dashicons-arrow-down-alt2"></span>
253 <div class="handle-actions hide-if-no-js">
254 <button type="button" class="handlediv" aria-expanded="true">
255 <span class="screen-reader-text"><?php esc_html_e('Toggle panel', 'simple-tags'); ?></span>
256 <span class="toggle-indicator dashicons dashicons-arrow-down" aria-hidden="true"></span>
257 </button>
258 </div>
259 </div>
260
261 <div class="inside">
262 <div class="main">
263 <div class="taxopress-preview-content">
264 <div class="taxopress-preview-control">
265 <?php
266 $preview_post_id = isset($current['preview_post_id']) ? (int) $current['preview_post_id'] : 0;
267 $preview_post = $preview_post_id ? get_post($preview_post_id) : null;
268 ?>
269 <select id="posttags-preview-select" name="taxopress_post_tags[preview_post_id]" class="taxopress-post-preview-select">
270 <?php if ($preview_post) : ?>
271 <option value="<?php echo esc_attr($preview_post->ID); ?>" selected>
272 <?php echo esc_html($preview_post->post_title); ?>
273 </option>
274 <?php endif; ?>
275 </select>
276 <button type="button" class="button button-secondary preview-post-tags">
277 <?php esc_html_e('Preview', 'simple-tags'); ?>
278 </button>
279 <span class="spinner"></span>
280 </div>
281 <div class="taxopress-preview-results-content">
282 <!-- results -->
283 </div>
284 </div>
285 </div>
286 </div>
287 </div>
288 </div>
289 </div>
290 <?php endif; ?>
291
292
293 <div class="posttags-postbox-container">
294 <div id="poststuff">
295 <div class="taxopress-section postbox">
296 <div class="postbox-header">
297 <h2 class="hndle ui-sortable-handle">
298 <?php
299 if ($post_tags_edit) {
300 $enable_hidden_terms = SimpleTags_Plugin::get_option_value('enable_hidden_terms');
301 $active_tab = (isset($current['active_tab']) && !empty(trim($current['active_tab']))) ? $current['active_tab'] : 'posttags_general';
302 if ($active_tab === 'posttags_exceptions' && !$enable_hidden_terms) {
303 $active_tab = 'posttags_general';
304 }
305 echo esc_html__('Edit Terms for Current Post', 'simple-tags');
306 echo '<input type="hidden" name="edited_posttags" value="' . esc_attr($current['ID']) . '" />';
307 echo '<input type="hidden" name="taxopress_post_tags[ID]" value="' . esc_attr($current['ID']) . '" />';
308 echo '<input type="hidden" name="taxopress_post_tags[active_tab]" class="taxopress-active-subtab" value="' . esc_attr($active_tab) . '" />';
309 } else {
310 $active_tab = 'posttags_general';
311 echo '<input type="hidden" name="taxopress_post_tags[active_tab]" class="taxopress-active-subtab" value="" />';
312 echo esc_html__('Add new Terms for Current Post', 'simple-tags');
313 }
314 ?>
315 </h2>
316 </div>
317 <div class="inside">
318 <div class="main">
319
320
321 <?php if ($post_tags_limit) {
322 echo '<div class="st-taxonomy-content promo-box-area"><div class="taxopress-warning upgrade-pro">
323 <h2 style="margin-bottom: 5px;">' . esc_html__(
324 'To create more Terms for Current Post, please upgrade to TaxoPress Pro.',
325 'simple-tags'
326 ) . '</h2>
327 <p>
328
329 ' . esc_html__(
330 'With TaxoPress Pro, you can create unlimited Terms for Current Post. You can create Terms for Current Post for any taxonomy and then display those Terms for Current Post anywhere on your site.',
331 'simple-tags'
332 ) . '
333
334 </p>
335 </div></div>';
336 } else {
337 ?>
338
339
340 <ul class="taxopress-tab">
341 <li aria-current="<?php echo $active_tab === 'posttags_general' ? 'true' : 'false'; ?>" class="posttags_general_tab <?php echo $active_tab === 'posttags_general' ? 'active' : ''; ?>" data-content="posttags_general">
342 <a href="#posttags_general"><span><?php esc_html_e(
343 'General',
344 'simple-tags'
345 ); ?></span></a>
346 </li>
347
348 <li aria-current="<?php echo $active_tab === 'posttags_terms' ? 'true' : 'false'; ?>" class="posttags_terms_tab <?php echo $active_tab === 'posttags_terms' ? 'active' : ''; ?>" data-content="posttags_terms">
349 <a href="#posttags_terms"><span><?php esc_html_e('Choose Terms',
350 'simple-tags'); ?></span></a>
351 </li>
352
353 <li aria-current="<?php echo $active_tab === 'posttags_display' ? 'true' : 'false'; ?>" class="posttags_display_tab <?php echo $active_tab === 'posttags_display' ? 'active' : ''; ?>" data-content="posttags_display">
354 <a href="#posttags_display"><span><?php esc_html_e(
355 'Display',
356 'simple-tags'
357 ); ?></span></a>
358 </li>
359
360 <li aria-current="<?php echo $active_tab === 'posttags_layout' ? 'true' : 'false'; ?>" class="posttags_layout_tab <?php echo $active_tab === 'posttags_layout' ? 'active' : ''; ?>" data-content="posttags_layout">
361 <a href="#posttags_layout"><span><?php esc_html_e(
362 'Layout',
363 'simple-tags'
364 ); ?></span></a>
365 </li>
366
367 <li aria-current="<?php echo $active_tab === 'posttags_design' ? 'true' : 'false'; ?>" class="posttags_design_tab <?php echo $active_tab === 'posttags_design' ? 'active' : ''; ?>" data-content="posttags_design">
368 <a href="#posttags_design"><span><?php esc_html_e(
369 'Design',
370 'simple-tags'
371 ); ?></span></a>
372 </li>
373
374 <li aria-current="<?php echo $active_tab === 'posttags_options' ? 'true' : 'false'; ?>" class="posttags_options_tab <?php echo $active_tab === 'posttags_options' ? 'active' : ''; ?>" data-content="posttags_options">
375 <a href="#posttags_options"><span><?php esc_html_e(
376 'Options',
377 'simple-tags'
378 ); ?></span></a>
379 </li>
380
381 <li aria-current="<?php echo $active_tab === 'posttags_advanced' ? 'true' : 'false'; ?>" class="posttags_advanced_tab <?php echo $active_tab === 'posttags_advanced' ? 'active' : ''; ?>" data-content="posttags_advanced">
382 <a href="#posttags_advanced"><span><?php esc_html_e(
383 'Advanced',
384 'simple-tags'
385 ); ?></span></a>
386 </li>
387
388 <?php
389 $enable_hidden_terms = SimpleTags_Plugin::get_option_value('enable_hidden_terms');
390 if ($enable_hidden_terms) : ?>
391 <li aria-current="<?php echo $active_tab === 'posttags_exceptions' ? 'true' : 'false'; ?>" class="posttags_exceptions_tab <?php echo $active_tab === 'posttags_exceptions' ? 'active' : ''; ?>" data-content="posttags_exceptions">
392 <a href="#posttags_exceptions"><span><?php esc_html_e('Exceptions',
393 'simple-tags'); ?></span></a>
394 </li>
395 <?php endif; ?>
396
397 </ul>
398
399 <div class="st-taxonomy-content taxopress-tab-content">
400
401
402 <table class="form-table taxopress-table posttags_general" style="<?php echo $active_tab === 'posttags_general' ? '' : 'display:none;'; ?>">
403 <?php
404 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
405 echo $ui->get_tr_start();
406
407 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
408 echo $ui->get_th_start();
409 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
410 echo $ui->get_label('name', esc_html__('Title', 'simple-tags')) . $ui->get_required_span();
411 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
412 echo $ui->get_th_end() . $ui->get_td_start();
413
414 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
415 echo $ui->get_text_input([
416 'namearray' => 'taxopress_post_tags',
417 'name' => 'title',
418 'textvalue' => isset($current['title']) ? esc_attr($current['title']) : '',
419 'maxlength' => '32',
420 'helptext' => '',
421 'required' => true,
422 'placeholder' => false,
423 'wrap' => false,
424 ]);
425
426 $options = [];
427 $main_option = [];
428 $other_option = [];
429 foreach (get_all_taxopress_taxonomies() as $_taxonomy) {
430 $_taxonomy = $_taxonomy->name;
431 $tax = get_taxonomy($_taxonomy);
432 if (empty($tax->labels->name) || $_taxonomy === 'link_category') {
433 continue;
434 }
435 if ($tax->name === 'post_tag') {
436 $main_option[] = [
437 'attr' => $tax->name,
438 'text' => $tax->labels->name . ' (' . $tax->name . ')',
439 'default' => 'true'
440 ];
441 } else {
442 $other_option[] = [
443 'attr' => $tax->name,
444 'text' => $tax->labels->name . ' (' . $tax->name . ')'
445 ];
446 }
447 }
448 $options = array_merge($main_option, $other_option);
449
450 $select = [
451 'options' => $options,
452 ];
453 $selected = isset($current) ? taxopress_disp_boolean($current['taxonomy']) : '';
454 $select['selected'] = !empty($selected) ? $current['taxonomy'] : '';
455 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
456 echo $ui->get_select_checkbox_input_main([
457 'namearray' => 'taxopress_post_tags',
458 'name' => 'taxonomy',
459 'labeltext' => esc_html__('Taxonomy', 'simple-tags'),
460 'required' => true,
461 'selections' => $select, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
462 ]);
463
464
465 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
466 echo $ui->get_td_end() . $ui->get_tr_end();
467 ?>
468 </table>
469
470 <table class="form-table taxopress-table posttags_terms"
471 style="<?php echo $active_tab === 'posttags_terms' ? '' : 'display:none;'; ?>">
472 <?php
473
474 $select = [
475 'options' => [
476 [ 'attr' => '1', 'text' => esc_attr__('24 hours', 'simple-tags') ],
477 [ 'attr' => '7', 'text' => esc_attr__('7 days', 'simple-tags') ],
478 [ 'attr' => '14', 'text' => esc_attr__('2 weeks', 'simple-tags') ],
479 [ 'attr' => '30', 'text' => esc_attr__('1 month', 'simple-tags') ],
480 [ 'attr' => '180', 'text' => esc_attr__('6 months', 'simple-tags') ],
481 [ 'attr' => '365', 'text' => esc_attr__('1 year', 'simple-tags') ],
482 [ 'attr' => '0', 'text' => esc_attr__('No limit', 'simple-tags'), 'default' => 'true' ],
483 ],
484 ];
485 $selected = isset($current['limit_days']) ? taxopress_disp_boolean($current['limit_days']) : '';
486 $select['selected'] = ! empty($selected) ? $current['limit_days'] : '';
487 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
488 echo $ui->get_select_number_select([
489 'namearray' => 'taxopress_post_tags',
490 'name' => 'limit_days',
491 'labeltext' => esc_html__('Limit terms based on timeframe', 'simple-tags'),
492 'selections' => $select,// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
493 ]);
494
495 do_action('taxopress_posttags_ordering_method', $current);
496
497 $select = [
498 'options' => [
499 [ 'attr' => 'asc', 'text' => esc_attr__('Ascending', 'simple-tags') ],
500 [ 'attr' => 'desc', 'text' => esc_attr__('Descending', 'simple-tags'), 'default' => 'true' ],
501 ],
502 ];
503 $selected = isset($current['order']) ? taxopress_disp_boolean($current['order']) : '';
504 $select['selected'] = ! empty($selected) ? $current['order'] : '';
505 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
506 echo $ui->get_select_checkbox_input_main([
507 'namearray' => 'taxopress_post_tags',
508 'name' => 'order',
509 'labeltext' => esc_html__('Ordering for choosing terms for display', 'simple-tags'),
510 'selections' => $select,// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
511 ]);
512
513 ?>
514 </table>
515
516 <table class="form-table taxopress-table posttags_layout" style="<?php echo $active_tab === 'posttags_layout' ? '' : 'display:none;'; ?>">
517 <?php
518
519 apply_filters('taxopress_display_formats', $current);
520
521
522
523 ?>
524 </table>
525
526
527 <table class="form-table taxopress-table posttags_design" style="<?php echo $active_tab === 'posttags_design' ? '' : 'display:none;'; ?>">
528 <?php
529
530 echo $ui->get_number_input([
531 'namearray' => 'taxopress_post_tags',
532 'name' => 'smallest',
533 'textvalue' => isset($current['smallest']) ? esc_attr($current['smallest']) : '12',
534 'labeltext' => esc_html__('Font size minimum', 'simple-tags'),
535 'helptext' => '',
536 'required' => false,
537 ]);
538
539 echo $ui->get_number_input([
540 'namearray' => 'taxopress_post_tags',
541 'name' => 'largest',
542 'textvalue' => isset($current['largest']) ? esc_attr($current['largest']) : '12',
543 'labeltext' => esc_html__('Font size maximum', 'simple-tags'),
544 'helptext' => '',
545 'required' => false,
546 ]);
547
548 $select = [
549 'options' => [
550 [ 'attr' => 'pt', 'text' => esc_attr__('Point', 'simple-tags'), 'default' => 'true' ],
551 [ 'attr' => 'px', 'text' => esc_attr__('Pixel', 'simple-tags') ],
552 [ 'attr' => 'em', 'text' => esc_attr__('Em', 'simple-tags') ],
553 [ 'attr' => '%', 'text' => esc_attr__('Percent', 'simple-tags') ],
554 ],
555 ];
556 $selected = isset($current['unit']) ? taxopress_disp_boolean($current['unit']) : '';
557 $select['selected'] = !empty($selected) ? $current['unit'] : '';
558 echo $ui->get_select_checkbox_input_main([
559 'namearray' => 'taxopress_post_tags',
560 'name' => 'unit',
561 'labeltext' => esc_html__('Unit font size', 'simple-tags'),
562 'selections' => $select,
563 ]);
564
565 $select = [
566 'options' => [
567 [
568 'attr' => '0',
569 'text' => esc_attr__('False', 'simple-tags'),
570 'default' => 'true',
571 ],
572 [
573 'attr' => '1',
574 'text' => esc_attr__('True', 'simple-tags'),
575 ],
576 ],
577 ];
578 $selected = (isset($current) && isset($current['color'])) ? taxopress_disp_boolean($current['color']) : '';
579 $select['selected'] = !empty($selected) ? $current['color'] : '';
580 echo $ui->get_select_checkbox_input([
581 'namearray' => 'taxopress_post_tags',
582 'name' => 'color',
583 'class' => 'posttags-color-option',
584 'labeltext' => esc_html__('Enable colors for terms', 'simple-tags'),
585 'selections' => $select,
586 ]);
587
588
589 echo $ui->get_text_input([
590 'namearray' => 'taxopress_post_tags',
591 'name' => 'mincolor',
592 'class' => 'text-color post-tag-min',
593 'textvalue' => isset($current['mincolor']) ? esc_attr($current['mincolor']) : '#353535',
594 'labeltext' => esc_html__('Font color minimum', 'simple-tags'),
595 'helptext' => esc_html__('This is the color of the least popular term.', 'simple-tags'),
596 'required' => true,
597 ]);
598
599 echo $ui->get_text_input([
600 'namearray' => 'taxopress_post_tags',
601 'name' => 'maxcolor',
602 'class' => 'text-color post-tag-max',
603 'textvalue' => isset($current['maxcolor']) ? esc_attr($current['maxcolor']) : '#000000',
604 'labeltext' => esc_html__('Font color maximum', 'simple-tags'),
605 'helptext' => esc_html__('This is the color of the most popular term.', 'simple-tags'),
606 'required' => true,
607 ]);
608
609 ?>
610 </table>
611
612
613
614
615 <table class="form-table taxopress-table posttags_display" style="<?php echo $active_tab === 'posttags_display' ? '' : 'display:none;'; ?>">
616 <?php
617
618 /**
619 * Filters the arguments for post types to list for taxonomy association.
620 *
621 *
622 * @param array $value Array of default arguments.
623 */
624 $args = apply_filters(
625 'taxopress_attach_post_types_to_taxonomy',
626 ['public' => true]
627 );
628
629 // If they don't return an array, fall back to the original default. Don't need to check for empty, because empty array is default for $args param in get_post_types anyway.
630 if (!is_array($args)) {
631 $args = ['public' => true];
632 }
633 $output = 'objects'; // Or objects.
634
635 /**
636 * Filters the results returned to display for available post types for taxonomy.
637 *
638 * @param array $value Array of post type objects.
639 * @param array $args Array of arguments for the post type query.
640 * @param string $output The output type we want for the results.
641 */
642 $post_types = apply_filters(
643 'taxopress_get_post_types_for_taxonomies',
644 get_post_types($args, $output),
645 $args,
646 $output
647 );
648
649 $term_auto_locations = [
650 'homeonly' => esc_attr__('Homepage', 'simple-tags'),
651 'blogonly' => esc_attr__('Blog display', 'simple-tags'),
652 ];
653 foreach ($post_types as $post_type) {
654 if (!in_array($post_type->name, ['attachment'])) {
655 $term_auto_locations[$post_type->name] = $post_type->label;
656 }
657 }
658
659 echo '<tr valign="top"><th scope="row"><label>' . esc_html__(
660 'Attempt to automatically display terms',
661 'simple-tags'
662 ) . '</label><br /><small style=" color: #646970;">' . esc_html__(
663 'TaxoPress will attempt to automatically display terms in this content. It may not be successful for all post types and layouts.',
664 'simple-tags'
665 ) . '</small></th><td>
666 <table class="visbile-table">';
667 foreach ($term_auto_locations as $key => $value) {
668
669
670 echo '<tr valign="top"><th scope="row"><label for="' . esc_attr($key) . '">' . esc_html($value) . '</label></th><td>';
671
672 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
673 echo $ui->get_check_input([
674 'checkvalue' => $key,
675 'checked' => (!empty($current['embedded']) && is_array($current['embedded']) && in_array(
676 $key,
677 $current['embedded'],
678 true
679 )) ? 'true' : 'false',
680 'name' => esc_attr($key),
681 'namearray' => 'embedded',
682 'textvalue' => esc_attr($key),
683 'labeltext' => "",
684 'wrap' => false,
685 ]);
686
687 echo '</td></tr>';
688
689 if ($key === 'blogonly') {
690 echo '<tr valign="top"><th style="padding: 0;" scope="row"><hr /></th><td style="padding: 0;"><hr /></td></tr>';
691 }
692 }
693 echo '</table></td></tr>';
694
695
696 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
697 echo $ui->get_number_input([
698 'namearray' => 'taxopress_post_tags',
699 'name' => 'number',
700 'textvalue' => isset($current['number']) ? esc_attr($current['number']) : '0',
701 'labeltext' => esc_html__(
702 'Maximum terms to display',
703 'simple-tags'
704 ),
705 'helptext' => esc_html__(
706 'You must set zero (0) to display all post tags.',
707 'simple-tags'
708 ),
709 'min' => '0',
710 'required' => true,
711 ]);
712
713 ?>
714 </table>
715
716
717 <table class="form-table taxopress-table posttags_options" style="<?php echo $active_tab === 'posttags_options' ? '' : 'display:none;'; ?>">
718 <?php
719
720 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
721 echo $ui->get_text_input([
722 'namearray' => 'taxopress_post_tags',
723 'name' => 'separator',
724 'textvalue' => isset($current['separator']) ? esc_attr($current['separator']) : ', ',
725 'labeltext' => esc_html__(
726 'Post term separator string: ',
727 'simple-tags'
728 ),
729 'helptext' => '',
730 'required' => false,
731 ]);
732
733 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
734 echo $ui->get_text_input([
735 'namearray' => 'taxopress_post_tags',
736 'name' => 'before',
737 'textvalue' => isset($current['before']) ? esc_attr($current['before']) : 'Tags: ',
738 'labeltext' => esc_html__(
739 'Text to display before terms list',
740 'simple-tags'
741 ),
742 'helptext' => esc_html__(
743 'Enter the text that should be display before terms list. This field accepts basic HTML.',
744 'simple-tags'
745 ),
746 'required' => false,
747 ]);
748
749 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
750 echo $ui->get_text_input([
751 'namearray' => 'taxopress_post_tags',
752 'name' => 'after',
753 'textvalue' => isset($current['after']) ? esc_attr($current['after']) : '<br />',
754 'labeltext' => esc_html__(
755 'Text to display after terms list',
756 'simple-tags'
757 ),
758 'helptext' => esc_html__(
759 'Enter the text that should be display after terms list. This field accepts basic HTML.',
760 'simple-tags'
761 ),
762 'required' => false,
763 ]);
764
765 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
766 echo $ui->get_text_input([
767 'namearray' => 'taxopress_post_tags',
768 'name' => 'notagtext',
769 'textvalue' => isset($current['notagtext']) ? esc_attr($current['notagtext']) : 'No tags for this post.',
770 'labeltext' => esc_html__(
771 'Text to display if no terms found',
772 'simple-tags'
773 ),
774 'helptext' => '',
775 'required' => false,
776 ]);
777
778 $select = [
779 'options' => [
780 [
781 'attr' => '0',
782 'text' => esc_attr__('False', 'simple-tags'),
783 'default' => 'true',
784 ],
785 [
786 'attr' => '1',
787 'text' => esc_attr__('True', 'simple-tags'),
788 ],
789 ],
790 ];
791 $selected = (isset($current) && isset($current['hide_output'])) ? taxopress_disp_boolean($current['hide_output']) : '';
792 $select['selected'] = !empty($selected) ? $current['hide_output'] : '';
793 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
794 echo $ui->get_select_checkbox_input([
795 'namearray' => 'taxopress_post_tags',
796 'name' => 'hide_output',
797 'labeltext' => esc_html__(
798 'Hide display output if no terms ?',
799 'simple-tags'
800 ),
801 'selections' => $select, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
802 ]);
803 ?>
804
805 </table>
806
807
808 <table class="form-table taxopress-table posttags_advanced" style="<?php echo $active_tab === 'posttags_advanced' ? '' : 'display:none;'; ?>">
809 <?php
810
811
812 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
813 echo $ui->get_text_input([
814 'namearray' => 'taxopress_post_tags',
815 'name' => 'wrap_class',
816 'class' => '',
817 'textvalue' => isset($current['wrap_class']) ? esc_attr($current['wrap_class']) : '',
818 'labeltext' => esc_html__('Terms for Current Post div class', 'simple-tags'),
819 'helptext' => '',
820 'required' => false,
821 ]);
822
823 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
824 echo $ui->get_text_input([
825 'namearray' => 'taxopress_post_tags',
826 'name' => 'link_class',
827 'class' => '',
828 'textvalue' => isset($current['link_class']) ? esc_attr($current['link_class']) : '',
829 'labeltext' => esc_html__('Term link class', 'simple-tags'),
830 'helptext' => '',
831 'required' => false,
832 ]);
833
834 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
835 echo $ui->get_textarea_input([
836 'namearray' => 'taxopress_post_tags',
837 'name' => 'xformat',
838 'class' => 'st-full-width',
839 'rows' => '4',
840 'cols' => '40',
841 'textvalue' => isset($current['xformat']) ? esc_attr($current['xformat']) : esc_attr('<a href="%tag_link%" title="%tag_name%" class="st-post-tags t%tag_scale%" style="%tag_size% %tag_color%" %tag_rel%>%tag_name%</a>'),
842 'labeltext' => esc_html__('Term link format', 'simple-tags'),
843 'helptext' => sprintf(esc_html__('You can find markers and explanations %1sin the documentation%2s.', 'simple-tags'), '<a target="blank" href="https://taxopress.com/docs/format-terms-current-post/">', '</a>'),
844 'required' => false,
845 ]);
846
847 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
848 echo $ui->get_td_end() . $ui->get_tr_end();
849
850 ?>
851 </table>
852 <?php
853 $enable_hidden_terms = SimpleTags_Plugin::get_option_value('enable_hidden_terms');
854 if ($enable_hidden_terms) : ?>
855 <table class="form-table taxopress-table posttags_exceptions" style="<?php echo $active_tab === 'posttags_exceptions' ? '' : 'display:none;'; ?>">
856 <?php
857
858 $enable_hidden_terms = SimpleTags_Plugin::get_option_value('enable_hidden_terms');
859
860 if ($enable_hidden_terms) {
861 $select = [
862 'options' => [
863 [
864 'attr' => '0',
865 'text' => esc_attr__('False', 'simple-tags'),
866 'default' => 'true',
867 ],
868 [
869 'attr' => '1',
870 'text' => esc_attr__('True', 'simple-tags'),
871 ],
872 ],
873 ];
874
875 $selected = isset($current['hide_terms']) ? taxopress_disp_boolean($current['hide_terms']) : '0';
876 $select['selected'] = !empty($selected) ? $selected : '0';
877
878 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
879 echo $ui->get_select_checkbox_input([
880 'namearray' => 'taxopress_post_tags',
881 'name' => 'hide_terms',
882 'labeltext' => esc_html__('Exclude hidden terms from Current Post?', 'simple-tags'),
883 'selections' => $select, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
884 ]);
885 } else {
886 if (isset($current['hide_terms']) && $current['hide_terms'] !== '0') {
887 $current['hide_terms'] = '0';
888 }
889 }
890
891 ?>
892 </table>
893 <?php endif; ?>
894
895 </div>
896
897
898 <?php } //end new fields
899 ?>
900
901
902 <div class="clear"></div>
903
904
905 </div>
906 </div>
907 </div>
908
909
910 <?php if ($post_tags_limit) { ?>
911
912 <div class="pp-version-notice-bold-purple" style="margin-left:0px;">
913 <div class="pp-version-notice-bold-purple-message"><?php echo esc_html__('You\'re using TaxoPress Free.
914 The Pro version has more features and support.', 'simple-tags'); ?>
915 </div>
916 <div class="pp-version-notice-bold-purple-button"><a href="https://taxopress.com/taxopress/" target="_blank"><?php echo esc_html__('Upgrade to Pro', 'simple-tags'); ?></a>
917 </div>
918 </div>
919
920 <?php } ?>
921 <?php
922 /**
923 * Fires after the default fieldsets on the taxonomy screen.
924 *
925 * @param taxopress_admin_ui $ui Admin UI instance.
926 */
927 do_action('taxopress_taxonomy_after_fieldsets', $ui);
928 ?>
929
930 </div>
931 </div>
932
933
934 </div>
935
936 <div class="taxopress-right-sidebar">
937 <div class="taxopress-right-sidebar-wrapper" style="min-height: 205px;<?php echo ($post_tags_limit) ? 'display: none;' : ''; ?>">
938
939
940 <?php
941 if (!$post_tags_limit) { ?>
942 <p class="submit">
943
944 <?php
945 wp_nonce_field(
946 'taxopress_addedit_posttags_nonce_action',
947 'taxopress_addedit_posttags_nonce_field'
948 );
949 if (!empty($_GET) && !empty($_GET['action']) && 'edit' === $_GET['action']) { ?>
950 <input type="submit" class="button-primary taxopress-taxonomy-submit taxopress-posttags-submit" name="posttags_submit" value="<?php echo esc_attr(esc_attr__(
951 'Save Terms for Current Post',
952 'simple-tags'
953 )); ?>" />
954 <?php
955 } else { ?>
956 <input type="submit" class="button-primary taxopress-taxonomy-submit taxopress-posttags-submit" name="posttags_submit" value="<?php echo esc_attr(esc_attr__(
957 'Add Terms for Current Post',
958 'simple-tags'
959 )); ?>" />
960 <?php } ?>
961
962 <input type="hidden" name="cpt_tax_status" id="cpt_tax_status" value="<?php echo esc_attr($tab); ?>" />
963 </p>
964
965 <?php if (!empty($current)) {
966 ?>
967 <p>
968 <?php echo '<div class="taxopress-warning" style="">' . esc_html__(
969 'Shortcode: ',
970 'simple-tags'
971 ); ?> &nbsp;
972 <textarea style="resize: none;padding: 5px;" readonly>[taxopress_postterms id="<?php echo (int)$current['ID']; ?>"]</textarea>
973 </div>
974 </p>
975 <?php } ?>
976
977 <?php
978 }
979 ?>
980
981 </div>
982
983 <div class="taxopress-token-right-sidebar">
984 <div id="postbox-container-1" class="postbox-container">
985 <div class="meta-box-sortables">
986 <div class="postbox">
987 <div class="postbox-header">
988 <h3 class="hndle is-non-sortable">
989 <span><?php echo esc_html__('Terms for Current Post', 'simple-tags'); ?></span>
990 </h3>
991 </div>
992
993 <div class="inside">
994 <p><?php echo esc_html__('Here are the tokens you can use for Terms for Current Post format', 'simple-tags'); ?>:</p>
995 <ul>
996 <li><code>%tag_link%</code><?php echo esc_html__('The URL of the tag', 'simple-tags'); ?></li>
997 <li><code>%tag_name%</code><?php echo esc_html__('The name of the tag', 'simple-tags'); ?></li>
998 <li><code>%tag_rel% </code><?php echo esc_html__('This provides rel tag markup', 'simple-tags'); ?> (it creates <code>rel="tag"</code>)</li>
999 <li><code>%tag_feed%</code><?php echo esc_html__('Replaced by the RSS tag link', 'simple-tags'); ?></li>
1000 <li><code>%tag_id%</code><?php echo esc_html__('Replaced by the tag ID', 'simple-tags'); ?></li>
1001 <li><code>%tag_name_attribute%</code><?php echo esc_html__('Replaced by the tag’s name, formatted for attribute HTML', 'simple-tags'); ?></li>
1002 <li><code>%tag_description%</code> – <?php echo esc_html__('The description of the tag', 'simple-tags'); ?></li>
1003 <li><code>%tag_size%</code> – <?php echo esc_html__('The font size of the tag', 'simple-tags'); ?></li>
1004 <li><code>%tag_color%</code> – <?php echo esc_html__('The font color of the tag', 'simple-tags'); ?></li>
1005 </ul>
1006 <p><?php echo esc_html__('You can also add HTML elements to the formatting.', 'simple-tags'); ?></p>
1007 </div>
1008 </div>
1009 </div>
1010 </div>
1011 </div>
1012
1013 <?php do_action('taxopress_admin_after_sidebar'); ?>
1014 </div>
1015
1016 <div class="clear"></div>
1017
1018
1019
1020 </form>
1021
1022 </div><!-- End .wrap -->
1023
1024 <div class="clear"></div>
1025
1026 <?php # Modal Windows;
1027 ?>
1028 <div class="remodal" data-remodal-id="taxopress-modal-alert" data-remodal-options="hashTracking: false, closeOnOutsideClick: false">
1029 <div class="" style="color:red;"><?php echo esc_html__('Please complete the following required fields to save your changes:', 'simple-tags'); ?></div>
1030 <div id="taxopress-modal-alert-content"></div>
1031 <br>
1032 <button data-remodal-action="cancel" class="remodal-cancel"><?php echo esc_html__('Okay', 'simple-tags'); ?></button>
1033 </div>
1034
1035 <div class="remodal" data-remodal-id="taxopress-modal-confirm" data-remodal-options="hashTracking: false, closeOnOutsideClick: false">
1036 <div id="taxopress-modal-confirm-content"></div>
1037 <br>
1038 <button data-remodal-action="cancel" class="remodal-cancel"><?php echo esc_html__('No', 'simple-tags'); ?></button>
1039 <button data-remodal-action="confirm" class="remodal-confirm"><?php echo esc_html__('Yes', 'simple-tags'); ?></button>
1040 </div>
1041
1042 <?php
1043 }
1044
1045 public function handle_posttags_preview()
1046 {
1047 if (!check_ajax_referer('st-admin-js', 'nonce', false)) {
1048 wp_send_json_error(['message' => __('Security check failed.', 'simple-tags')]);
1049 }
1050
1051 if (!current_user_can('simple_tags')) {
1052 wp_send_json_error(['message' => __('Permission denied.', 'simple-tags')]);
1053 }
1054
1055 $post_id = isset($_POST['preview_post_id']) ? intval($_POST['preview_post_id']) : 0;
1056 if (!$post_id) {
1057 wp_send_json_error([
1058 'html' => '<p class="taxopress-preview-message error">' .
1059 esc_html__('Select a post to see a preview.', 'simple-tags') .
1060 '</p>'
1061 ]);
1062 }
1063
1064 // Get current settings
1065 $settings = isset($_POST['taxopress_post_tags']) ? wp_unslash($_POST['taxopress_post_tags']) : [];
1066
1067 $args = [
1068 'before' => isset($settings['before']) ? wp_kses_post($settings['before']) : '',
1069 'separator' => isset($settings['separator']) ? sanitize_text_field($settings['separator']) : ', ',
1070 'after' => isset($settings['after']) ? wp_kses_post($settings['after']) : '',
1071 'post_id' => $post_id,
1072 'inc_cats' => isset($settings['inc_cats']) ? (int)$settings['inc_cats'] : 0,
1073 'xformat' => isset($settings['xformat']) ? wp_kses_post($settings['xformat']) : '',
1074 'notagtext' => isset($settings['notagtext']) ? wp_kses_post($settings['notagtext']) : '',
1075 'number' => isset($settings['number']) ? (int)$settings['number'] : 0,
1076 'ID' => isset($settings['ID']) ? (bool)$settings['ID'] : false,
1077 'taxonomy' => isset($settings['taxonomy']) ? sanitize_text_field($settings['taxonomy']) : false,
1078 'hide_output' => isset($settings['hide_output']) ? (int)$settings['hide_output'] : 0,
1079 'wrap_class' => isset($settings['wrap_class']) ? sanitize_html_class($settings['wrap_class']) : '',
1080 'link_class' => isset($settings['link_class']) ? sanitize_html_class($settings['link_class']) : '',
1081 'hide_terms' => isset($settings['hide_terms']) ? (int)$settings['hide_terms'] : 0,
1082 'format' => isset($settings['format']) ? sanitize_text_field($settings['format']) : 'flat',
1083 'smallest' => isset($settings['smallest']) ? (int)$settings['smallest'] : 12,
1084 'largest' => isset($settings['largest']) ? (int)$settings['largest'] : 12,
1085 'unit' => isset($settings['unit']) ? sanitize_text_field($settings['unit']) : 'pt',
1086 'color' => isset($settings['color']) ? (int)$settings['color'] : true,
1087 'mincolor' => isset($settings['mincolor']) ? sanitize_hex_color($settings['mincolor']) : '#353535',
1088 'maxcolor' => isset($settings['maxcolor']) ? sanitize_hex_color($settings['maxcolor']) : '#000000',
1089 'selectionby' => isset($settings['selectionby']) ? sanitize_text_field($settings['selectionby']) : 'count',
1090 'selection' => isset($settings['selection']) ? sanitize_text_field($settings['selection']) : 'desc',
1091 'orderby' => isset($settings['orderby']) ? sanitize_text_field($settings['orderby']) : 'name',
1092 'order' => isset($settings['order']) ? sanitize_text_field($settings['order']) : 'asc',
1093 'limit_days' => isset($settings['limit_days']) ? (int)$settings['limit_days'] : 0,
1094 ];
1095
1096 $output = SimpleTags_Client_PostTags::extendedPostTags($args, false);
1097
1098 if (empty($output)) {
1099 if (!empty($settings['hide_output'])) {
1100 wp_send_json_success(['html' => '']);
1101 }
1102 $notagtext = !empty($settings['notagtext']) ? $settings['notagtext'] : __('No terms found for this post.', 'simple-tags');
1103 wp_send_json_success(['html' => '<div class="taxopress-no-tags-message">' . esc_html($notagtext) . '</div>']);
1104 return;
1105 }
1106
1107 wp_send_json_success(['html' => $output]);
1108 }
1109
1110 }
1111