PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.44.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.44.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 3.6.2 All 177 releases
simple-tags / inc / post-tags.php

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

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