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

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