PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.6.2
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.6.2
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-widget.php

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

148 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * TaxoPress widget class
5 *
6 */
7 class SimpleTags_RelatedPosts_Widget extends WP_Widget
8 {
9 /**
10 * Constructor widget
11 *
12 * @return void
13 * @author Olatechpro
14 */
15 public function __construct()
16 {
17 parent::__construct('simpletags-relatedposts', esc_html__('Related Posts (TaxoPress)', 'simple-tags'),
18 [
19 'classname' => 'widget-simpletags-relatedposts',
20 'description' => esc_html__('Taxopress Related Posts Shortcode', 'simple-tags')
21 ]
22 );
23 }
24
25 /**
26 * Default settings for widget
27 *
28 * @return array
29 * @author Olatechpro
30 */
31 public static function get_fields()
32 {
33 return [
34 'relatedposts_id' => 0,
35 ];
36 }
37
38 /**
39 * Method for theme render
40 *
41 * @param array $args
42 * @param array $instance
43 *
44 * @return void
45 * @author Olatechpro
46 */
47 public function widget($args, $instance)
48 {
49 extract($args);
50
51 // Set values and clean it
52 foreach ((array)self::get_fields() as $field => $field_value) {
53 ${$field} = isset($instance[$field]) ? trim($instance[$field]) : '';
54 }//$relatedposts_id;
55
56 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
57 echo $before_widget;
58 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
59 echo do_shortcode('[taxopress_relatedposts id="' . (int)$relatedposts_id . '"]');
60 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
61 echo $after_widget;
62 }
63
64 /**
65 * Update widget settings
66 *
67 * @param array $new_instance
68 * @param array $old_instance
69 *
70 * @return array
71 * @author Olatechpro
72 */
73 public function update($new_instance, $old_instance)
74 {
75 $instance = $old_instance;
76
77 foreach ((array)self::get_fields() as $field => $field_value) {
78 $instance[$field] = $new_instance[$field];
79 }
80
81 return $instance;
82 }
83
84 /**
85 * Admin form for widgets
86 *
87 * @param array $instance
88 *
89 * @return void
90 * @author Olatechpro
91 */
92 public function form($instance)
93 {
94 //Defaults
95 $instance = wp_parse_args((array)$instance, self::get_fields());
96
97 $relatedposts_data = taxopress_get_relatedpost_data();
98 if (count($relatedposts_data) > 0) {
99 $shortcode_page = sprintf(
100 '<a href="%s">%s</a>',
101 add_query_arg(
102 [
103 'page' => 'st_related_posts',
104 ],
105 admin_url('admin.php')
106 ),
107 esc_html__('this page.', 'simple-tags')
108 );
109
110 echo '<p>' . esc_html__('Related Posts are added on ', 'simple-tags');
111 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
112 echo $shortcode_page;
113 echo '</p>'
114
115 ?>
116 <p>
117 <label for="<?php echo esc_attr($this->get_field_id('relatedposts_id')); ?>">
118 <?php esc_html_e('Select widget Related Posts.', 'simple-tags'); ?>
119 <select id="<?php echo esc_attr($this->get_field_id('relatedposts_id')); ?>"
120 name="<?php echo esc_attr($this->get_field_name('relatedposts_id')); ?>">
121 <?php foreach ($relatedposts_data as $key => $value) { ?>
122 <option <?php selected(esc_attr($instance['relatedposts_id']), esc_attr($key)); ?>
123 value="<?php echo esc_attr($key); ?>"><?php echo esc_html_e($value['title']); ?></option>
124 <?php } ?>
125 </select>
126 </label>
127 </p>
128
129 <?php
130 } else {
131 $shortcode_page = sprintf(
132 '<a href="%s">%s</a>',
133 add_query_arg(
134 [
135 'page' => 'st_related_posts',
136 ],
137 admin_url('admin.php')
138 ),
139 esc_html__('Here', 'simple-tags')
140 );
141
142 echo '<br />' . esc_html__('No Related Posts shortcode available. Add new shortcode ', 'simple-tags');
143 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
144 echo $shortcode_page;
145 echo '<br /><br />';
146 }
147 }
148 }