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

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

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