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

642 lines 34.9 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 }
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__('Terms for 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 _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"><?php esc_html_e('Add New', 'simple-tags'); ?></a>
129
130 <div class="taxopress-description"><?php _e('This feature allows you create a customizable display of all the terms assigned to the current post.', 'simple-tags'); ?></div>
131
132
133 <?php
134 if (isset($_REQUEST['s']) && $search = sanitize_text_field(wp_unslash($_REQUEST['s']))) {
135 /* translators: %s: search keywords */
136 printf(' <span class="subtitle">' . esc_html__('Search results for &#8220;%s&#8221;', 'simple-tags') . '</span>', esc_html($search));
137 }
138 ?>
139 <?php
140
141 //the terms table instance
142 $this->terms_table->prepare_items();
143 ?>
144
145
146 <hr class="wp-header-end">
147 <div id="ajax-response"></div>
148 <form class="search-form wp-clearfix st-taxonomies-search-form" method="get">
149 <?php $this->terms_table->search_box(esc_html__('Search Terms for Current Post', 'simple-tags'), 'term'); ?>
150 </form>
151 <div class="clear"></div>
152
153 <div id="col-container" class="wp-clearfix">
154
155 <div class="col-wrap">
156 <form action="<?php echo esc_url(add_query_arg('', '')); ?>" method="post">
157 <?php $this->terms_table->display(); //Display the table ?>
158 </form>
159 <div class="form-wrap edit-term-notes">
160 <p><?php esc_html__('Description here.', 'simple-tags') ?></p>
161 </div>
162 </div>
163
164
165 </div>
166
167
168 </div>
169 <?php } else {
170 if ($_GET['add'] == 'new_item') {
171 //add/edit taxonomy
172 $this->taxopress_manage_posttags();
173 echo '<div>';
174 }
175 } ?>
176
177
178 <?php SimpleTags_Admin::printAdminFooter(); ?>
179 </div>
180 <?php
181 }
182
183
184 /**
185 * Create our settings page output.
186 *
187 * @internal
188 */
189 public function taxopress_manage_posttags()
190 {
191
192 $tab = (!empty($_GET) && !empty($_GET['action']) && 'edit' == $_GET['action']) ? 'edit' : 'new';
193 $tab_class = 'taxopress-' . $tab;
194 $current = null;
195
196 ?>
197
198 <div class="wrap <?php echo esc_attr($tab_class); ?>">
199
200 <?php
201
202 $posttags = taxopress_get_posttags_data();
203 $post_tags_edit = false;
204 $post_tags_limit = false;
205
206 if ('edit' === $tab) {
207
208
209 $selected_posttags = taxopress_get_current_posttags();
210
211 if ($selected_posttags && array_key_exists($selected_posttags, $posttags)) {
212 $current = $posttags[$selected_posttags];
213 $post_tags_edit = true;
214 }
215
216 }
217
218
219 if (!isset($current['title']) && count($posttags) > 0 && apply_filters('taxopress_post_tags_create_limit',
220 true)) {
221 $post_tags_limit = true;
222 }
223
224
225 $ui = new taxopress_admin_ui();
226 ?>
227
228
229 <div class="wrap <?php echo esc_attr($tab_class); ?>">
230 <h1><?php echo esc_html__('Manage Terms for Current Post', 'simple-tags'); ?></h1>
231 <div class="wp-clearfix"></div>
232
233 <form method="post" action="">
234
235
236 <div class="tagcloudui">
237
238
239 <div class="posttags-postbox-container">
240 <div id="poststuff">
241 <div class="taxopress-section postbox">
242 <div class="postbox-header">
243 <h2 class="hndle ui-sortable-handle">
244 <?php
245 if ($post_tags_edit) {
246 echo esc_html__('Edit Terms for Current Post', 'simple-tags');
247 echo '<input type="hidden" name="edited_posttags" value="' . esc_attr($current['ID']) . '" />';
248 echo '<input type="hidden" name="taxopress_post_tags[ID]" value="' . esc_attr($current['ID']) . '" />';
249 } else {
250 echo esc_html__('Add new Terms for Current Post', 'simple-tags');
251 }
252 ?>
253 </h2>
254 </div>
255 <div class="inside">
256 <div class="main">
257
258
259 <div class="st-taxonomy-content">
260
261 <?php if ($post_tags_limit) {
262 echo '<div class="taxopress-warning upgrade-pro">
263 <p>
264
265 <h2 style="margin-bottom: 5px;">' . esc_html__('To create more Terms for Current Post, please upgrade to TaxoPress Pro.',
266 'simple-tags') . '</h2>
267 ' . esc_html__('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.',
268 'simple-tags') . '
269
270 </p>
271 </div>';
272
273 } else {
274 ?>
275 <table class="form-table taxopress-table">
276 <?php
277 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
278 echo $ui->get_tr_start();
279
280 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
281 echo $ui->get_th_start();
282 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
283 echo $ui->get_label('name', esc_html__('Title', 'simple-tags')) . $ui->get_required_span();
284 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
285 echo $ui->get_th_end() . $ui->get_td_start();
286
287 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
288 echo $ui->get_text_input([
289 'namearray' => 'taxopress_post_tags',
290 'name' => 'title',
291 'textvalue' => isset($current['title']) ? esc_attr($current['title']) : '',
292 'maxlength' => '32',
293 'helptext' => '',
294 'required' => true,
295 'placeholder' => false,
296 'wrap' => false,
297 ]);
298
299 $options = [];
300 $main_option = [];
301 $other_option = [];
302 foreach (get_all_taxopress_taxonomies() as $_taxonomy) {
303 $_taxonomy = $_taxonomy->name;
304 $tax = get_taxonomy($_taxonomy);
305 if (empty($tax->labels->name)) {
306 continue;
307 }
308 if ($tax->name === 'post_tag') {
309 $main_option[] = [
310 'attr' => $tax->name,
311 'text' => $tax->labels->name. ' ('.$tax->name.')',
312 'default' => 'true'
313 ];
314 } else {
315 $other_option[] = [
316 'attr' => $tax->name,
317 'text' => $tax->labels->name. ' ('.$tax->name.')'
318 ];
319 }
320 }
321 $options = array_merge($main_option, $other_option);
322
323 $select = [
324 'options' => $options,
325 ];
326 $selected = isset($current) ? taxopress_disp_boolean($current['taxonomy']) : '';
327 $select['selected'] = !empty($selected) ? $current['taxonomy'] : '';
328 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
329 echo $ui->get_select_checkbox_input_main([
330 'namearray' => 'taxopress_post_tags',
331 'name' => 'taxonomy',
332 'labeltext' => esc_html__('Taxonomy', 'simple-tags'),
333 'required' => true,
334 'selections' => $select, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
335 ]);
336
337
338 /**
339 * Filters the arguments for post types to list for taxonomy association.
340 *
341 *
342 * @param array $value Array of default arguments.
343 */
344 $args = apply_filters('taxopress_attach_post_types_to_taxonomy',
345 ['public' => true]);
346
347 // 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.
348 if (!is_array($args)) {
349 $args = ['public' => true];
350 }
351 $output = 'objects'; // Or objects.
352
353 /**
354 * Filters the results returned to display for available post types for taxonomy.
355 *
356 * @param array $value Array of post type objects.
357 * @param array $args Array of arguments for the post type query.
358 * @param string $output The output type we want for the results.
359 */
360 $post_types = apply_filters('taxopress_get_post_types_for_taxonomies',
361 get_post_types($args, $output), $args, $output);
362
363 $term_auto_locations = [
364 'homeonly' => esc_attr__('Homepage', 'simple-tags'),
365 'blogonly' => esc_attr__('Blog display', 'simple-tags'),
366 ];
367 foreach ($post_types as $post_type) {
368 $term_auto_locations[$post_type->name] = $post_type->label;
369 }
370
371 echo '<tr valign="top"><th scope="row"><label>' . esc_html__('Attempt to automatically display terms',
372 'simple-tags') . '</label><br /><small style=" color: #646970;">' . esc_html__('TaxoPress will attempt to automatically display terms in this content. It may not be successful for all post types and layouts.',
373 'simple-tags') . '</small></th><td>
374 <table>';
375 foreach ($term_auto_locations as $key => $value) {
376
377
378 echo '<tr valign="top"><th scope="row"><label for="' . esc_attr($key) . '">' . esc_html($value) . '</label></th><td>';
379
380 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
381 echo $ui->get_check_input([
382 'checkvalue' => $key,
383 'checked' => (!empty($current['embedded']) && is_array($current['embedded']) && in_array($key,
384 $current['embedded'], true)) ? 'true' : 'false',
385 'name' => esc_attr($key),
386 'namearray' => 'embedded',
387 'textvalue' => esc_attr($key),
388 'labeltext' => "",
389 'wrap' => false,
390 ]);
391
392 echo '</td></tr>';
393
394 if ($key === 'blogonly') {
395 echo '<tr valign="top"><th style="padding: 0;" scope="row"><hr /></th><td style="padding: 0;"><hr /></td></tr>';
396 }
397
398
399 }
400 echo '</table></td></tr>';
401
402
403 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
404 echo $ui->get_number_input([
405 'namearray' => 'taxopress_post_tags',
406 'name' => 'number',
407 'textvalue' => isset($current['number']) ? esc_attr($current['number']) : '0',
408 'labeltext' => esc_html__('Maximum terms to display',
409 'simple-tags'),
410 'helptext' => esc_html__('You must set zero (0) to display all post tags.',
411 'simple-tags'),
412 'min' => '0',
413 'required' => true,
414 ]);
415
416 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
417 echo $ui->get_text_input([
418 'namearray' => 'taxopress_post_tags',
419 'name' => 'separator',
420 'textvalue' => isset($current['separator']) ? esc_attr($current['separator']) : ', ',
421 'labeltext' => esc_html__('Post term separator string: ',
422 'simple-tags'),
423 'helptext' => '',
424 'required' => false,
425 ]);
426
427 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
428 echo $ui->get_text_input([
429 'namearray' => 'taxopress_post_tags',
430 'name' => 'after',
431 'textvalue' => isset($current['after']) ? esc_attr($current['after']) : '<br />',
432 'labeltext' => esc_html__('Text to display after tags list',
433 'simple-tags'),
434 'helptext' => '',
435 'required' => false,
436 ]);
437
438 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
439 echo $ui->get_text_input([
440 'namearray' => 'taxopress_post_tags',
441 'name' => 'before',
442 'textvalue' => isset($current['before']) ? esc_attr($current['before']) : 'Tags: ',
443 'labeltext' => esc_html__('Text to display before tags list',
444 'simple-tags'),
445 'helptext' => '',
446 'required' => false,
447 ]);
448
449 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
450 echo $ui->get_text_input([
451 'namearray' => 'taxopress_post_tags',
452 'name' => 'notagtext',
453 'textvalue' => isset($current['notagtext']) ? esc_attr($current['notagtext']) : 'No tags for this post.',
454 'labeltext' => esc_html__('Text to display if no tags found',
455 'simple-tags'),
456 'helptext' => '',
457 'required' => false,
458 ]);
459
460 $select = [
461 'options' => [
462 [
463 'attr' => '0',
464 'text' => esc_attr__('False', 'simple-tags'),
465 'default' => 'true',
466 ],
467 [
468 'attr' => '1',
469 'text' => esc_attr__('True', 'simple-tags'),
470 ],
471 ],
472 ];
473 $selected = (isset($current) && isset($current['hide_output'])) ? taxopress_disp_boolean($current['hide_output']) : '';
474 $select['selected'] = !empty($selected) ? $current['hide_output'] : '';
475 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
476 echo $ui->get_select_checkbox_input([
477 'namearray' => 'taxopress_post_tags',
478 'name' => 'hide_output',
479 'labeltext' => esc_html__('Hide display output if no terms ?',
480 'simple-tags'),
481 'selections' => $select, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
482 ]);
483
484 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
485 echo $ui->get_text_input([
486 'namearray' => 'taxopress_post_tags',
487 'name' => 'wrap_class',
488 'class' => '',
489 'textvalue' => isset($current['wrap_class']) ? esc_attr($current['wrap_class']) : '',
490 'labeltext' => esc_html__('Terms for Current Post div class', 'simple-tags'),
491 'helptext' => '',
492 'required' => false,
493 ]);
494
495 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
496 echo $ui->get_text_input([
497 'namearray' => 'taxopress_post_tags',
498 'name' => 'link_class',
499 'class' => '',
500 'textvalue' => isset($current['link_class']) ? esc_attr($current['link_class']) : '',
501 'labeltext' => esc_html__('Term link class', 'simple-tags'),
502 'helptext' => '',
503 'required' => false,
504 ]);
505
506 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
507 echo $ui->get_text_input([
508 'namearray' => 'taxopress_post_tags',
509 'name' => 'xformat',
510 'class' => 'st-full-width',
511 'textvalue' => isset($current['xformat']) ? esc_attr($current['xformat']) : esc_attr('<a href="%tag_link%" title="%tag_name%" %tag_rel%>%tag_name%</a>'),
512 'labeltext' => esc_html__('Term link format', 'simple-tags'),
513 '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>'),
514 'required' => false,
515 ]);
516
517 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
518 echo $ui->get_td_end() . $ui->get_tr_end();
519 ?>
520 </table>
521
522 <?php }//end new fields
523 ?>
524
525
526 </div>
527 <div class="clear"></div>
528
529
530 </div>
531 </div>
532 </div>
533
534
535 <?php if ($post_tags_limit) { ?>
536
537 <div class="pp-version-notice-bold-purple" style="margin-left:0px;">
538 <div class="pp-version-notice-bold-purple-message"><?php echo esc_html__('You\'re using TaxoPress Free.
539 The Pro version has more features and support.', 'simple-tags'); ?>
540 </div>
541 <div class="pp-version-notice-bold-purple-button"><a
542 href="https://taxopress.com/pro" target="_blank"><?php echo esc_html__('Upgrade to Pro', 'simple-tags'); ?></a>
543 </div>
544 </div>
545
546 <?php } ?>
547 <?php
548 /**
549 * Fires after the default fieldsets on the taxonomy screen.
550 *
551 * @param taxopress_admin_ui $ui Admin UI instance.
552 */
553 do_action('taxopress_taxonomy_after_fieldsets', $ui);
554 ?>
555
556 </div>
557 </div>
558
559
560 </div>
561
562 <div class="taxopress-right-sidebar">
563 <div class="taxopress-right-sidebar-wrapper" style="min-height: 205px;">
564
565
566 <?php
567 if (!$post_tags_limit){ ?>
568 <p class="submit">
569
570 <?php
571 wp_nonce_field('taxopress_addedit_posttags_nonce_action',
572 'taxopress_addedit_posttags_nonce_field');
573 if (!empty($_GET) && !empty($_GET['action']) && 'edit' === $_GET['action']) { ?>
574 <input type="submit" class="button-primary taxopress-taxonomy-submit taxopress-posttags-submit"
575 name="posttags_submit"
576 value="<?php echo esc_attr(esc_attr__('Save Terms for Current Post',
577 'simple-tags')); ?>"/>
578 <?php
579 } else { ?>
580 <input type="submit" class="button-primary taxopress-taxonomy-submit taxopress-posttags-submit"
581 name="posttags_submit"
582 value="<?php echo esc_attr(esc_attr__('Add Terms for Current Post',
583 'simple-tags')); ?>"/>
584 <?php } ?>
585
586 <input type="hidden" name="cpt_tax_status" id="cpt_tax_status"
587 value="<?php echo esc_attr($tab); ?>"/>
588 </p>
589
590 <?php if (!empty($current)) {
591 ?>
592 <p>
593 <?php echo '<div class="taxopress-warning" style="">' . esc_html__('Shortcode: ',
594 'simple-tags'); ?> &nbsp;
595 <textarea
596 style="resize: none;padding: 5px;">[taxopress_postterms id="<?php echo (int)$current['ID']; ?>"]</textarea>
597 </div>
598 </p>
599 <?php } ?>
600
601 <?php
602 }
603 ?>
604
605 </div>
606
607 <?php do_action('taxopress_admin_after_sidebar'); ?>
608 </div>
609
610 <div class="clear"></div>
611
612
613
614 </form>
615
616 </div><!-- End .wrap -->
617
618 <div class="clear"></div>
619
620 <?php # Modal Windows; ?>
621 <div class="remodal" data-remodal-id="taxopress-modal-alert"
622 data-remodal-options="hashTracking: false, closeOnOutsideClick: false">
623 <div class="" style="color:red;"><?php echo esc_html__('Please complete the following required fields to save your changes:', 'simple-tags'); ?></div>
624 <div id="taxopress-modal-alert-content"></div>
625 <br>
626 <button data-remodal-action="cancel" class="remodal-cancel"><?php echo esc_html__('Okay', 'simple-tags'); ?></button>
627 </div>
628
629 <div class="remodal" data-remodal-id="taxopress-modal-confirm"
630 data-remodal-options="hashTracking: false, closeOnOutsideClick: false">
631 <div id="taxopress-modal-confirm-content"></div>
632 <br>
633 <button data-remodal-action="cancel" class="remodal-cancel"><?php echo esc_html__('No', 'simple-tags'); ?></button>
634 <button data-remodal-action="confirm"
635 class="remodal-confirm"><?php echo esc_html__('Yes', 'simple-tags'); ?></button>
636 </div>
637
638 <?php
639 }
640
641 }
642