PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.51.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.51.0
3.54.0 3.53.0 3.52.0 3.51.0 3.50.0 3.45.0 3.38.0 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.40.0 3.40.1 3.41.0 3.42.0 3.43.0 3.44.0 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 All 178 releases
simple-tags / inc / autolinks.php

autolinks.php in Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms 3.51.0, at inc/autolinks.php

1,175 lines 78.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class SimpleTags_Autolink
4 {
5 public const MENU_SLUG = 'st_options';
6
7 // class instance
8 public static $instance;
9
10 // WP_List_Table object
11 public $terms_table;
12
13 /**
14 * Constructor
15 *
16 * @return void
17 * @author Olatechpro
18 */
19 public function __construct()
20 {
21
22 add_filter('set-screen-option', [__CLASS__, 'set_screen'], 10, 3);
23 // Admin menu
24 add_action('admin_menu', [$this, 'admin_menu']);
25
26 // Javascript
27 add_action('admin_enqueue_scripts', [__CLASS__, 'admin_enqueue_scripts'], 11);
28 }
29
30 /**
31 * Init somes JS and CSS need for this feature
32 *
33 * @return void
34 * @author Olatechpro
35 */
36 public static function admin_enqueue_scripts()
37 {
38
39 // add JS for manage click tags
40 if (isset($_GET['page']) && $_GET['page'] == 'st_autolinks') {
41 wp_enqueue_style('st-taxonomies-css');
42 }
43 }
44
45 public static function set_screen($status, $option, $value)
46 {
47 return $value;
48 }
49
50 /** Singleton instance */
51 public static function get_instance()
52 {
53 if (!isset(self::$instance)) {
54 self::$instance = new self();
55 }
56
57 return self::$instance;
58 }
59
60 /**
61 * Add WP admin menu for Tags
62 *
63 * @return void
64 * @author Olatechpro
65 */
66 public function admin_menu()
67 {
68 $hook = add_submenu_page(
69 self::MENU_SLUG,
70 esc_html__('Auto Links', 'simple-tags'),
71 esc_html__('Auto Links', 'simple-tags'),
72 'simple_tags',
73 'st_autolinks',
74 [
75 $this,
76 'page_manage_autolinks',
77 ]
78 );
79
80 if (taxopress_is_screen_main_page()) {
81 add_action("load-$hook", [$this, 'screen_option']);
82 }
83 }
84
85 /**
86 * Screen options
87 */
88 public function screen_option()
89 {
90
91 $option = 'per_page';
92 $args = [
93 'label' => esc_html__('Number of items per page', 'simple-tags'),
94 'default' => 20,
95 'option' => 'st_autolinks_per_page'
96 ];
97
98 add_screen_option($option, $args);
99
100 $this->terms_table = new Autolinks_List();
101 }
102
103 /**
104 * Method for build the page HTML manage tags
105 *
106 * @return void
107 * @author Olatechpro
108 */
109 public function page_manage_autolinks()
110 {
111 // Default order
112 if (!isset($_GET['order'])) {
113 $_GET['order'] = 'name-asc';
114 }
115
116 settings_errors(__CLASS__);
117
118 if (!isset($_GET['add'])) {
119 //all tax
120 ?>
121 <div class="wrap st_wrap st-manage-taxonomies-page">
122
123 <div id="">
124 <h1 class="wp-heading-inline"><?php esc_html_e('Auto Links', 'simple-tags'); ?></h1>
125 <a href="<?php echo esc_url(admin_url('admin.php?page=st_autolinks&add=new_item')); ?>"
126 class="page-title-action taxopress">
127 <?php if (! taxopress_is_pro_version()) : ?>
128 <span class="dashicons dashicons-lock" aria-hidden="true"></span>
129 <?php endif; ?>
130 <?php esc_html_e('Add New Auto Link', 'simple-tags'); ?></a>
131
132 <div class="taxopress-description"><?php esc_html_e('Auto Links can automatically create links to your defined terms. For example, if you have a term called “WordPress”, the Auto Links feature can find the word “WordPress” in your content and add links to the archive page for that term.', 'simple-tags'); ?></div>
133
134
135 <?php
136 if (isset($_REQUEST['s']) && $search = sanitize_text_field(wp_unslash($_REQUEST['s']))) {
137 /* translators: %s: search keywords */
138 printf(' <span class="subtitle">' . esc_html__(
139 'Search results for &#8220;%s&#8221;',
140 'simple-tags'
141 ) . '</span>', esc_html($search));
142 }
143 ?>
144 <?php
145
146 //the terms table instance
147 $this->terms_table->prepare_items();
148 ?>
149
150
151 <hr class="wp-header-end">
152 <div id="ajax-response"></div>
153 <form class="search-form wp-clearfix st-taxonomies-search-form" method="get">
154 <?php $this->terms_table->search_box(esc_html__('Search Auto Links', 'simple-tags'), 'term'); ?>
155 </form>
156 <div class="clear"></div>
157
158 <div id="col-container" class="wp-clearfix">
159
160 <div class="col-wrap">
161 <form action="<?php echo esc_url(add_query_arg('', '')); ?>" method="post">
162 <?php $this->terms_table->display(); //Display the table
163 ?>
164 </form>
165 <div class="form-wrap edit-term-notes">
166 <p><?php esc_html__('Description here.', 'simple-tags') ?></p>
167 </div>
168 </div>
169
170
171 </div>
172
173
174 </div>
175 <?php } else {
176 if ($_GET['add'] == 'new_item') {
177 //add/edit taxonomy
178 $this->taxopress_manage_autolinks();
179 echo '<div>';
180 }
181 } ?>
182
183
184 <?php SimpleTags_Admin::printAdminFooter(); ?>
185 </div>
186 <?php
187 }
188
189
190 /**
191 * Create our settings page output.
192 *
193 * @internal
194 */
195 public function taxopress_manage_autolinks()
196 {
197
198 $tab = (!empty($_GET) && !empty($_GET['action']) && 'edit' == $_GET['action']) ? 'edit' : 'new';
199 $tab_class = 'taxopress-' . $tab;
200 $current = null;
201
202 ?>
203
204 <div class="wrap <?php echo esc_attr($tab_class); ?>">
205
206 <?php
207
208 $autolinks = taxopress_get_autolink_data();
209 $autolink_edit = false;
210 $autolink_limit = false;
211
212 if ('edit' === $tab) {
213
214
215 $selected_autolink = taxopress_get_current_autolink();
216
217 if ($selected_autolink && array_key_exists($selected_autolink, $autolinks)) {
218 $current = $autolinks[$selected_autolink];
219 $autolink_edit = true;
220 }
221 }
222
223
224 if (!isset($current['title']) && count($autolinks) > 0 && apply_filters(
225 'taxopress_autolinks_create_limit',
226 true
227 )) {
228 $autolink_limit = true;
229 }
230
231
232 $ui = new taxopress_admin_ui();
233 ?>
234
235
236 <div class="wrap <?php echo esc_attr($tab_class); ?>">
237 <h1><?php echo esc_html__('Manage Auto Links', 'simple-tags'); ?></h1>
238 <div class="wp-clearfix"></div>
239
240 <form method="post" action="">
241
242
243 <div class="tagcloudui st-tabbed">
244
245
246 <div class="autolinks-postbox-container">
247 <div id="poststuff">
248 <div class="taxopress-section postbox">
249 <div class="postbox-header">
250 <h2 class="hndle ui-sortable-handle">
251 <?php
252 if ($autolink_edit) {
253 $active_tab = (isset($current['active_tab']) && !empty(trim($current['active_tab']))) ? $current['active_tab'] : 'autolink_general';
254 echo esc_html__('Edit Auto Links', 'simple-tags');
255 echo '<input type="hidden" name="edited_autolink" value="' . esc_attr($current['ID']) . '" />';
256 echo '<input type="hidden" name="taxopress_autolink[ID]" value="' . esc_attr($current['ID']) . '" />';
257 echo '<input type="hidden" name="taxopress_autolink[active_tab]" class="taxopress-active-subtab" value="' . esc_attr($active_tab) . '" />';
258 } else {
259 $active_tab = 'autolink_general';
260 echo '<input type="hidden" name="taxopress_autolink[active_tab]" class="taxopress-active-subtab" value="" />';
261 echo esc_html__('Add new Auto Links', 'simple-tags');
262 }
263 ?>
264 </h2>
265 </div>
266 <div class="inside">
267 <div class="main">
268
269
270 <?php if ($autolink_limit) {
271 echo '<div class="st-taxonomy-content promo-box-area"><div class="taxopress-warning upgrade-pro">
272
273 <h2 style="margin-bottom: 5px;">' . esc_html__(
274 'To create more Auto Links, please upgrade to TaxoPress Pro.',
275 'simple-tags'
276 ) . '</h2>
277 <p>
278 ' . esc_html__(
279 'With TaxoPress Pro, you can create unlimited Auto Links. You can create Auto Links for any taxonomy.',
280 'simple-tags'
281 ) . '
282
283 </p>
284 </div></div>';
285 } else {
286 ?>
287
288
289 <ul class="taxopress-tab">
290 <li aria-current="<?php echo $active_tab === 'autolink_general' ? 'true' : 'false'; ?>" class="autolink_general_tab <?php echo $active_tab === 'autolink_general' ? 'active' : ''; ?>" data-content="autolink_general">
291 <a href="#autolink_general"><span><?php esc_html_e(
292 'General',
293 'simple-tags'
294 ); ?></span></a>
295 </li>
296
297 <li aria-current="<?php echo $active_tab === 'autolink_display' ? 'true' : 'false'; ?>" class="autolink_display_tab <?php echo $active_tab === 'autolink_display' ? 'active' : ''; ?>" data-content="autolink_display">
298 <a href="#autolink_display"><span><?php esc_html_e(
299 'Post Types',
300 'simple-tags'
301 ); ?></span></a>
302 </li>
303
304 <li aria-current="<?php echo $active_tab === 'autolink_control' ? 'true' : 'false'; ?>" class="autolink_control_tab <?php echo $active_tab === 'autolink_control' ? 'active' : ''; ?>" data-content="autolink_control">
305 <a href="#autolink_control"><span><?php esc_html_e(
306 'Control',
307 'simple-tags'
308 ); ?></span></a>
309 </li>
310
311 <li aria-current="<?php echo $active_tab === 'autolink_exceptions' ? 'true' : 'false'; ?>" class="autolink_exceptions_tab <?php echo $active_tab === 'autolink_exceptions' ? 'active' : ''; ?>" data-content="autolink_exceptions">
312 <a href="#autolink_exceptions"><span><?php esc_html_e(
313 'Exceptions',
314 'simple-tags'
315 ); ?></span></a>
316 </li>
317
318 <li aria-current="<?php echo $active_tab === 'autolink_options' ? 'true' : 'false'; ?>" class="autolink_options_tab <?php echo $active_tab === 'autolink_options' ? 'active' : ''; ?>" data-content="autolink_options">
319 <a href="#autolink_options"><span><?php esc_html_e(
320 'Options',
321 'simple-tags'
322 ); ?></span></a>
323 </li>
324
325 <li aria-current="<?php echo $active_tab === 'autolink_advanced' ? 'true' : 'false'; ?>" class="autolink_advanced_tab <?php echo $active_tab === 'autolink_advanced' ? 'active' : ''; ?>" data-content="autolink_advanced">
326 <a href="#autolink_advanced"><span><?php esc_html_e(
327 'Advanced',
328 'simple-tags'
329 ); ?></span></a>
330 </li>
331
332 <li aria-current="<?php echo $active_tab === 'autolink_custom_url' ? 'true' : 'false'; ?>" class="autolink_custom_url_tab <?php echo $active_tab === 'autolink_custom_url' ? 'active' : ''; ?>" data-content="autolink_custom_url">
333 <a href="#autolink_custom_url"><span><?php esc_html_e('Link Types', 'simple-tags'); ?></span></a>
334 </li>
335
336 </ul>
337
338 <div class="st-taxonomy-content taxopress-tab-content">
339
340
341 <table class="form-table taxopress-table autolink_general" style="<?php echo $active_tab === 'autolink_general' ? '' : 'display:none;'; ?>">
342 <?php
343 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
344 echo $ui->get_tr_start();
345
346 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
347 echo $ui->get_th_start();
348 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
349 echo $ui->get_label('title', esc_html__('Title', 'simple-tags')) . $ui->get_required_span();
350 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
351 echo $ui->get_th_end() . $ui->get_td_start();
352 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
353 echo $ui->get_text_input([
354 'namearray' => 'taxopress_autolink',
355 'name' => 'title',
356 'textvalue' => isset($current['title']) ? esc_attr($current['title']) : '',
357 'maxlength' => '32',
358 'helptext' => '',
359 'required' => true,
360 'placeholder' => false,
361 'wrap' => false,
362 ]);
363
364
365 $options = [];
366 foreach (get_all_taxopress_taxonomies() as $_taxonomy) {
367 $_taxonomy = $_taxonomy->name;
368 $tax = get_taxonomy($_taxonomy);
369 if (empty($tax->labels->name)) {
370 continue;
371 }
372 if ($tax->name === 'post_tag') {
373 $options[] = [
374 'attr' => $tax->name,
375 'text' => $tax->labels->name . ' (' . $tax->name . ')',
376 'default' => 'true',
377 ];
378 } else {
379 $options[] = [
380 'attr' => $tax->name,
381 'text' => $tax->labels->name . ' (' . $tax->name . ')',
382 ];
383 }
384 }
385
386 $select = [
387 'options' => $options,
388 ];
389 $selected = isset($current) ? taxopress_disp_boolean($current['taxonomy']) : '';
390 $select['selected'] = !empty($selected) ? $current['taxonomy'] : '';
391 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
392 echo $ui->get_select_checkbox_input_main([
393 'namearray' => 'taxopress_autolink',
394 'name' => 'taxonomy',
395 'class' => 'taxopress-dynamic-taxonomy st-post-taxonomy-select',
396 'labeltext' => esc_html__('Taxonomy', 'simple-tags'),
397 'required' => true,
398 'selections' => $select, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
399 ]);
400
401
402 $select = [
403 'options' => [
404 [
405 'attr' => 'none',
406 'text' => esc_attr__(
407 'Use case of text in content',
408 'simple-tags'
409 ),
410 'default' => 'true'
411 ],
412 [
413 'attr' => 'termcase',
414 'text' => esc_attr__('Use case of term', 'simple-tags')
415 ],
416 [
417 'attr' => 'uppercase',
418 'text' => esc_attr__('All uppercase', 'simple-tags')
419 ],
420 [
421 'attr' => 'lowercase',
422 'text' => esc_attr__('All lowercase', 'simple-tags')
423 ],
424 ],
425 ];
426 $selected = isset($current) ? taxopress_disp_boolean($current['autolink_case']) : '';
427 $select['selected'] = !empty($selected) ? $current['autolink_case'] : '';
428 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
429 echo $ui->get_select_number_select([
430 'namearray' => 'taxopress_autolink',
431 'name' => 'autolink_case',
432 'labeltext' => esc_html__(
433 'Auto Link case',
434 'simple-tags'
435 ),
436 'selections' => $select, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
437 ]);
438
439 $select = [
440 'options' => [
441 [
442 'attr' => 'post_content',
443 'text' => esc_attr__('Post Content', 'simple-tags'),
444 'default' => 'true'
445 ],
446 [
447 'attr' => 'posts',
448 'text' => esc_attr__(
449 'Post Content and Title',
450 'simple-tags'
451 )
452 ],
453 ],
454 ];
455 $selected = isset($current) ? taxopress_disp_boolean($current['autolink_display']) : '';
456 $select['selected'] = !empty($selected) ? $current['autolink_display'] : '';
457 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
458 echo $ui->get_select_number_select([
459 'namearray' => 'taxopress_autolink',
460 'name' => 'autolink_display',
461 'labeltext' => esc_html__(
462 'Auto Link areas',
463 'simple-tags'
464 ),
465 'selections' => $select, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
466 ]);
467
468 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
469 echo $ui->get_text_input([
470 'namearray' => 'taxopress_autolink',
471 'name' => 'autolink_title_attribute',
472 'textvalue' => isset($current['autolink_title_attribute']) ? esc_attr($current['autolink_title_attribute']) : 'Posts tagged with %s',
473 'labeltext' => esc_html__(
474 'Auto Link title when linking to terms',
475 'simple-tags'
476 ),
477 'helptext' => '',
478 'required' => false,
479 ]);
480
481 echo $ui->get_text_input([
482 'namearray' => 'taxopress_autolink',
483 'name' => 'autolink_title_attribute_when_using_custom_url',
484 'textvalue' => isset($current['autolink_title_attribute_when_using_custom_url']) ? esc_attr($current['autolink_title_attribute_when_using_custom_url']) : 'Visit this URL for more on %s',
485 'labeltext' => esc_html__(
486 'Auto Link title attribute when using a custom URL',
487 'simple-tags'
488 ),
489 'helptext' => '',
490 'required' => false,
491 ]);
492
493 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
494 echo $ui->get_td_end() . $ui->get_tr_end();
495 ?>
496 </table>
497
498
499 <table class="form-table taxopress-table autolink_display" style="<?php echo $active_tab === 'autolink_display' ? '' : 'display:none;'; ?>">
500 <?php
501
502
503 /**
504 * Filters the arguments for post types to list for taxonomy association.
505 *
506 *
507 * @param array $value Array of default arguments.
508 */
509 $args = apply_filters(
510 'taxopress_attach_post_types_to_taxonomy',
511 ['public' => true]
512 );
513
514 // 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.
515 if (!is_array($args)) {
516 $args = ['public' => true];
517 }
518 $output = 'objects'; // Or objects.
519
520 /**
521 * Filters the results returned to display for available post types for taxonomy.
522 *
523 * @param array $value Array of post type objects.
524 * @param array $args Array of arguments for the post type query.
525 * @param string $output The output type we want for the results.
526 */
527 $post_types = apply_filters(
528 'taxopress_get_post_types_for_taxonomies',
529 get_post_types($args, $output),
530 $args,
531 $output
532 );
533
534 $term_auto_locations = [];
535 foreach ($post_types as $post_type) {
536 if (!in_array($post_type->name, ['attachment'])) {
537 $term_auto_locations[$post_type->name] = $post_type->label;
538 }
539 }
540
541 echo '<tr valign="top"><th scope="row"><label>' . esc_html__(
542 'Enable this Auto Links instance for:',
543 'simple-tags'
544 ) . '</label><br /><small style=" color: #646970;">' . esc_html__(
545 'TaxoPress will attempt to automatically insert Auto Links in this content. It may not be successful for all post types and layouts.',
546 'simple-tags'
547 ) . '</small></th><td>
548 <table class="visbile-table">';
549 foreach ($term_auto_locations as $key => $value) {
550
551
552 echo '<tr valign="top"><th scope="row"><label for="' . esc_attr($key) . '">' . esc_html($value) . '</label></th><td>';
553 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
554 echo $ui->get_check_input([
555 'checkvalue' => $key,
556 'checked' => (!empty($current['embedded']) && is_array($current['embedded']) && in_array(
557 $key,
558 $current['embedded'],
559 true
560 )) ? 'true' : 'false',
561 'name' => esc_attr($key),
562 'namearray' => 'embedded',
563 'textvalue' => esc_attr($key),
564 'labeltext' => "",
565 'wrap' => false,
566 ]);
567
568 echo '</td></tr>';
569 }
570 echo '</table></td></tr>';
571
572
573 ?>
574
575 </table>
576
577
578 <table class="form-table taxopress-table autolink_control" style="<?php echo $active_tab === 'autolink_control' ? '' : 'display:none;'; ?>">
579 <?php
580 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
581 echo $ui->get_number_input([
582 'namearray' => 'taxopress_autolink',
583 'name' => 'autolink_usage_min',
584 'textvalue' => isset($current['autolink_usage_min']) ? esc_attr($current['autolink_usage_min']) : '1',
585 'labeltext' => esc_html__(
586 'Minimum term usage for Auto Links',
587 'simple-tags'
588 ),
589 'helptext' => esc_html__(
590 'To be included in Auto Links, a term must be used at least this many times.',
591 'simple-tags'
592 ),
593 'min' => '0',
594 'required' => true,
595 ]);
596
597 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
598 echo $ui->get_number_input([
599 'namearray' => 'taxopress_autolink',
600 'name' => 'autolink_usage_max',
601 'textvalue' => isset($current['autolink_usage_max']) ? esc_attr($current['autolink_usage_max']) : '10',
602 'labeltext' => esc_html__(
603 'Maximum number of links per post',
604 'simple-tags'
605 ),
606 'helptext' => esc_html__(
607 'This setting determines the maximum number of Auto Links in one post.',
608 'simple-tags'
609 ),
610 'min' => '1',
611 'required' => true,
612 ]);
613
614 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
615 echo $ui->get_number_input([
616 'namearray' => 'taxopress_autolink',
617 'name' => 'autolink_same_usage_max',
618 'textvalue' => isset($current['autolink_same_usage_max']) ? esc_attr($current['autolink_same_usage_max']) : '1',
619 'labeltext' => esc_html__(
620 'Maximum number of links for the same term',
621 'simple-tags'
622 ),
623 'helptext' => esc_html__(
624 'This setting determines the maximum number of Auto Links for each term in one post.',
625 'simple-tags'
626 ),
627 'min' => '1',
628 'required' => true,
629 ]);
630
631 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
632 echo $ui->get_number_input([
633 'namearray' => 'taxopress_autolink',
634 'name' => 'autolink_min_char',
635 'textvalue' => isset($current['autolink_min_char']) ? esc_attr($current['autolink_min_char']) : '',
636 'labeltext' => esc_html__(
637 'Minimum character length for an Auto Link',
638 'simple-tags'
639 ),
640 'helptext' => esc_html__(
641 'For example, \'4\' would only link terms that are of 4 characters or more in length.',
642 'simple-tags'
643 ),
644 'min' => '0',
645 'required' => false,
646 ]);
647
648 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
649 echo $ui->get_number_input([
650 'namearray' => 'taxopress_autolink',
651 'name' => 'autolink_max_char',
652 'textvalue' => isset($current['autolink_max_char']) ? esc_attr($current['autolink_max_char']) : '',
653 'labeltext' => esc_html__(
654 'Maximum character length for an Auto Link',
655 'simple-tags'
656 ),
657 'helptext' => esc_html__(
658 'For example, \'4\' would only link terms that are of 4 characters or less in length.',
659 'simple-tags'
660 ),
661 'min' => '0',
662 'required' => false,
663 ]);
664
665 $select = [
666 'options' => [
667 [
668 'attr' => '0',
669 'text' => esc_attr__('False', 'simple-tags'),
670 ],
671 [
672 'attr' => '1',
673 'text' => esc_attr__('True', 'simple-tags'),
674 'default' => 'true',
675 ],
676 ],
677 ];
678 $selected = (isset($current) && isset($current['whole_words'])) ? taxopress_disp_boolean($current['whole_words']) : '';
679 $select['selected'] = !empty($selected) ? $current['whole_words'] : '';
680 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
681 echo $ui->get_select_checkbox_input([
682 'namearray' => 'taxopress_autolink',
683 'name' => 'whole_words',
684 'labeltext' => esc_html__(
685 'Whole words only',
686 'simple-tags'
687 ),
688 'aftertext' => esc_html__(
689 'Only add links when the term is an exact whole word match. Do not autolink partial matches.',
690 'simple-tags'
691 ),
692 'selections' => $select, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
693 ]);
694
695
696 ?>
697
698 </table>
699
700
701 <table class="form-table taxopress-table autolink_exceptions fixed" style="<?php echo $active_tab === 'autolink_exceptions' ? '' : 'display:none;'; ?>">
702 <?php
703 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
704 echo $ui->get_textarea_input([
705 'namearray' => 'taxopress_autolink',
706 'name' => 'auto_link_exclude',
707 'rows' => '4',
708 'cols' => '40',
709 'class' => 'autocomplete-input',
710 'textvalue' => isset($current['auto_link_exclude']) ? esc_attr($current['auto_link_exclude']) : '',
711 'labeltext' => esc_html__(
712 'Exclude terms from Auto Links',
713 'simple-tags'
714 ),
715 'helptext' => esc_html__(
716 'If you enter the terms "WordPress", "Website" the Auto Links feature will never replace these terms. Separate multiple entries with a comma.',
717 'simple-tags'
718 ),
719 'required' => false,
720 ]);
721
722 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
723 echo $ui->get_text_input([
724 'namearray' => 'taxopress_autolink',
725 'name' => 'autolink_exclude_class',
726 'textvalue' => isset($current['autolink_exclude_class']) ? esc_attr($current['autolink_exclude_class']) : '',
727 'labeltext' => esc_html__(
728 'Prevent Auto Links inside classes or IDs',
729 'simple-tags'
730 ),
731 'helptext' => esc_html__(
732 'Separate multiple entries with a comma. For example: .notag, #main-header',
733 'simple-tags'
734 ),
735 'required' => false,
736 ]);
737
738 $html_exclusions = [
739 //headers
740 'h1' => esc_attr__('H1', 'simple-tags'),
741 'h2' => esc_attr__('H2', 'simple-tags'),
742 'h3' => esc_attr__('H3', 'simple-tags'),
743 'h4' => esc_attr__('H4', 'simple-tags'),
744 'h5' => esc_attr__('H5', 'simple-tags'),
745 'h6' => esc_attr__('H6', 'simple-tags'),
746 //html elements
747 'script' => esc_attr__('script', 'simple-tags'),
748 'style' => esc_attr__('style', 'simple-tags'),
749 'pre' => esc_attr__('pre', 'simple-tags'),
750 'code' => esc_attr__('code', 'simple-tags'),
751 ];
752
753 echo '<tr valign="top"><th scope="row"><label>' . esc_html__(
754 'Prevent Auto Links inside elements',
755 'simple-tags'
756 ) . '</label><br /><small style=" color: #646970;">' . esc_html__(
757 'Terms inside these HTML tags will not have Auto Links applied.',
758 'simple-tags'
759 ) . '</small></th><td>
760 <table class="visbile-table st-html-exclusion-table">';
761 foreach ($html_exclusions as $key => $value) {
762
763 echo '<tr valign="top"><th scope="row"><label for="' . esc_attr($key) . '">' . esc_html($value) . '</label></th><td>';
764
765 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
766 echo $ui->get_check_input([
767 'checkvalue' => $key,
768 'checked' => (!empty($current['html_exclusion']) && is_array($current['html_exclusion']) && in_array(
769 $key,
770 $current['html_exclusion'],
771 true
772 )) ? 'true' : 'false',
773 'name' => esc_attr($key),
774 'namearray' => 'html_exclusion',
775 'textvalue' => esc_attr($key),
776 'labeltext' => esc_html($key),
777 'labeldescription' => true,
778 'wrap' => false,
779 ]);
780
781 echo '</td></tr>';
782
783 if ($key === 'h6') {
784 echo '<tr valign="top"><th style="padding: 0;" scope="row"><hr /></th><td style="padding: 0;"><hr /></td></tr>';
785 }
786 }
787
788 /**
789 * Fires after the autolinks html_exclusions.
790 * @param $current array
791 * @param taxopress_admin_ui $ui Admin UI instance.
792 */
793 do_action('taxopress_autolinks_after_html_exclusions', $current, $ui);
794
795 echo '</table></td></tr>';
796
797 /**
798 * Fires after the autolinks html_exclusions tr.
799 * @param $current array
800 * @param taxopress_admin_ui $ui Admin UI instance.
801 */
802 do_action('taxopress_autolinks_after_html_exclusions_tr', $current, $ui);
803
804 ?>
805
806 </table>
807
808
809 <table class="form-table taxopress-table autolink_options" style="<?php echo $active_tab === 'autolink_options' ? '' : 'display:none;'; ?>">
810 <?php
811 if (taxopress_is_pro_version() && taxopress_is_synonyms_enabled()) {
812 $select = [
813 'options' => [
814 [
815 'attr' => '0',
816 'text' => esc_attr__('False', 'simple-tags'),
817 ],
818 [
819 'attr' => '1',
820 'text' => esc_attr__('True', 'simple-tags'),
821 'default' => 'true',
822 ],
823 ],
824 ];
825 $selected = (isset($current) && isset($current['synonyms_link'])) ? taxopress_disp_boolean($current['synonyms_link']) : '';
826 $select['selected'] = !empty($selected) ? $current['synonyms_link'] : '';
827
828 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
829 echo $ui->get_select_checkbox_input([
830 'namearray' => 'taxopress_autolink',
831 'name' => 'synonyms_link',
832 'labeltext' => esc_html__(
833 'Add links to synonyms',
834 'simple-tags'
835 ),
836 'aftertext' => esc_html__(
837 'Add links to the term synonyms.',
838 'simple-tags'
839 ),
840 'selections' => $select, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
841 ]);
842 }
843
844
845 $select = [
846 'options' => [
847 [
848 'attr' => '0',
849 'text' => esc_attr__('False', 'simple-tags'),
850 'default' => 'true',
851 ],
852 [
853 'attr' => '1',
854 'text' => esc_attr__('True', 'simple-tags'),
855 ],
856 ],
857 ];
858 $selected = (isset($current) && isset($current['unattached_terms'])) ? taxopress_disp_boolean($current['unattached_terms']) : '';
859 $select['selected'] = !empty($selected) ? $current['unattached_terms'] : '';
860 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
861 echo $ui->get_select_checkbox_input([
862 'namearray' => 'taxopress_autolink',
863 'name' => 'unattached_terms',
864 'labeltext' => esc_html__(
865 'Add links for all terms',
866 'simple-tags'
867 ),
868 'aftertext' => esc_html__(
869 'By default, TaxoPress will add links for all terms. If this box is unchecked, Auto Links will only add links for terms that are attached to the post.',
870 'simple-tags'
871 ),
872 'selections' => $select, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
873 ]);
874
875 ?>
876 <?php
877 $select = [
878 'options' => [
879 [
880 'attr' => '0',
881 'text' => esc_attr__('False', 'simple-tags'),
882 ],
883 [
884 'attr' => '1',
885 'text' => esc_attr__('True', 'simple-tags'),
886 'default' => 'true',
887 ],
888 ],
889 ];
890 $selected = (isset($current) && isset($current['autolink_dom'])) ? taxopress_disp_boolean($current['autolink_dom']) : '';
891 $select['selected'] = !empty($selected) ? $current['autolink_dom'] : '';
892
893 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
894 echo $ui->get_select_checkbox_input([
895 'namearray' => 'taxopress_autolink',
896 'name' => 'autolink_dom',
897 'labeltext' => esc_html__(
898 'Use new Auto Links engine',
899 'simple-tags'
900 ),
901 'aftertext' => esc_html__(
902 'The new Auto Links engine uses the DOMDocument PHP class and may offer better performance. If your server does not support this functionality, TaxoPress will use the usual engine.',
903 'simple-tags'
904 ),
905 'selections' => $select, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
906 ]);
907 ?>
908 </table>
909
910 <table class="form-table taxopress-table autolink_custom_url" style="<?php echo $active_tab === 'autolink_custom_url' ? '' : 'display:none;'; ?>">
911 <?php
912
913
914 $select = [
915 'options' => [
916 [
917 'attr' => '1',
918 'text' => esc_attr__('True', 'simple-tags'),
919 'default' => 'true',
920 ],
921 [
922 'attr' => '0',
923 'text' => esc_attr__('False', 'simple-tags'),
924 ],
925 ],
926 ];
927 $selected = (isset($current) && isset($current['archivepage'])) ? taxopress_disp_boolean($current['archivepage']) : '';
928 $select['selected'] = !empty($selected) ? $current['archivepage'] : '';
929
930 echo $ui->get_select_checkbox_input([
931 'namearray' => 'taxopress_autolink',
932 'name' => 'archivepage',
933 'labeltext' => esc_html__('Enable Auto Link to archive pages', 'simple-tags'),
934 'aftertext' => esc_html__('When enabled, terms will be linked to the archive page for that term.', 'simple-tags'),
935 'selections' => $select,
936 ]);
937
938 $select = [
939 'options' => [
940 [
941 'attr' => '1',
942 'text' => esc_attr__('True', 'simple-tags'),
943 'default' => 'true',
944 ],
945 [
946 'attr' => '0',
947 'text' => esc_attr__('False', 'simple-tags'),
948 ],
949 ],
950 ];
951 $selected = (isset($current) && isset($current['enable_custom_urls'])) ? taxopress_disp_boolean($current['enable_custom_urls']) : '';
952 $select['selected'] = !empty($selected) ? $current['enable_custom_urls'] : '';
953
954 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
955 echo $ui->get_select_checkbox_input([
956 'namearray' => 'taxopress_autolink',
957 'name' => 'enable_custom_urls',
958 'labeltext' => esc_html__('Enable Custom URLs', 'simple-tags'),
959 'aftertext' => esc_html__('When enabled, terms can be linked to custom URLs instead of their archive pages.', 'simple-tags'),
960 'selections' => $select,
961 ]);
962 // Fetch all taxonomies
963 $all_taxonomies = get_taxonomies([], 'objects');
964
965 $selected_taxonomies = [];
966 if (isset($current['taxonomy'])) {
967 if (is_array($current['taxonomy'])) {
968 $selected_taxonomies = $current['taxonomy'];
969 } else {
970 $selected_taxonomies = [$current['taxonomy']];
971 }
972 }
973
974
975 if (!is_array($current) || !array_key_exists('enable_customurl_field', $current)) {
976 $enable_customurl_field = isset($_POST['taxopress_autolink']) ? [] : ['post_tag', 'category'];
977 } else {
978 $enable_customurl_field = is_array($current['enable_customurl_field']) ? $current['enable_customurl_field'] : [];
979 }
980
981 echo '<tr valign="top"><th scope="row"><label>' . esc_html__(
982 'Enable the Custom URL Field:',
983 'simple-tags'
984 ) . '</label><br /><small style=" color: #646970;">' . esc_html__(
985 'Enable the Custom URL field for this taxonomy.',
986 'simple-tags'
987 ) . '</small></th><td><table class="visbile-table">';
988
989 $enable_custom_urls = isset($current['enable_custom_urls']) && $current['enable_custom_urls'] == '1';
990
991 foreach ($all_taxonomies as $taxonomy) {
992 if (!in_array($taxonomy->name, $selected_taxonomies, true)) {
993 continue;
994 }
995 $disabled = !$enable_custom_urls ? 'disabled' : '';
996 echo '<tr valign="top"><th scope="row"><label for="' . esc_attr($taxonomy->name) . '">' . esc_html($taxonomy->label) . '</label></th><td>';
997 echo $ui->get_check_input([
998 'checkvalue' => $taxonomy->name,
999 'checked' => in_array($taxonomy->name, $enable_customurl_field, true) ? 'true' : 'false',
1000 'name' => esc_attr($taxonomy->name),
1001 'namearray' => 'taxopress_autolink[enable_customurl_field]',
1002 'textvalue' => esc_attr($taxonomy->name),
1003 'labeltext' => '',
1004 'wrap' => false,
1005 ]);
1006 echo '</td></tr>';
1007 }
1008 echo '</table></td></tr>';
1009 ?>
1010 </table>
1011
1012 <table class="form-table taxopress-table autolink_advanced" style="<?php echo $active_tab === 'autolink_advanced' ? '' : 'display:none;'; ?>">
1013 <?php
1014 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1015 echo $ui->get_text_input([
1016 'namearray' => 'taxopress_autolink',
1017 'name' => 'link_class',
1018 'class' => '',
1019 'textvalue' => isset($current['link_class']) ? esc_attr($current['link_class']) : '',
1020 'labeltext' => esc_html__('Term link class', 'simple-tags'),
1021 'helptext' => '',
1022 'required' => false,
1023 ]);
1024
1025 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1026 echo $ui->get_number_input([
1027 'namearray' => 'taxopress_autolink',
1028 'name' => 'hook_priority',
1029 'textvalue' => isset($current['hook_priority']) ? esc_attr($current['hook_priority']) : '12',
1030 'labeltext' => esc_html__(
1031 'Priority on the_content and the_title hook',
1032 'simple-tags'
1033 ),
1034 'helptext' => esc_html__(
1035 'Change the priority of the Auto Links functions on the_content hook. This is useful for fixing conflicts with other plugins. Higher number means autolink will be executed only after hooks with lower number has been executed.',
1036 'simple-tags'
1037 ),
1038 'min' => '1',
1039 'required' => false,
1040 ]);
1041
1042 ?>
1043 </table>
1044
1045
1046 </div>
1047
1048
1049 <?php } //end new fields
1050 ?>
1051
1052
1053 <div class="clear"></div>
1054
1055
1056 </div>
1057 </div>
1058 </div>
1059
1060
1061 <?php if ($autolink_limit) { ?>
1062
1063 <div class="pp-version-notice-bold-purple" style="margin-left:0px;">
1064 <div class="pp-version-notice-bold-purple-message"><?php esc_html_e('You\'re using TaxoPress Free.
1065 The Pro version has more features and support.', 'simple-tags'); ?>
1066 </div>
1067 <div class="pp-version-notice-bold-purple-button"><a href="https://taxopress.com/taxopress/" target="_blank"><?php esc_html_e('Upgrade to Pro', 'simple-tags'); ?></a>
1068 </div>
1069 </div>
1070
1071 <?php } ?>
1072 <?php
1073 /**
1074 * Fires after the default fieldsets on the taxonomy screen.
1075 *
1076 * @param taxopress_admin_ui $ui Admin UI instance.
1077 */
1078 do_action('taxopress_taxonomy_after_fieldsets', $ui);
1079 ?>
1080
1081 </div>
1082 </div>
1083
1084
1085 </div>
1086
1087 <div class="taxopress-right-sidebar">
1088 <div class="taxopress-right-sidebar-wrapper" style="min-height: 205px;<?php echo ($autolink_limit) ? 'display: none;' : ''; ?>">
1089
1090
1091 <?php
1092 if (!$autolink_limit) { ?>
1093 <p class="submit">
1094
1095 <?php
1096 wp_nonce_field(
1097 'taxopress_addedit_autolink_nonce_action',
1098 'taxopress_addedit_autolink_nonce_field'
1099 );
1100 if (!empty($_GET) && !empty($_GET['action']) && 'edit' === $_GET['action']) { ?>
1101 <input type="submit" class="button-primary taxopress-taxonomy-submit taxopress-autolink-submit" name="autolink_submit" value="<?php echo esc_attr(esc_attr__(
1102 'Save Auto Links',
1103 'simple-tags'
1104 )); ?>" />
1105 <?php
1106 } else { ?>
1107 <input type="submit" class="button-primary taxopress-taxonomy-submit taxopress-autolink-submit" name="autolink_submit" value="<?php echo esc_attr(esc_attr__(
1108 'Add Auto Links',
1109 'simple-tags'
1110 )); ?>" />
1111 <?php } ?>
1112
1113
1114 <input type="hidden" name="cpt_tax_status" id="cpt_tax_status" value="<?php echo esc_attr($tab); ?>" />
1115 </p>
1116
1117 <?php
1118 }
1119 ?>
1120
1121 </div>
1122
1123 <?php do_action('taxopress_admin_after_sidebar'); ?>
1124 <div class="taxopress-advertisement-right-sidebar">
1125 <div id="postbox-container-1" class="postbox-container">
1126 <div class="meta-box-sortables">
1127 <div class="advertisement-box-content postbox">
1128 <div class="postbox-header">
1129 <h3 class="advertisement-box-header hndle is-non-sortable">
1130 <span><?php echo esc_html__('TaxoPress and Languages', 'simple-tags'); ?></span>
1131 </h3>
1132 </div>
1133 <div class="inside">
1134 <p><?php echo sprintf(esc_html__('Please note that this is an automatic tool. It does have limitations around languages, types of content, and other factors. %1s Please read this documentation. %2s', 'simple-tags'), '<a href="https://taxopress.com/docs/characters/">', '</a>'); ?>
1135 </p>
1136 </div>
1137 </div>
1138 </div>
1139 </div>
1140 </div>
1141
1142
1143 </div>
1144
1145 <div class="clear"></div>
1146
1147
1148
1149 </form>
1150
1151 </div><!-- End .wrap -->
1152
1153 <div class="clear"></div>
1154
1155 <?php # Modal Windows;
1156 ?>
1157 <div class="remodal" data-remodal-id="taxopress-modal-alert" data-remodal-options="hashTracking: false, closeOnOutsideClick: false">
1158 <div class="" style="color:red;"><?php echo esc_html__('Please complete the following required fields to save your changes:', 'simple-tags'); ?></div>
1159 <div id="taxopress-modal-alert-content"></div>
1160 <br>
1161 <button data-remodal-action="cancel" class="remodal-cancel"><?php echo esc_html__('Okay', 'simple-tags'); ?></button>
1162 </div>
1163
1164 <div class="remodal" data-remodal-id="taxopress-modal-confirm" data-remodal-options="hashTracking: false, closeOnOutsideClick: false">
1165 <div id="taxopress-modal-confirm-content"></div>
1166 <br>
1167 <button data-remodal-action="cancel" class="remodal-cancel"><?php echo esc_html__('No', 'simple-tags'); ?></button>
1168 <button data-remodal-action="confirm" class="remodal-confirm"><?php echo esc_html__('Yes', 'simple-tags'); ?></button>
1169 </div>
1170
1171 <?php
1172 do_action('simpletags-autolinks');
1173 }
1174 }
1175