PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.51.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.51.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.51.0, at inc/post-tags.php

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