PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.42.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.42.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.42.0, at inc/autolinks.php

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