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 / related-posts.php

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

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