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

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