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

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