PluginProbe ʕ •ᴥ•ʔ
WP Popular Posts / trunk
WP Popular Posts vtrunk
4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 5.0.0 5.0.1 5.0.2 5.1.0 5.2.0 5.2.1 5.2.2 5.2.3 5.2.4 5.3.0 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.4.0 5.4.1 5.4.2 5.5.0 5.5.1 6.0.0 6.0.1 6.0.2 6.0.3 6.0.4 6.0.5 6.1.0 6.1.1 6.1.2 6.1.3 6.1.4 6.2.0 6.2.1 6.3.0 6.3.1 6.3.2 6.3.3 6.3.4 6.4.0 6.4.1 6.4.2 7.0.0 7.0.1 7.1.0 7.2.0 7.3.0 7.3.1 7.3.2 7.3.3 7.3.4 7.3.5 7.3.6 7.3.7 7.3.8 7.4.0 trunk 2.3.7 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.2 4.0.3 4.0.5 4.0.6
wordpress-popular-posts / src / Widget / Widget.php
wordpress-popular-posts / src / Widget Last commit date
Widget.php 3 weeks ago form.php 3 weeks ago
Widget.php
246 lines
1 <?php
2
3 namespace WordPressPopularPosts\Widget;
4
5 use WordPressPopularPosts\{ Helper, Image, Output, Themer, Translate };
6 use WordPressPopularPosts\Traits\QueriesPosts;
7
8 class Widget extends \WP_Widget {
9
10 use QueriesPosts;
11
12 /**
13 * Default options.
14 *
15 * @since 5.0.0
16 * @var array
17 */
18 private $defaults = [];
19
20 /**
21 * Administrative settings.
22 *
23 * @since 2.3.3
24 * @var array
25 */
26 private $config = [];
27
28 /**
29 * Image object.
30 *
31 * @since 5.0.0
32 * @var WordPressPopularPosts\Image
33 */
34 private $thumbnail;
35
36 /**
37 * Output object.
38 *
39 * @var \WordPressPopularPosts\Output
40 * @access private
41 */
42 private $output;
43
44 /**
45 * Translate object.
46 *
47 * @var \WordPressPopularPosts\Translate $translate
48 * @access private
49 */
50 private $translate;
51
52 /**
53 * Themer object.
54 *
55 * @var \WordPressPopularPosts\Themer $themer
56 * @access private
57 */
58 private $themer;
59
60 /**
61 * Construct.
62 *
63 * @since 1.0.0
64 * @param array $options
65 * @param array $config
66 * @param \WordPressPopularPosts\Output $output
67 * @param \WordPressPopularPosts\Image $image
68 * @param \WordPressPopularPosts\Translate $translate
69 * @param \WordPressPopularPosts\Themer $themer
70 */
71 public function __construct(array $options, array $config, Output $output, Image $thumbnail, Translate $translate, Themer $themer)
72 {
73 // Create the widget
74 parent::__construct(
75 'wpp',
76 'WP Popular Posts',
77 [
78 'classname' => 'popular-posts',
79 'description' => 'The most Popular Posts on your blog.'
80 ]
81 );
82
83 $this->defaults = $options;
84 $this->config = $config;
85 $this->output = $output;
86 $this->thumbnail = $thumbnail;
87 $this->translate = $translate;
88 $this->themer = $themer;
89 }
90
91 /**
92 * Widget hooks.
93 *
94 * @since 5.0.0
95 */
96 public function hooks()
97 {
98 // Register the widget
99 add_action('widgets_init', [$this, 'register']);
100 // Remove widget from Legacy Widget block
101 add_filter('widget_types_to_hide_from_legacy_widget_block', [$this, 'remove_from_legacy_widget_block']);
102 }
103
104 /**
105 * Registers the widget.
106 *
107 * @since 5.0.0
108 */
109 public function register()
110 {
111 register_widget($this);
112 }
113
114 /**
115 * Outputs the content of the widget.
116 *
117 * @since 1.0.0
118 * @param array $args The array of form elements.
119 * @param array $instance The current instance of the widget.
120 */
121 public function widget($args, $instance)
122 {
123 /**
124 * @var string $name
125 * @var string $id
126 * @var string $description
127 * @var string $class
128 * @var string $before_widget
129 * @var string $after_widget
130 * @var string $before_title
131 * @var string $after_title
132 * @var string $widget_id
133 * @var string $widget_name
134 */
135 extract($args, EXTR_SKIP);
136
137 echo "\n" . $before_widget . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
138
139 $notice = '';
140
141 if ( is_user_logged_in() && current_user_can('manage_options') ) {
142 ob_start();
143 ?>
144 <style>
145 .wpp-notice {
146 margin: 0 0 22px;
147 padding: 18px 22px;
148 background: #fcfcf7;
149 border: #ffff63 4px solid;
150 }
151
152 .wpp-notice p {
153 color: #000 !important;
154 }
155
156 .wpp-notice p:nth-child(2n) {
157 margin: 0;
158 font-size: 0.85em;
159 }
160 </style>
161 <div class="wpp-notice">
162 <p><strong>Important notice for administrators:</strong> The WP Popular Posts "classic" widget has been removed.</p>
163 <p>This widget has reached end-of-life as of version 7.0. Please go to <strong>Appearance > Widgets > [Your Sidebar] > WP Popular Posts</strong> for instructions on migrating your popular posts list to either the WP Popular Posts block or the wpp shortcode.</p>
164 </div>
165 <?php
166 $notice = ob_get_clean() . "\n";
167 }
168
169 echo $notice;
170
171 echo "\n" . $after_widget . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
172 }
173
174 /**
175 * Generates the administration form for the widget.
176 *
177 * @since 1.0.0
178 * @param array $instance The array of keys and values for the widget.
179 */
180 public function form($instance)
181 {
182 $instance = Helper::merge_array_r(
183 $this->defaults,
184 (array) $instance
185 );
186 require plugin_dir_path(__FILE__) . '/form.php';
187 }
188
189 /**
190 * Processes the widget's options to be saved.
191 *
192 * @since 1.0.0
193 * @param array $new_instance The previous instance of values before the update.
194 * @param array $old_instance The new instance of values to be generated via the update.
195 * @return array $instance Updated instance.
196 */
197 public function update($new_instance, $old_instance)
198 {
199 if ( empty($old_instance) ) {
200 $old_instance = $this->defaults;
201 } else {
202 $old_instance = Helper::merge_array_r(
203 $this->defaults,
204 (array) $old_instance
205 );
206 }
207
208 $instance = $old_instance;
209
210 return $instance;
211 }
212
213 /**
214 * Returns data on the current sidebar.
215 *
216 * @since 5.0.0
217 * @access private
218 * @return array|null
219 */
220 private function get_sidebar_data()
221 {
222 global $wp_registered_sidebars;
223 $sidebars = wp_get_sidebars_widgets();
224
225 foreach ( (array) $sidebars as $sidebar_id => $sidebar ) {
226 if ( in_array($this->id, (array) $sidebar, true ) ) {
227 return $wp_registered_sidebars[$sidebar_id];
228 }
229 }
230
231 return null;
232 }
233
234 /**
235 * Removes the standard widget from the Legacy Widget block.
236 *
237 * @param array
238 * @return array
239 */
240 public function remove_from_legacy_widget_block(array $widget_types)
241 {
242 $widget_types[] = 'wpp';
243 return $widget_types;
244 }
245 }
246