PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.50.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.50.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 / related-posts.php

related-posts.php in Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms 3.50.0, at inc/related-posts.php

1,426 lines 96.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_Related_Post
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 add_action('wp_ajax_taxopress_preview_related_posts', [$this, 'handle_relatedposts_preview']);
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 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
43 if (isset($_GET['page']) && $_GET['page'] == 'st_related_posts') {
44 wp_enqueue_style('st-taxonomies-css');
45 }
46 }
47
48 public static function set_screen($status, $option, $value)
49 {
50 return $value;
51 }
52
53 /** Singleton instance */
54 public static function get_instance()
55 {
56 if (!isset(self::$instance)) {
57 self::$instance = new self();
58 }
59
60 return self::$instance;
61 }
62
63 /**
64 * Add WP admin menu for Tags
65 *
66 * @return void
67 * @author Olatechpro
68 */
69 public function admin_menu()
70 {
71 $hook = add_submenu_page(
72 self::MENU_SLUG,
73 esc_html__('Related Posts', 'simple-tags'),
74 esc_html__('Related Posts', 'simple-tags'),
75 'simple_tags',
76 'st_related_posts',
77 [
78 $this,
79 'page_manage_relatedposts',
80 ]
81 );
82
83 if (taxopress_is_screen_main_page()) {
84 add_action("load-$hook", [$this, 'screen_option']);
85 }
86 }
87
88 /**
89 * Screen options
90 */
91 public function screen_option()
92 {
93
94 $option = 'per_page';
95 $args = [
96 'label' => esc_html__('Number of items per page', 'simple-tags'),
97 'default' => 20,
98 'option' => 'st_related_posts_per_page'
99 ];
100
101 add_screen_option($option, $args);
102
103 $this->terms_table = new RelatedPosts_List();
104 }
105
106 /**
107 * Method for build the page HTML manage tags
108 *
109 * @return void
110 * @author Olatechpro
111 */
112
113
114 public function page_manage_relatedposts()
115 {
116 // Default order
117 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
118 if (!isset($_GET['order'])) {
119 $_GET['order'] = 'name-asc';
120 }
121
122 settings_errors(__CLASS__);
123
124 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
125 if (!isset($_GET['add'])) {
126 //all tax
127 ?>
128 <div class="wrap st_wrap st-manage-taxonomies-page">
129
130 <div id="">
131 <h1 class="wp-heading-inline"><?php _e('Related Posts', 'simple-tags'); ?></h1>
132 <a href="<?php echo esc_url(admin_url('admin.php?page=st_related_posts&add=new_item')); ?>"
133 class="page-title-action taxopress">
134 <span class="dashicons dashicons-lock"></span>
135 <?php esc_html_e('Add New Related Post', 'simple-tags'); ?>
136 </a>
137
138 <div class="taxopress-description"><?php esc_html_e('The Related Posts feature works by checking for shared taxonomy terms. If your post has the terms “WordPress” and “Website”, then Related Posts will display other posts that also have the terms “WordPress” and “Website”.', 'simple-tags'); ?></div>
139
140
141 <?php
142 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
143 if (isset($_REQUEST['s']) && $search = sanitize_text_field(wp_unslash($_REQUEST['s']))) {
144 /* translators: %s: search keywords */
145 printf(' <span class="subtitle">' . esc_html__('Search results for &#8220;%s&#8221;', 'simple-tags') . '</span>', esc_html($search));
146 }
147 ?>
148 <?php
149 //the terms table instance
150 $this->terms_table->prepare_items();
151 ?>
152
153
154 <hr class="wp-header-end">
155 <div id="ajax-response"></div>
156 <form class="search-form wp-clearfix st-taxonomies-search-form" method="get">
157 <?php $this->terms_table->search_box(__('Search Related Posts', 'simple-tags'), 'term'); ?>
158 </form>
159 <div class="clear"></div>
160
161 <div id="col-container" class="wp-clearfix">
162
163 <div class="col-wrap">
164 <form action="<?php echo esc_url(add_query_arg('', '')); ?>" method="post">
165 <?php $this->terms_table->display(); //Display the table?>
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 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
179 if ($_GET['add'] == 'new_item') {
180 //add/edit taxonomy
181 $this->taxopress_manage_relatedposts();
182 echo '<div>';
183 }
184 } ?>
185
186
187 <?php SimpleTags_Admin::printAdminFooter(); ?>
188 </div>
189 <?php
190 }
191
192
193 /**
194 * Create our settings page output.
195 *
196 * @internal
197 */
198 public function taxopress_manage_relatedposts()
199 {
200 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
201 $tab = (!empty($_GET) && !empty($_GET['action']) && 'edit' == $_GET['action']) ? 'edit' : 'new';
202 $tab_class = 'taxopress-' . $tab;
203 $current = null;
204
205 ?>
206
207 <div class="wrap <?php echo esc_attr($tab_class); ?>">
208
209 <?php
210 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
211 $relatedposts = taxopress_get_relatedpost_data();
212 $related_post_edit = false;
213 $related_post_limit = false;
214
215 if ('edit' === $tab) {
216 $selected_relatedpost = taxopress_get_current_relatedpost();
217
218 if ($selected_relatedpost && array_key_exists($selected_relatedpost, $relatedposts)) {
219 $current = $relatedposts[$selected_relatedpost];
220 $related_post_edit = true;
221 }
222 }
223
224 if (!isset($current['title']) && count($relatedposts) > 0 && apply_filters('taxopress_related_posts_create_limit', true)) {
225 $related_post_limit = true;
226 }
227
228 $ui = new taxopress_admin_ui();
229 ?>
230
231 <div class="wrap <?php echo esc_attr($tab_class); ?>">
232 <h1><?php echo esc_html__('Manage Related Posts', 'simple-tags'); ?></h1>
233 <div class="wp-clearfix"></div>
234
235 <form method="post" action="">
236 <div class="tagcloudui st-tabbed">
237 <?php
238 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
239 if (isset($_GET['action']) && $_GET['action'] === 'edit') {
240 ?>
241
242
243 <div class="relatedposts-preview-container">
244 <div id="poststuff" class="taxopress-preview-box">
245 <div class="taxopress-section postbox">
246 <div class="postbox-header">
247 <h2 class="hndle ui-sortable-handle">
248 <?php echo esc_html__('Preview Related Posts', 'simple-tags'); ?>
249 </h2>
250 <span class="taxopress-move-up dashicons dashicons-arrow-up-alt2"></span>
251 <span class="taxopress-move-down dashicons dashicons-arrow-down-alt2"></span>
252 <div class="handle-actions hide-if-no-js">
253 <button type="button" class="handlediv" aria-expanded="true">
254 <span class="screen-reader-text"><?php esc_html_e('Toggle panel', 'simple-tags'); ?></span>
255 <span class="toggle-indicator dashicons dashicons-arrow-down" aria-hidden="true"></span>
256 </button>
257 </div>
258 </div>
259 <div class="inside">
260 <div class="main">
261 <div class="taxopress-preview-content">
262 <div class="taxopress-preview-control">
263 <?php
264 $preview_post_id = isset($current['preview_post_id']) ? (int) $current['preview_post_id'] : 0;
265 $preview_post = $preview_post_id ? get_post($preview_post_id) : null;
266 ?>
267 <select id="preview-post-select" name="taxopress_related_post[preview_post_id]" class="taxopress-post-preview-select">
268 <?php if ($preview_post) : ?>
269 <option value="<?php echo esc_attr($preview_post->ID); ?>" selected>
270 <?php echo esc_html($preview_post->post_title); ?>
271 </option>
272 <?php endif; ?>
273 </select>
274 <button type="button" class="button button-secondary preview-related-posts">
275 <?php esc_html_e('Preview', 'simple-tags'); ?>
276 </button>
277 <span class="spinner"></span>
278 </div>
279 <div class="taxopress-preview-results">
280 <!-- results -->
281 </div>
282 </div>
283 </div>
284 </div>
285 </div>
286 </div>
287 </div>
288 <?php
289 } ?>
290 <div class="relatedposts-postbox-container">
291 <div id="poststuff">
292 <div class="taxopress-section postbox">
293 <div class="postbox-header">
294 <h2 class="hndle ui-sortable-handle">
295 <?php
296 if ($related_post_edit) {
297 $active_tab = (isset($current['active_tab']) && !empty(trim($current['active_tab']))) ? $current['active_tab'] : 'relatedpost_general';
298 echo esc_html__('Edit Related Posts', 'simple-tags');
299 echo '<input type="hidden" name="edited_relatedpost" value="' . esc_attr($current['ID']) . '" />';
300 echo '<input type="hidden" name="taxopress_related_post[ID]" value="' . esc_attr($current['ID']) . '" />';
301 echo '<input type="hidden" name="taxopress_related_post[active_tab]" class="taxopress-active-subtab" value="' . esc_attr($active_tab) . '" />';
302 } else {
303 $active_tab = 'relatedpost_general';
304 echo '<input type="hidden" name="taxopress_related_post[active_tab]" class="taxopress-active-subtab" value="" />';
305 echo esc_html__('Add new Related Posts', 'simple-tags');
306 }
307 ?>
308 </h2>
309 </div>
310 <div class="inside">
311 <div class="main">
312
313
314 <?php if ($related_post_limit) {
315 echo '<div class="st-taxonomy-content promo-box-area"><div class="taxopress-warning upgrade-pro">
316 <h2 style="margin-bottom: 5px;">' . esc_html__(
317 'To create more Related Posts, please upgrade to TaxoPress Pro.',
318 'simple-tags'
319 ) . '</h2>
320 <p>
321
322 ' . esc_html__(
323 'With TaxoPress Pro, you can create unlimited Related Posts. You can create Related Posts for any taxonomy and then display those Related Posts anywhere on your site.',
324 'simple-tags'
325 ) . '
326
327 </p>
328 </div></div>';
329 } else {
330 ?>
331
332
333 <ul class="taxopress-tab">
334 <li aria-current="<?php echo $active_tab === 'relatedpost_general' ? 'true' : 'false'; ?>" class="relatedpost_general_tab <?php echo $active_tab === 'relatedpost_general' ? 'active' : ''; ?>" data-content="relatedpost_general">
335 <a href="#relatedpost_general"><span><?php esc_html_e('General', 'simple-tags'); ?></span></a>
336 </li>
337
338 <li aria-current="<?php echo $active_tab === 'relatedpost_post_types' ? 'true' : 'false'; ?>" class="relatedpost_post_types_tab <?php echo $active_tab === 'relatedpost_post_types' ? 'active' : ''; ?>" data-content="relatedpost_post_types">
339 <a href="#relatedpost_post_types"><span><?php esc_html_e('Post Types', 'simple-tags'); ?></span></a>
340 </li>
341
342 <li aria-current="<?php echo $active_tab === 'relatedpost_display' ? 'true' : 'false'; ?>" class="relatedpost_display_tab <?php echo $active_tab === 'relatedpost_display' ? 'active' : ''; ?>" data-content="relatedpost_display">
343 <a href="#relatedpost_display"><span><?php esc_html_e('Display', 'simple-tags'); ?></span></a>
344 </li>
345
346 <li aria-current="<?php echo $active_tab === 'relatedpost_design' ? 'true' : 'false'; ?>" class="relatedpost_design_tab <?php echo $active_tab === 'relatedpost_design' ? 'active' : ''; ?>" data-content="relatedpost_design">
347 <a href="#relatedpost_design"><span><?php esc_html_e('Design', 'simple-tags'); ?></span></a>
348 </li>
349
350 <li aria-current="<?php echo $active_tab === 'relatedpost_layout' ? 'true' : 'false'; ?>" class="relatedpost_layout_tab <?php echo $active_tab === 'relatedpost_layout' ? 'active' : ''; ?>" data-content="relatedpost_layout">
351 <a href="#relatedpost_layout"><span><?php esc_html_e('Layout', 'simple-tags'); ?></span></a>
352 </li>
353
354 <li aria-current="<?php echo $active_tab === 'relatedpost_display_format' ? 'true' : 'false'; ?>" class="relatedpost_display_format_tab <?php echo $active_tab === 'relatedpost_display_format' ? 'active' : ''; ?>" data-content="relatedpost_display_format">
355 <a href="#relatedpost_display_format"><span><?php esc_html_e('Display format', 'simple-tags'); ?></span></a>
356 </li>
357
358 <li aria-current="<?php echo $active_tab === 'relatedpost_option' ? 'true' : 'false'; ?>" class="relatedpost_option_tab <?php echo $active_tab === 'relatedpost_option' ? 'active' : ''; ?>" data-content="relatedpost_option">
359 <a href="#relatedpost_option"><span><?php esc_html_e('Options', 'simple-tags'); ?></span></a>
360 </li>
361
362 <li aria-current="<?php echo $active_tab === 'relatedpost_advanced' ? 'true' : 'false'; ?>" class="relatedpost_advanced_tab <?php echo $active_tab === 'relatedpost_advanced' ? 'active' : ''; ?>" data-content="relatedpost_advanced">
363 <a href="#relatedpost_advanced"><span><?php esc_html_e('Advanced', 'simple-tags'); ?></span></a>
364 </li>
365
366 </ul>
367
368 <div class="st-taxonomy-content taxopress-tab-content">
369
370
371 <table class="form-table taxopress-table relatedpost_general"
372 style="<?php echo $active_tab === 'relatedpost_general' ? '' : 'display:none;'; ?>">
373 <?php
374 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
375 echo $ui->get_tr_start();
376
377 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
378 echo $ui->get_th_start();
379 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
380 echo $ui->get_label('name', esc_html__('Title', 'simple-tags')) . $ui->get_required_span();
381 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
382 echo $ui->get_th_end() . $ui->get_td_start();
383 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
384 echo $ui->get_text_input([
385 'namearray' => 'taxopress_related_post',
386 'name' => 'title',
387 'textvalue' => isset($current['title']) ? esc_attr($current['title']) : '',
388 'maxlength' => '32',
389 'helptext' => '',
390 'required' => true,
391 'placeholder' => false,
392 'wrap' => false,
393 ]);
394
395 $select = [
396 'options' => [
397 [
398 'attr' => '0',
399 'text' => esc_attr__('False', 'simple-tags'),
400 'default' => 'true',
401 ],
402 [
403 'attr' => '1',
404 'text' => esc_attr__('True', 'simple-tags'),
405 ],
406 ],
407 ];
408 $selected = (isset($current) && isset($current['hide_title'])) ? taxopress_disp_boolean($current['hide_title']) : '';
409 $select['selected'] = !empty($selected) ? $current['hide_title'] : '';
410 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
411 echo $ui->get_select_checkbox_input([
412 'namearray' => 'taxopress_related_post',
413 'name' => 'hide_title',
414 'labeltext' => esc_html__(
415 'Hide title in output ?',
416 'simple-tags'
417 ),
418 'selections' => $select,// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
419 ]);
420
421
422 $select = [
423 'options' => [
424 [
425 'attr' => '',
426 'text' => esc_attr__('None', 'simple-tags')
427 ],
428 [
429 'attr' => 'h1',
430 'text' => esc_attr__('H1', 'simple-tags')
431 ],
432 [
433 'attr' => 'h2',
434 'text' => esc_attr__('H2', 'simple-tags')
435 ],
436 [
437 'attr' => 'h3',
438 'text' => esc_attr__('H3', 'simple-tags')
439 ],
440 [
441 'attr' => 'h4',
442 'text' => esc_attr__('H4', 'simple-tags'),
443 'default' => 'true'
444 ],
445 [
446 'attr' => 'h5',
447 'text' => esc_attr__('H5', 'simple-tags')
448 ],
449 [
450 'attr' => 'h6',
451 'text' => esc_attr__('H6', 'simple-tags')
452 ],
453 ],
454 ];
455 $selected = isset($current) ? taxopress_disp_boolean($current['title_header']) : '';
456
457 $select['selected'] = !empty($selected) ? $current['title_header'] : '';
458 if (isset($current['title_header']) && empty($current['title_header'])) {
459 $select['selected'] = 'none';
460 }
461 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
462 echo $ui->get_select_checkbox_input_main([
463 'namearray' => 'taxopress_related_post',
464 'name' => 'title_header',
465 'labeltext' => esc_html__('Title header', 'simple-tags'),
466 'selections' => $select,// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
467 ]);
468
469 $options = [];
470 foreach (get_all_taxopress_taxonomies() as $_taxonomy) {
471 $_taxonomy = $_taxonomy->name;
472 $tax = get_taxonomy($_taxonomy);
473 if (empty($tax->labels->name) || $_taxonomy === 'link_category') {
474 continue;
475 }
476 if ($tax->name === 'post_tag') {
477 $options[] = [
478 'attr' => $tax->name,
479 'text' => $tax->labels->name . ' (' . $tax->name . ')',
480 'default' => 'true'
481 ];
482 } else {
483 $options[] = [
484 'attr' => $tax->name,
485 'text' => $tax->labels->name . ' (' . $tax->name . ')'
486 ];
487 }
488 }
489
490 $select = [
491 'options' => $options,
492 ];
493 $selected = isset($current) ? taxopress_disp_boolean($current['taxonomy']) : '';
494 $select['selected'] = !empty($selected) ? $current['taxonomy'] : '';
495 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
496 echo $ui->get_select_checkbox_input_main([
497 'namearray' => 'taxopress_related_post',
498 'name' => 'taxonomy',
499 'class' => 'st-post-taxonomy-select',
500 'labeltext' => esc_html__('Taxonomy', 'simple-tags'),
501 'required' => true,
502 'selections' => $select,// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
503 ]);
504
505 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
506 echo $ui->get_td_end() . $ui->get_tr_end();
507 ?>
508 </table>
509
510 <table class="form-table taxopress-table relatedpost_design"
511 style="<?php echo $active_tab === 'relatedpost_design' ? '' : 'display:none;'; ?>">
512 <?php
513
514 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
515 echo $ui->get_number_input([
516 'namearray' => 'taxopress_related_post',
517 'name' => 'smallest',
518 'textvalue' => isset($current['smallest']) ? esc_attr($current['smallest']) : '12',
519 'labeltext' => esc_html__('Font size minimum', 'simple-tags'),
520 'helptext' => '',
521 'required' => false,
522 ]);
523
524 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
525 echo $ui->get_number_input([
526 'namearray' => 'taxopress_related_post',
527 'name' => 'largest',
528 'textvalue' => isset($current['largest']) ? esc_attr($current['largest']) : '12',
529 'labeltext' => esc_html__('Font size maximum', 'simple-tags'),
530 'helptext' => '',
531 'required' => false,
532 ]);
533
534 $select = [
535 'options' => [
536 [ 'attr' => 'pt', 'text' => esc_attr__('Point', 'simple-tags'), 'default' => 'true' ],
537 [ 'attr' => 'px', 'text' => esc_attr__('Pixel', 'simple-tags') ],
538 [ 'attr' => 'em', 'text' => esc_attr__('Em', 'simple-tags') ],
539 [ 'attr' => '%', 'text' => esc_attr__('Percent', 'simple-tags') ],
540 ],
541 ];
542 $selected = isset($current['unit']) ? taxopress_disp_boolean($current['unit']) : '';
543 $select['selected'] = !empty($selected) ? $current['unit'] : '';
544 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
545 echo $ui->get_select_checkbox_input_main([
546 'namearray' => 'taxopress_related_post',
547 'name' => 'unit',
548 'labeltext' => esc_html__('Unit font size', 'simple-tags'),
549 'selections' => $select, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
550 ]);
551
552 $select = [
553 'options' => [
554 [
555 'attr' => '0',
556 'text' => esc_attr__('False', 'simple-tags'),
557 'default' => 'true',
558 ],
559 [
560 'attr' => '1',
561 'text' => esc_attr__('True', 'simple-tags'),
562 ],
563 ],
564 ];
565 $selected = (isset($current) && isset($current['color'])) ? taxopress_disp_boolean($current['color']) : '';
566 $select['selected'] = !empty($selected) ? $current['color'] : '';
567 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
568 echo $ui->get_select_checkbox_input([
569 'namearray' => 'taxopress_related_post',
570 'name' => 'color',
571 'class' => 'relatedposts-color-option',
572 'labeltext' => esc_html__('Enable colors for terms', 'simple-tags'),
573 'selections' => $select, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
574 ]);
575
576 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
577 echo $ui->get_text_input([
578 'namearray' => 'taxopress_related_post',
579 'name' => 'mincolor',
580 'class' => 'text-color related-post-min',
581 'textvalue' => isset($current['mincolor']) ? esc_attr($current['mincolor']) : '#353535',
582 'labeltext' => esc_html__('Font color minimum', 'simple-tags'),
583 'helptext' => esc_html__('This is the color of the least popular term.', 'simple-tags'),
584 'required' => true,
585 ]);
586
587 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
588 echo $ui->get_text_input([
589 'namearray' => 'taxopress_related_post',
590 'name' => 'maxcolor',
591 'class' => 'text-color related-post-max',
592 'textvalue' => isset($current['maxcolor']) ? esc_attr($current['maxcolor']) : '#000000',
593 'labeltext' => esc_html__('Font color maximum', 'simple-tags'),
594 'helptext' => esc_html__('This is the color of the most popular term.', 'simple-tags'),
595 'required' => true,
596 ]);
597 ?>
598 </table>
599
600
601 <table class="form-table taxopress-table relatedpost_display"
602 style="<?php echo $active_tab === 'relatedpost_display' ? '' : 'display:none;'; ?>">
603 <?php
604
605 /**
606 * Filters the arguments for post types to list for taxonomy association.
607 *
608 * @param array $value Array of default arguments.
609 */
610 $args = apply_filters(
611 'taxopress_attach_post_types_to_taxonomy',
612 ['public' => true]
613 );
614
615 // 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.
616 if (!is_array($args)) {
617 $args = ['public' => true];
618 }
619 $output = 'objects'; // Or objects.
620
621 /**
622 * Filters the results returned to display for available post types for taxonomy.
623 *
624 * @param array $value Array of post type objects.
625 * @param array $args Array of arguments for the post type query.
626 * @param string $output The output type we want for the results.
627 */
628 $post_types = apply_filters(
629 'taxopress_get_post_types_for_taxonomies',
630 get_post_types($args, $output),
631 $args,
632 $output
633 );
634
635 $term_auto_locations = [
636 'homeonly' => esc_attr__('Homepage', 'simple-tags'),
637 'blogonly' => esc_attr__('Blog display', 'simple-tags'),
638 'post' => esc_attr__('Posts', 'simple-tags'),
639 ];
640 foreach ($post_types as $post_type) {
641 if (!in_array($post_type->name, ['attachment'])) {
642 $term_auto_locations[$post_type->name] = $post_type->label;
643 }
644 }
645
646 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
647 echo $ui->get_number_input([
648 'namearray' => 'taxopress_related_post',
649 'name' => 'max_related_posts',
650 'textvalue' => isset($current['max_related_posts']) ? esc_attr($current['max_related_posts']) : '3',
651 'labeltext' => esc_html__(
652 'Maximum related posts to display',
653 'simple-tags'
654 ),
655 'helptext' => esc_html__('Specify the number of related posts to display.', 'simple-tags'),
656 'required' => true,
657 ]);
658
659 echo '<tr valign="top"><th scope="row"><label>' . esc_html__(
660 'Attempt to automatically display related posts',
661 'simple-tags'
662 ) . '</label><br /><small style=" color: #646970;">' . esc_html__(
663 'TaxoPress will attempt to automatically display related posts in this content. It may not be successful for all post types and layouts.',
664 'simple-tags'
665 ) . '</small></th><td>
666 <table class="visbile-table">';
667 foreach ($term_auto_locations as $key => $value) {
668 $is_checked = 'false';
669
670 // Set 'post' as default if nothing is set in the $current['embedded'] array
671 if ((!isset($current['embedded']) || !is_array($current['embedded'])) && $key === 'post') {
672 $is_checked = 'true';
673 } elseif (isset($current['embedded']) && is_array($current['embedded']) && in_array($key, $current['embedded'], true)) {
674 $is_checked = 'true';
675 }
676
677
678 echo '<tr valign="top"><th scope="row"><label for="' . esc_attr($key) . '">' . esc_html($value) . '</label></th><td>';
679
680 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
681 echo $ui->get_check_input([
682 'checkvalue' => esc_attr($key),
683 'checked' => $is_checked, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
684 'name' => esc_attr($key),
685 'namearray' => 'embedded',
686 'textvalue' => esc_attr($key),
687 'labeltext' => "",
688 'wrap' => false,
689 ]);
690
691 echo '</td></tr>';
692
693 if ($key === 'blogonly') {
694 echo '<tr valign="top"><th style="padding: 0;" scope="row"><hr /></th><td style="padding: 0;"><hr /></td></tr>';
695 }
696 }
697 echo '</table></td></tr>';
698
699
700 ?>
701
702 </table>
703
704
705 <table class="form-table taxopress-table relatedpost_layout"
706 style="<?php echo $active_tab === 'relatedpost_layout' ? '' : 'display:none;'; ?>">
707 <?php
708
709 $select = [
710 'options' => [
711 [ 'attr' => 'box', 'text' => esc_attr__('Box List', 'simple-tags'), 'default' => 'true' ],
712 [ 'attr' => 'list', 'text' => esc_attr__('Unordered List (UL/LI)', 'simple-tags') ],
713 [ 'attr' => 'ol', 'text' => esc_attr__('Ordered List (OL/LI)', 'simple-tags') ],
714 ],
715 ];
716 $selected = (isset($current) && isset($current['format'])) ? taxopress_disp_boolean($current['format']) : '';
717 $select['selected'] = !empty($selected) ? $current['format'] : '';
718 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
719 echo $ui->get_select_checkbox_input_main([
720 'namearray' => 'taxopress_related_post',
721 'name' => 'format',
722 'labeltext' => esc_html__('Display format', 'simple-tags'),
723 'selections' => $select,// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
724 ]);
725
726 ?>
727 </table>
728
729
730 <table class="form-table taxopress-table relatedpost_display_format"
731 style="<?php echo $active_tab === 'relatedpost_display_format' ? '' : 'display:none;'; ?>">
732 <?php
733
734 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
735 echo $ui->get_textarea_input([
736 'namearray' => 'taxopress_related_post',
737 'name' => 'xformat',
738 'class' => 'st-full-width',
739 'rows' => '4',
740 'cols' => '40',
741 'textvalue' => isset($current['xformat']) ? esc_attr($current['xformat']) : esc_attr('<a href="%post_permalink%" title="%post_title% (%post_date%)" style="font-size:%post_size%;color:%post_color%"><img src="%post_thumb_url%" height="200" width="200" class="custom-image-class"/><br>%post_title%<br>%post_category%</a>'),
742 'labeltext' => esc_html__('Term link format', 'simple-tags'),
743 'helptext' => sprintf(esc_html__('This settings allows to customize the appearance of Related Post links. You can find tokens and explanations in the sidebar and %1sin the documentation%2s.', 'simple-tags'), '<a target="blank" href="https://taxopress.com/docs/format-related-posts/">', '</a>'),
744 'required' => false,
745 ]);
746 ?>
747
748 </table>
749
750
751 <table class="form-table taxopress-table relatedpost_post_types"
752 style="<?php echo $active_tab === 'relatedpost_post_types' ? '' : 'display:none;'; ?>">
753 <?php
754
755 /**
756 * Filters the arguments for post types to list for taxonomy association.
757 *
758 *
759 * @param array $value Array of default arguments.
760 */
761 $args = apply_filters(
762 'taxopress_attach_post_types_to_taxonomy',
763 ['public' => true]
764 );
765
766 // 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.
767 if (!is_array($args)) {
768 $args = ['public' => true];
769 }
770 $output = 'objects'; // Or objects.
771
772 /**
773 * Filters the results returned to post_types for available post types for taxonomy.
774 *
775 * @param array $value Array of post type objects.
776 * @param array $args Array of arguments for the post type query.
777 * @param string $output The output type we want for the results.
778 */
779 $post_types = apply_filters(
780 'taxopress_get_post_types_for_taxonomies',
781 get_post_types($args, $output),
782 $args,
783 $output
784 );
785
786 echo '<tr valign="top"><th scope="row"><label>' . esc_html__(
787 'Post Types',
788 'simple-tags'
789 ) . '</label><br /><small style=" color: #646970;">' . esc_html__(
790 'TaxoPress will display related posts from selected post types.',
791 'simple-tags'
792 ) . '</small></th><td>
793 <table class="visbile-table">';
794 foreach ($post_types as $post_type) {
795 $key = $post_type->name;
796 $value = $post_type->label;
797
798 if (in_array($post_type->name, ['attachment'])) {
799 continue;
800 }
801 echo '<tr valign="top"><th scope="row"><label for="' . esc_attr($key) . '">' . esc_html($value) . '</label></th><td>';
802
803 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
804 $legacy_post_type = (isset($current) && isset($current['post_type'])) ? $current['post_type'] : '';
805 $selected_post_type = (isset($current) && isset($current['post_types'])) ? $current['post_types'] : [];
806 if (!isset($current)) {
807 $selected_post_type = ['post'];
808 }
809 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
810 echo $ui->get_check_input([
811 'checkvalue' => esc_attr($key),
812 'checked' => (
813 in_array($key, $selected_post_type)
814 || $legacy_post_type == $key
815 || $legacy_post_type == 'st_all_posttype'
816 || $legacy_post_type == 'st_current_posttype'
817 ) ? 'true' : 'false',
818 'name' => esc_attr($key),
819 'namearray' => 'post_types',
820 'textvalue' => esc_attr($key),
821 'labeltext' => "",
822 'wrap' => false,
823 ]);
824
825 echo '</td></tr>';
826 }
827 echo '</table></td></tr>';
828
829
830 ?>
831
832 </table>
833
834
835 <table class="form-table taxopress-table relatedpost_option"
836 style="<?php echo $active_tab === 'relatedpost_option' ? '' : 'display:none;'; ?>">
837 <?php
838 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
839 echo $ui->get_text_input([
840 'namearray' => 'taxopress_related_post',
841 'name' => 'before',
842 'textvalue' => isset($current['before']) ? esc_attr($current['before']) : '',
843 'labeltext' => esc_html__(
844 'Text to display before posts list',
845 'simple-tags'
846 ),
847 'helptext' => esc_html__(
848 'Enter the text that should be displayed before the posts list.',
849 'simple-tags'
850 ),
851 'required' => false,
852 ]);
853
854 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
855 echo $ui->get_text_input([
856 'namearray' => 'taxopress_related_post',
857 'name' => 'after',
858 'textvalue' => isset($current['after']) ? esc_attr($current['after']) : '',
859 'labeltext' => esc_html__(
860 'Text to display after posts list',
861 'simple-tags'
862 ),
863 'helptext' => esc_html__(
864 'Enter the text that should be display after the posts list.',
865 'simple-tags'
866 ),
867 'required' => false,
868 ]);
869
870 $select = [
871 'options' => [
872 [
873 'attr' => '1',
874 'text' => esc_attr__('24 hours', 'simple-tags')
875 ],
876 [
877 'attr' => '7',
878 'text' => esc_attr__('7 days', 'simple-tags')
879 ],
880 [
881 'attr' => '14',
882 'text' => esc_attr__('2 weeks', 'simple-tags')
883 ],
884 [
885 'attr' => '30',
886 'text' => esc_attr__('1 month', 'simple-tags')
887 ],
888 [
889 'attr' => '180',
890 'text' => esc_attr__('6 months', 'simple-tags')
891 ],
892 [
893 'attr' => '365',
894 'text' => esc_attr__('1 year', 'simple-tags')
895 ],
896 [
897 'attr' => '0',
898 'text' => esc_attr__('No limit', 'simple-tags'),
899 'default' => 'true'
900 ],
901 ],
902 ];
903 $selected = isset($current) ? taxopress_disp_boolean($current['limit_days']) : '';
904 $select['selected'] = !empty($selected) ? $current['limit_days'] : '';
905 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
906 echo $ui->get_select_number_select([
907 'namearray' => 'taxopress_related_post',
908 'name' => 'limit_days',
909 'labeltext' => esc_html__(
910 'Limit related posts based on timeframe',
911 'simple-tags'
912 ),
913 'selections' => $select,// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
914 ]);
915
916
917 $select = [
918 'options' => [
919 [
920 'attr' => 'count-asc',
921 'text' => esc_attr__(
922 'Least common tags between posts',
923 'simple-tags'
924 )
925 ],
926 [
927 'attr' => 'count-desc',
928 'text' => esc_attr__(
929 'Most common tags between posts',
930 'simple-tags'
931 ),
932 'default' => 'true'
933 ],
934 [
935 'attr' => 'date-asc',
936 'text' => esc_attr__('Older Entries', 'simple-tags')
937 ],
938 [
939 'attr' => 'date-desc',
940 'text' => esc_attr__('Newer Entries', 'simple-tags')
941 ],
942 [
943 'attr' => 'name-asc',
944 'text' => esc_attr__('Alphabetical', 'simple-tags')
945 ],
946 [
947 'attr' => 'name-desc',
948 'text' => esc_attr__(
949 'Inverse Alphabetical',
950 'simple-tags'
951 )
952 ],
953 [
954 'attr' => 'random',
955 'text' => esc_attr__('Random', 'simple-tags')
956 ],
957 ],
958 ];
959 $selected = isset($current) ? taxopress_disp_boolean($current['order']) : '';
960 $select['selected'] = !empty($selected) ? $current['order'] : '';
961 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
962 echo $ui->get_select_checkbox_input_main([
963 'namearray' => 'taxopress_related_post',
964 'name' => 'order',
965 'labeltext' => esc_html__(
966 'Related Posts Order',
967 'simple-tags'
968 ),
969 'selections' => $select,// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
970 ]);
971
972 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
973 echo $ui->get_text_input([
974 'namearray' => 'taxopress_related_post',
975 'name' => 'nopoststext',
976 'textvalue' => isset($current['nopoststext']) ? esc_attr($current['nopoststext']) : 'No related posts.',
977 'labeltext' => esc_html__(
978 'Text to show when there is no related post',
979 'simple-tags'
980 ),
981 'helptext' => '',
982 'required' => false,
983 ]);
984
985
986 $select = [
987 'options' => [
988 [
989 'attr' => '0',
990 'text' => esc_attr__('False', 'simple-tags'),
991 'default' => 'true',
992 ],
993 [
994 'attr' => '1',
995 'text' => esc_attr__('True', 'simple-tags'),
996 ],
997 ],
998 ];
999 $selected = (isset($current) && isset($current['hide_output'])) ? taxopress_disp_boolean($current['hide_output']) : '';
1000 $select['selected'] = !empty($selected) ? $current['hide_output'] : '';
1001 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1002 echo $ui->get_select_checkbox_input([
1003 'namearray' => 'taxopress_related_post',
1004 'name' => 'hide_output',
1005 'labeltext' => esc_html__(
1006 'Hide output if no related post is found ?',
1007 'simple-tags'
1008 ),
1009 'selections' => $select,// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1010 ]);
1011
1012
1013 ?>
1014
1015 </table>
1016
1017
1018 <table class="form-table taxopress-table relatedpost_advanced"
1019 style="<?php echo $active_tab === 'relatedpost_advanced' ? '' : 'display:none;'; ?>">
1020 <?php
1021 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1022 echo $ui->get_text_input([
1023 'namearray' => 'taxopress_related_post',
1024 'name' => 'wrap_class',
1025 'class' => '',
1026 'textvalue' => isset($current['wrap_class']) ? esc_attr($current['wrap_class']) : '',
1027 'labeltext' => esc_html__('Related Posts div class', 'simple-tags'),
1028 'helptext' => '',
1029 'required' => false,
1030 ]);
1031
1032 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1033 echo $ui->get_text_input([
1034 'namearray' => 'taxopress_related_post',
1035 'name' => 'link_class',
1036 'class' => '',
1037 'textvalue' => isset($current['link_class']) ? esc_attr($current['link_class']) : '',
1038 'labeltext' => esc_html__('Term link class', 'simple-tags'),
1039 'helptext' => '',
1040 'required' => false,
1041 ]);
1042
1043 $select = [
1044 'options' => [
1045 ['attr' => 'd.m.Y', 'text' => esc_attr__('d.m.Y (e.g., 09.10.2024)', 'simple-tags'), 'default' => 'true'],
1046 ['attr' => 'F j, Y', 'text' => esc_attr__('F j, Y (e.g., October 9, 2024)', 'simple-tags')],
1047 ['attr' => 'Y-m-d', 'text' => esc_attr__('Y-m-d (e.g., 2024-10-09)', 'simple-tags')],
1048 ['attr' => 'm/d/Y', 'text' => esc_attr__('m/d/Y (e.g., 10/09/2024)', 'simple-tags')],
1049 ['attr' => 'd M, Y', 'text' => esc_attr__('d M, Y (e.g., 09 Oct, 2024)', 'simple-tags')],
1050 ],
1051 ];
1052 $selected = (isset($current) && isset($current['dateformat'])) ? taxopress_disp_boolean($current['dateformat']) : '';
1053 $select['selected'] = !empty($selected) ? $current['dateformat'] : '';
1054 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1055 echo $ui->get_select_checkbox_input_main([
1056 'namearray' => 'taxopress_related_post',
1057 'name' => 'dateformat',
1058 'labeltext' => esc_html__('Post date format', 'simple-tags'),
1059 'selections' => $select,// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1060 ]);
1061
1062 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1063 echo $ui->get_number_input([
1064 'namearray' => 'taxopress_related_post',
1065 'name' => 'max_post_chars',
1066 'textvalue' => isset($current['max_post_chars']) ? esc_attr($current['max_post_chars']) : '100',
1067 'labeltext' => esc_html__(
1068 'Maximum characters of post content to display',
1069 'simple-tags'
1070 ),
1071 'helptext' => '',
1072 'required' => true,
1073 ]);
1074
1075 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1076 echo $ui->get_number_input([
1077 'namearray' => 'taxopress_related_post',
1078 'name' => 'taxopress_max_cats',
1079 'textvalue' => isset($current['taxopress_max_cats']) ? esc_attr($current['taxopress_max_cats']) : '3',
1080 'labeltext' => esc_html__(
1081 'Maximum number of categories',
1082 'simple-tags'
1083 ),
1084 'helptext' => esc_html__('You must set zero (0) to display all post categories.', 'simple-tags'),
1085 'min' => '0',
1086 'required' => false,
1087 ]);
1088
1089 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1090 echo $ui->get_number_input([
1091 'namearray' => 'taxopress_related_post',
1092 'name' => 'taxopress_max_tags',
1093 'textvalue' => isset($current['taxopress_max_tags']) ? esc_attr($current['taxopress_max_tags']) : '3',
1094 'labeltext' => esc_html__(
1095 'Maximum number of tags',
1096 'simple-tags'
1097 ),
1098 'helptext' => esc_html__('You must set zero (0) to display all post tags.', 'simple-tags'),
1099 'min' => '0',
1100 'required' => false,
1101 ]);
1102 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1103 $select = [
1104 'options' => [
1105 ['attr' => 'thumbnail', 'text' => esc_attr__('Thumbnail (150x150)', 'simple-tags')],
1106 ['attr' => 'medium', 'text' => esc_attr__('Medium (300x300)', 'simple-tags')],
1107 ['attr' => 'large', 'text' => esc_attr__('Large (1024x1024)', 'simple-tags')],
1108 ['attr' => '1536x1536', 'text' => esc_attr__('1536x1536 (High Res)', 'simple-tags'), 'default' => 'true'],
1109 ['attr' => '2048x2048', 'text' => esc_attr__('2048x2048 (Ultra High Res)', 'simple-tags')],
1110 ],
1111 ];
1112
1113 $selected = (isset($current) && isset($current['imageresolution'])) ? taxopress_disp_boolean($current['imageresolution']) : '';
1114 $select['selected'] = !empty($selected) ? $current['imageresolution'] : '';
1115
1116 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1117 echo $ui->get_select_checkbox_input_main([
1118 'namearray' => 'taxopress_related_post',
1119 'name' => 'imageresolution',
1120 'labeltext' => esc_html__('Thumbnail image resolution', 'simple-tags'),
1121 'selections' => $select, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1122 ]);
1123
1124
1125 ?>
1126 <!-- Default Featured Image Integration -->
1127 <table class="form-table taxopress-table relatedpost_advanced"
1128 style="<?php echo $active_tab === 'relatedpost_advanced' ? '' : 'display:none;'; ?>">
1129 <tr valign="top">
1130 <th scope="row">
1131 <label for="default_featured_media"><?php echo esc_html__('Default post thumbnail', 'simple-tags'); ?></label>
1132 </th>
1133 <td>
1134 <div class="default-featured-media-field-wrapper">
1135 <div class="default-featured-media-field-container">
1136 <?php
1137 $current_value = isset($current['default_featured_media']) ? $current['default_featured_media'] : '';
1138 $default_image = STAGS_URL . '/assets/images/taxopress-white-logo.png';
1139
1140 if ($current_value === $default_image) {
1141 echo '<img src="' . esc_url($default_image) . '" style="max-width: 300px;" alt=""/>';
1142 echo '<p class="description">' . esc_html__('Using default TaxoPress image', 'simple-tags') . '</p>';
1143 } elseif (!empty($current_value)) {
1144 echo '<img src="' . esc_url($current_value) . '" style="max-width: 300px;" alt=""/>';
1145 }
1146 ?>
1147 </div>
1148
1149 <p class="hide-if-no-js">
1150 <a class="select-default-featured-media-field <?php echo !empty($current_value) ? 'hidden' : ''; ?>" href="#">
1151 <?php esc_html_e('Select Media', 'simple-tags'); ?>
1152 </a>
1153 <a class="use-default-featured-media-field <?php echo ($current_value === $default_image) ? 'hidden' : ''; ?>" href="#">
1154 <?php esc_html_e('Use Default Image', 'simple-tags'); ?>
1155 </a>
1156 <a class="delete-default-featured-media-field <?php echo empty($current_value) ? 'hidden' : ''; ?>" href="#">
1157 <?php esc_html_e('Remove Image', 'simple-tags'); ?>
1158 </a>
1159 </p>
1160
1161 <input type="hidden" id="default_featured_media" name="taxopress_related_post[default_featured_media]"
1162 value="<?php echo esc_attr($current_value); ?>" />
1163 </div>
1164 <p class="taxopress-field-description description"><?php esc_html_e('Select the default %post_thumb_url% to be used when a post doesn\'t have a featured image.', 'simple-tags'); ?></p>
1165 </td>
1166 </tr>
1167
1168 </table>
1169
1170 <?php
1171 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1172 echo $ui->get_td_end() . $ui->get_tr_end();
1173 ?>
1174 </table>
1175
1176 </div>
1177 <?php
1178 }//end new fields
1179
1180 ?>
1181
1182 <div class="clear"></div>
1183
1184
1185 </div>
1186 </div>
1187 </div>
1188
1189
1190 <?php if ($related_post_limit) { ?>
1191 <div class="pp-version-notice-bold-purple" style="margin-left:0px;">
1192 <div class="pp-version-notice-bold-purple-message"><?php echo esc_html__('You\'re using TaxoPress Free.
1193 The Pro version has more features and support.', 'simple-tags'); ?>
1194 </div>
1195 <div class="pp-version-notice-bold-purple-button"><a
1196 href="https://taxopress.com/taxopress/" target="_blank"><?php echo esc_html__('Upgrade to Pro', 'simple-tags'); ?></a>
1197 </div>
1198 </div>
1199
1200 <?php } ?>
1201 <?php
1202 /**
1203 * Fires after the default fieldsets on the taxonomy screen.
1204 *
1205 * @param taxopress_admin_ui $ui Admin UI instance.
1206 */
1207 do_action('taxopress_taxonomy_after_fieldsets', $ui);
1208 ?>
1209
1210 </div>
1211 </div>
1212
1213
1214 </div>
1215
1216 <div class="taxopress-right-sidebar">
1217 <div class="taxopress-right-sidebar-wrapper" style="min-height: 205px;<?php echo ($related_post_limit) ? 'display: none;' : ''; ?>">
1218
1219
1220 <?php
1221 if (!$related_post_limit) { ?>
1222 <p class="submit">
1223
1224 <?php
1225 wp_nonce_field(
1226 'taxopress_addedit_relatedpost_nonce_action',
1227 'taxopress_addedit_relatedpost_nonce_field'
1228 );
1229 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
1230 if (!empty($_GET) && !empty($_GET['action']) && 'edit' === $_GET['action']) { ?>
1231 <input type="submit" class="button-primary taxopress-taxonomy-submit taxopress-relatedposts-submit"
1232 name="relatedpost_submit"
1233 value="<?php echo esc_attr(esc_attr__(
1234 'Save Related Posts',
1235 'simple-tags'
1236 )); ?>"/>
1237 <?php
1238 } else { ?>
1239 <input type="submit" class="button-primary taxopress-taxonomy-submit taxopress-relatedposts-submit"
1240 name="relatedpost_submit"
1241 value="<?php echo esc_attr(esc_attr__(
1242 'Add Related Posts',
1243 'simple-tags'
1244 )); ?>"/>
1245 <?php } ?>
1246
1247 <input type="hidden" name="cpt_tax_status" id="cpt_tax_status"
1248 value="<?php echo esc_attr($tab); ?>"/>
1249 </p>
1250
1251 <?php if (!empty($current)) {
1252 ?>
1253 <p>
1254 <?php echo '<div class="taxopress-warning" style="">' . esc_html__(
1255 'Shortcode: ',
1256 'simple-tags'
1257 ); ?> &nbsp;
1258 <textarea
1259 style="resize: none;padding: 5px;" readonly>[taxopress_relatedposts id="<?php echo (int)$current['ID']; ?>"]</textarea>
1260 </div>
1261 </p>
1262 <?php } ?>
1263
1264 <?php
1265 }
1266 ?>
1267
1268 </div>
1269
1270 <div class="taxopress-token-right-sidebar">
1271 <div id="postbox-container-1" class="postbox-container">
1272 <div class="meta-box-sortables">
1273 <div class="postbox">
1274 <div class="postbox-header">
1275 <h3 class="hndle is-non-sortable">
1276 <span><?php echo esc_html__('Related Posts format', 'simple-tags'); ?></span>
1277 </h3>
1278 </div>
1279
1280 <div class="inside">
1281 <p><?php echo esc_html__('Here are the tokens you can use for related posts format', 'simple-tags'); ?>:</p>
1282 <ul>
1283 <li><code>%post_permalink%</code> <?php echo esc_html__('The URL of the post', 'simple-tags'); ?></li>
1284 <li><code>%post_title%</code> <?php echo esc_html__('The title of the post', 'simple-tags'); ?></li>
1285 <li><code>%post_date% </code><?php echo esc_html__('The date of the post (this shows inside a tooltip)', 'simple-tags'); ?></li>
1286 <li><code>%post_tagcount%</code> <?php echo esc_html__('The number of tags used by both posts', 'simple-tags'); ?></li>
1287 <li><code>%post_comment%</code> <?php echo esc_html__('The number of comments on the post', 'simple-tags'); ?></li>
1288 <li><code>%post_id%</code> <?php echo esc_html__('The ID of the post', 'simple-tags'); ?></li>
1289 <li><code>%post_relatedtags%</code> <?php echo esc_html__('A list of tags used by both the current post and the related post', 'simple-tags'); ?></li>
1290 <li><code>%post_excerpt%</code> <?php echo esc_html__('The post excerpt', 'simple-tags'); ?></li>
1291 <li><code>%post_thumb_url%</code> <?php echo esc_html__('The post featured image url', 'simple-tags'); ?></li>
1292 <li><code>%post_content%</code> <?php echo esc_html__('The post content', 'simple-tags'); ?></li>
1293 <li><code>%post_category%</code> <?php echo esc_html__('The post category', 'simple-tags'); ?></li>
1294 <li><code>%post_size%</code> <?php echo esc_html__('The font size of the post', 'simple-tags'); ?></li>
1295 <li><code>%post_color%</code> <?php echo esc_html__('The color of the post title', 'simple-tags'); ?></li>
1296 </ul>
1297 </div>
1298 </div>
1299 </div>
1300 </div>
1301 </div>
1302
1303 <?php do_action('taxopress_admin_after_sidebar'); ?>
1304 </div>
1305
1306 <div class="clear"></div>
1307
1308 </form>
1309
1310 </div><!-- End .wrap -->
1311
1312 <div class="clear"></div>
1313
1314 <?php # Modal Windows;?>
1315 <div class="remodal" data-remodal-id="taxopress-modal-alert"
1316 data-remodal-options="hashTracking: false, closeOnOutsideClick: false">
1317 <div class="" style="color:red;"><?php echo esc_html__('Please complete the following required fields to save your changes:', 'simple-tags'); ?></div>
1318 <div id="taxopress-modal-alert-content"></div>
1319 <br>
1320 <button data-remodal-action="cancel" class="remodal-cancel"><?php echo esc_html__('Okay', 'simple-tags'); ?></button>
1321 </div>
1322
1323 <div class="remodal" data-remodal-id="taxopress-modal-confirm"
1324 data-remodal-options="hashTracking: false, closeOnOutsideClick: false">
1325 <div id="taxopress-modal-confirm-content"></div>
1326 <br>
1327 <button data-remodal-action="cancel" class="remodal-cancel"><?php echo esc_html__('No', 'simple-tags'); ?></button>
1328 <button data-remodal-action="confirm"
1329 class="remodal-confirm"><?php echo esc_html__('Yes', 'simple-tags'); ?></button>
1330 </div>
1331 <?php
1332 }
1333
1334
1335 /**
1336 * Function to display the related posts settings page.
1337 */
1338 public function handle_relatedposts_preview()
1339 {
1340 if (!check_ajax_referer('st-admin-js', 'nonce', false)) {
1341 wp_send_json_error(['message' => __('Security check failed.', 'simple-tags')]);
1342 }
1343
1344 if (!current_user_can('simple_tags')) {
1345 wp_send_json_error(['message' => __('Permission denied.', 'simple-tags')]);
1346 }
1347
1348 $post_id = isset($_POST['preview_post_id']) ? intval($_POST['preview_post_id']) : 0;
1349 if (!$post_id) {
1350 wp_send_json_error([
1351 'html' => '<p class="taxopress-preview-message error">' .
1352 esc_html__('Select a post to see a preview.', 'simple-tags') .
1353 '</p>'
1354 ]);
1355 return;
1356 }
1357
1358 // Get current form settings
1359 $settings = [];
1360 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1361 if (isset($_POST['taxopress_related_post'])) {
1362 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1363 $settings = wp_unslash($_POST['taxopress_related_post']);
1364 }
1365
1366
1367
1368 // Create an instance of the client class
1369 $client = new SimpleTags_Client_RelatedPosts();
1370
1371 $default_featured_media = isset($settings['default_featured_media']) ?
1372 $settings['default_featured_media'] : '';
1373
1374 // If it's the default value, use the proper plugin URL path
1375 if ($default_featured_media === 'default') {
1376 $default_featured_media = STAGS_URL . '/assets/images/taxopress-white-logo.png';
1377 }
1378 // Prepare arguments with strict type casting and validation
1379 $args = array(
1380 'post_id' => $post_id,
1381 'taxonomy' => isset($settings['taxonomy']) ? sanitize_key($settings['taxonomy']) : 'post_tag',
1382 'max_related_posts' => isset($settings['max_related_posts']) ? max(1, intval($settings['max_related_posts'])) : 5,
1383 'format' => isset($settings['format']) ? sanitize_text_field($settings['format']) : 'list',
1384 'title' => isset($settings['title']) ? wp_kses_post($settings['title']) : '',
1385 'title_header' => isset($settings['title_header']) ? sanitize_text_field($settings['title_header']) : '',
1386 'hide_title' => !empty($settings['hide_title']),
1387 'xformat' => isset($settings['xformat']) ? wp_kses_post($settings['xformat']) : '',
1388 'post_types' => isset($_POST['post_types']) && is_array($_POST['post_types']) ?
1389 array_map('sanitize_key', $_POST['post_types']) : ['post'],
1390 'limit_days' => isset($settings['limit_days']) ? max(0, intval($settings['limit_days'])) : 0,
1391 'nopoststext' => isset($settings['nopoststext']) ? wp_kses_post($settings['nopoststext']) : '',
1392 'wrap_class' => isset($settings['wrap_class']) ? sanitize_html_class($settings['wrap_class']) : '',
1393 'link_class' => isset($settings['link_class']) ? sanitize_html_class($settings['link_class']) : '',
1394 'before' => isset($settings['before']) ? wp_kses_post($settings['before']) : '',
1395 'after' => isset($settings['after']) ? wp_kses_post($settings['after']) : '',
1396 'order' => isset($settings['order']) ? sanitize_text_field($settings['order']) : 'count-desc',
1397 'hide_output' => !empty($settings['hide_output']),
1398 'max_post_chars' => isset($settings['max_post_chars']) ? max(0, intval($settings['max_post_chars'])) : 100,
1399 'taxopress_max_cats' => isset($settings['taxopress_max_cats']) ? max(0, intval($settings['taxopress_max_cats'])) : 3,
1400 'taxopress_max_tags' => isset($settings['taxopress_max_tags']) ? max(0, intval($settings['taxopress_max_tags'])) : 3,
1401 'imageresolution' => isset($settings['imageresolution']) ? sanitize_text_field($settings['imageresolution']) : '1536x1536',
1402 'default_featured_media' => esc_url($default_featured_media),
1403 'dateformat' => isset($settings['dateformat']) ? sanitize_text_field($settings['dateformat']) : 'd.m.Y',
1404 'smallest' => isset($settings['smallest']) ? max(1, intval($settings['smallest'])) : 12,
1405 'largest' => isset($settings['largest']) ? max(1, intval($settings['largest'])) : 12,
1406 'unit' => isset($settings['unit']) ? sanitize_text_field($settings['unit']) : 'pt',
1407 'mincolor' => isset($settings['mincolor']) ? sanitize_hex_color($settings['mincolor']) : '#353535',
1408 'maxcolor' => isset($settings['maxcolor']) ? sanitize_hex_color($settings['maxcolor']) : '#000000',
1409 'color' => !empty($settings['color']),
1410 );
1411
1412 // Get the HTML output
1413 $output = $client->get_related_posts($args);
1414
1415 if (empty($output)) {
1416 if (!empty($settings['hide_output'])) {
1417 wp_send_json_success(['html' => '']);
1418 }
1419
1420 wp_send_json_error(['message' => __('No related posts found.', 'simple-tags')]);
1421 }
1422
1423 wp_send_json_success(['html' => $output]);
1424 }
1425 }
1426