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

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

143 lines 3.9 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', __('Related Posts (TaxoPress)', 'simple-tags'),
18 [
19 'classname' => 'widget-simpletags-relatedposts',
20 'description' => __('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 echo $before_widget;
57 echo do_shortcode('[taxopress_relatedposts id="' . $relatedposts_id . '"]');
58 echo $after_widget;
59 }
60
61 /**
62 * Update widget settings
63 *
64 * @param array $new_instance
65 * @param array $old_instance
66 *
67 * @return array
68 * @author Olatechpro
69 */
70 public function update($new_instance, $old_instance)
71 {
72 $instance = $old_instance;
73
74 foreach ((array)self::get_fields() as $field => $field_value) {
75 $instance[$field] = $new_instance[$field];
76 }
77
78 return $instance;
79 }
80
81 /**
82 * Admin form for widgets
83 *
84 * @param array $instance
85 *
86 * @return void
87 * @author Olatechpro
88 */
89 public function form($instance)
90 {
91 //Defaults
92 $instance = wp_parse_args((array)$instance, self::get_fields());
93
94 $relatedposts_data = taxopress_get_relatedpost_data();
95 if (count($relatedposts_data) > 0) {
96 $shortcode_page = sprintf(
97 '<a href="%s">%s</a>',
98 add_query_arg(
99 [
100 'page' => 'st_related_posts',
101 ],
102 admin_url('admin.php')
103 ),
104 __('this page.', 'simple-tags')
105 );
106
107 echo '<p>' . __('Related Posts are added on ', 'simple-tags');
108 echo $shortcode_page;
109 echo '</p>'
110
111 ?>
112 <p>
113 <label for="<?php echo $this->get_field_id('relatedposts_id'); ?>">
114 <?php _e('Select widget Related Posts.', 'simple-tags'); ?>
115 <select id="<?php echo $this->get_field_id('relatedposts_id'); ?>"
116 name="<?php echo $this->get_field_name('relatedposts_id'); ?>">
117 <?php foreach ($relatedposts_data as $key => $value) { ?>
118 <option <?php selected($instance['relatedposts_id'], $key); ?>
119 value="<?php echo $key; ?>"><?php echo $value['title']; ?></option>
120 <?php } ?>
121 </select>
122 </label>
123 </p>
124
125 <?php
126 } else {
127 $shortcode_page = sprintf(
128 '<a href="%s">%s</a>',
129 add_query_arg(
130 [
131 'page' => 'st_related_posts',
132 ],
133 admin_url('admin.php')
134 ),
135 __('Here', 'simple-tags')
136 );
137
138 echo '<br />' . __('No Related Posts shortcode available. Add new shortcode ', 'simple-tags');
139 echo $shortcode_page;
140 echo '<br /><br />';
141 }
142 }
143 }