PluginProbe
bbPress / 2.6.17
bbPress v2.6.17
2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 All 72 releases
← All changes | includes/common/widgets.php +832 -375 2.2.12.6.17 View file →
@@ -9,9 +9,9 @@
9 9 * @subpackage Widgets
10 10 */
11 11
12 12 // Exit if accessed directly
13 -if ( !defined( 'ABSPATH' ) ) exit;
13 +defined( 'ABSPATH' ) || exit;
14 14
15 15 /**
16 16 * bbPress Login Widget
17 17 *
@@ -16,11 +16,9 @@
16 16 * bbPress Login Widget
17 17 *
18 18 * Adds a widget which displays the login form
19 19 *
20 - * @since bbPress (r2827)
21 - *
22 - * @uses WP_Widget
20 + * @since 2.0.0 bbPress (r2827)
23 21 */
24 22 class BBP_Login_Widget extends WP_Widget {
25 23
26 24 /**
@@ -27,28 +25,27 @@
27 25 * bbPress Login Widget
28 26 *
29 27 * Registers the login widget
30 28 *
31 - * @since bbPress (r2827)
32 - *
33 - * @uses apply_filters() Calls 'bbp_login_widget_options' with the
34 - * widget options
29 + * @since 2.0.0 bbPress (r2827)
35 30 */
36 31 public function __construct() {
37 - $widget_ops = apply_filters( 'bbp_login_widget_options', array(
38 - 'classname' => 'bbp_widget_login',
39 - 'description' => __( 'A simple login form with optional links to sign-up and lost password pages.', 'bbpress' )
40 - ) );
32 + $widget_ops = apply_filters(
33 + 'bbp_login_widget_options',
34 + array(
35 + 'classname' => 'bbp_widget_login',
36 + 'description' => esc_html__( 'A simple login form with optional links to sign-up and lost password pages.', 'bbpress' ),
37 + 'customize_selective_refresh' => true
38 + )
39 + );
41 40
42 - parent::__construct( false, __( '(bbPress) Login Widget', 'bbpress' ), $widget_ops );
41 + parent::__construct( false, esc_html__( '(bbPress) Login Widget', 'bbpress' ), $widget_ops );
43 42 }
44 43
45 44 /**
46 45 * Register the widget
47 46 *
48 - * @since bbPress (r3389)
49 - *
50 - * @uses register_widget()
47 + * @since 2.0.0 bbPress (r3389)
51 48 */
52 49 public static function register_widget() {
53 50 register_widget( 'BBP_Login_Widget' );
54 51 }
@@ -55,71 +52,76 @@
55 52
56 53 /**
57 54 * Displays the output, the login form
58 55 *
59 - * @since bbPress (r2827)
56 + * @since 2.0.0 bbPress (r2827)
60 57 *
61 - * @param mixed $args Arguments
58 + * @param array $args Arguments
62 59 * @param array $instance Instance
63 - * @uses apply_filters() Calls 'bbp_login_widget_title' with the title
64 - * @uses get_template_part() To get the login/logged in form
65 60 */
66 - public function widget( $args, $instance ) {
67 - extract( $args );
61 + public function widget( $args = array(), $instance = array() ) {
68 62
69 - $title = apply_filters( 'bbp_login_widget_title', $instance['title'] );
70 - $register = apply_filters( 'bbp_login_widget_register', $instance['register'] );
71 - $lostpass = apply_filters( 'bbp_login_widget_lostpass', $instance['lostpass'] );
63 + // Get widget settings
64 + $settings = $this->parse_settings( $instance );
72 65
73 - echo $before_widget;
66 + // Typical WordPress filter
67 + $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base );
74 68
75 - if ( !empty( $title ) )
76 - echo $before_title . $title . $after_title;
69 + // bbPress filters
70 + $settings['title'] = apply_filters( 'bbp_login_widget_title', $settings['title'], $instance, $this->id_base );
71 + $settings['register'] = apply_filters( 'bbp_login_widget_register', $settings['register'], $instance, $this->id_base );
72 + $settings['lostpass'] = apply_filters( 'bbp_login_widget_lostpass', $settings['lostpass'], $instance, $this->id_base );
77 73
78 - if ( !is_user_logged_in() ) : ?>
74 + echo $args['before_widget'];
79 75
76 + if ( ! empty( $settings['title'] ) ) {
77 + echo $args['before_title'] . $settings['title'] . $args['after_title'];
78 + }
79 +
80 + if ( ! is_user_logged_in() ) : ?>
81 +
80 82 <form method="post" action="<?php bbp_wp_login_action( array( 'context' => 'login_post' ) ); ?>" class="bbp-login-form">
81 - <fieldset>
82 - <legend><?php _e( 'Log In', 'bbpress' ); ?></legend>
83 + <fieldset class="bbp-form">
84 + <legend><?php esc_html_e( 'Log In', 'bbpress' ); ?></legend>
83 85
84 86 <div class="bbp-username">
85 - <label for="user_login"><?php _e( 'Username', 'bbpress' ); ?>: </label>
86 - <input type="text" name="log" value="<?php bbp_sanitize_val( 'user_login', 'text' ); ?>" size="20" id="user_login" tabindex="<?php bbp_tab_index(); ?>" />
87 + <label for="user_login"><?php esc_html_e( 'Username', 'bbpress' ); ?>: </label>
88 + <input type="text" name="log" value="<?php bbp_sanitize_val( 'user_login', 'text' ); ?>" size="20" maxlength="100" id="user_login" autocomplete="off" />
87 89 </div>
88 90
89 91 <div class="bbp-password">
90 - <label for="user_pass"><?php _e( 'Password', 'bbpress' ); ?>: </label>
91 - <input type="password" name="pwd" value="<?php bbp_sanitize_val( 'user_pass', 'password' ); ?>" size="20" id="user_pass" tabindex="<?php bbp_tab_index(); ?>" />
92 + <label for="user_pass"><?php esc_html_e( 'Password', 'bbpress' ); ?>: </label>
93 + <input type="password" name="pwd" value="<?php bbp_sanitize_val( 'user_pass', 'password' ); ?>" size="20" id="user_pass" autocomplete="off" />
92 94 </div>
93 95
94 96 <div class="bbp-remember-me">
95 - <input type="checkbox" name="rememberme" value="forever" <?php checked( bbp_get_sanitize_val( 'rememberme', 'checkbox' ), true, true ); ?> id="rememberme" tabindex="<?php bbp_tab_index(); ?>" />
96 - <label for="rememberme"><?php _e( 'Remember Me', 'bbpress' ); ?></label>
97 + <input type="checkbox" name="rememberme" value="forever" <?php checked( bbp_get_sanitize_val( 'rememberme', 'checkbox' ) ); ?> id="rememberme" />
98 + <label for="rememberme"><?php esc_html_e( 'Keep me signed in', 'bbpress' ); ?></label>
97 99 </div>
98 100
101 + <?php do_action( 'login_form' ); ?>
102 +
99 103 <div class="bbp-submit-wrapper">
100 104
101 - <?php do_action( 'login_form' ); ?>
105 + <button type="submit" name="user-submit" id="user-submit" class="button submit user-submit"><?php esc_html_e( 'Log In', 'bbpress' ); ?></button>
102 106
103 - <button type="submit" name="user-submit" id="user-submit" tabindex="<?php bbp_tab_index(); ?>" class="button submit user-submit"><?php _e( 'Log In', 'bbpress' ); ?></button>
104 -
105 107 <?php bbp_user_login_fields(); ?>
106 108
107 109 </div>
108 110
109 - <?php if ( !empty( $register ) || !empty( $lostpass ) ) : ?>
111 + <?php if ( ! empty( $settings['register'] ) || ! empty( $settings['lostpass'] ) ) : ?>
110 112
111 113 <div class="bbp-login-links">
112 114
113 - <?php if ( !empty( $register ) ) : ?>
115 + <?php if ( ! empty( $settings['register'] ) ) : ?>
114 116
115 - <a href="<?php echo esc_url( $register ); ?>" title="<?php esc_attr_e( 'Register', 'bbpress' ); ?>" class="bbp-register-link"><?php _e( 'Register', 'bbpress' ); ?></a>
117 + <a href="<?php echo esc_url( $settings['register'] ); ?>" title="<?php esc_attr_e( 'Register', 'bbpress' ); ?>" class="bbp-register-link"><?php esc_html_e( 'Register', 'bbpress' ); ?></a>
116 118
117 119 <?php endif; ?>
118 120
119 - <?php if ( !empty( $lostpass ) ) : ?>
121 + <?php if ( ! empty( $settings['lostpass'] ) ) : ?>
120 122
121 - <a href="<?php echo esc_url( $lostpass ); ?>" title="<?php esc_attr_e( 'Lost Password', 'bbpress' ); ?>" class="bbp-lostpass-link"><?php _e( 'Lost Password', 'bbpress' ); ?></a>
123 + <a href="<?php echo esc_url( $settings['lostpass'] ); ?>" title="<?php esc_attr_e( 'Lost Password', 'bbpress' ); ?>" class="bbp-lostpass-link"><?php esc_html_e( 'Lost Password', 'bbpress' ); ?></a>
122 124
123 125 <?php endif; ?>
124 126
125 127 </div>
@@ -139,15 +141,15 @@
139 141 </div>
140 142
141 143 <?php endif;
142 144
143 - echo $after_widget;
145 + echo $args['after_widget'];
144 146 }
145 147
146 148 /**
147 149 * Update the login widget options
148 150 *
149 - * @since bbPress (r2827)
151 + * @since 2.0.0 bbPress (r2827)
150 152 *
151 153 * @param array $new_instance The new instance options
152 154 * @param array $old_instance The old instance options
153 155 */
@@ -153,10 +155,10 @@
153 155 */
154 156 public function update( $new_instance, $old_instance ) {
155 157 $instance = $old_instance;
156 158 $instance['title'] = strip_tags( $new_instance['title'] );
157 - $instance['register'] = esc_url( $new_instance['register'] );
158 - $instance['lostpass'] = esc_url( $new_instance['lostpass'] );
159 + $instance['register'] = esc_url_raw( $new_instance['register'] );
160 + $instance['lostpass'] = esc_url_raw( $new_instance['lostpass'] );
159 161
160 162 return $instance;
161 163 }
162 164
@@ -162,40 +164,53 @@
162 164
163 165 /**
164 166 * Output the login widget options form
165 167 *
166 - * @since bbPress (r2827)
168 + * @since 2.0.0 bbPress (r2827)
167 169 *
168 170 * @param $instance Instance
169 - * @uses BBP_Login_Widget::get_field_id() To output the field id
170 - * @uses BBP_Login_Widget::get_field_name() To output the field name
171 171 */
172 - public function form( $instance ) {
172 + public function form( $instance = array() ) {
173 173
174 - // Form values
175 - $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
176 - $register = !empty( $instance['register'] ) ? esc_attr( $instance['register'] ) : '';
177 - $lostpass = !empty( $instance['lostpass'] ) ? esc_attr( $instance['lostpass'] ) : '';
174 + // Get widget settings
175 + $settings = $this->parse_settings( $instance ); ?>
178 176
179 - ?>
180 -
181 177 <p>
182 - <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?>
183 - <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></label>
178 + <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'bbpress' ); ?>
179 + <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $settings['title'] ); ?>" /></label>
184 180 </p>
185 181
186 182 <p>
187 - <label for="<?php echo $this->get_field_id( 'register' ); ?>"><?php _e( 'Register URI:', 'bbpress' ); ?>
188 - <input class="widefat" id="<?php echo $this->get_field_id( 'register' ); ?>" name="<?php echo $this->get_field_name( 'register' ); ?>" type="text" value="<?php echo $register; ?>" /></label>
183 + <label for="<?php echo $this->get_field_id( 'register' ); ?>"><?php esc_html_e( 'Register URI:', 'bbpress' ); ?>
184 + <input class="widefat" id="<?php echo $this->get_field_id( 'register' ); ?>" name="<?php echo $this->get_field_name( 'register' ); ?>" type="text" value="<?php echo esc_url( $settings['register'] ); ?>" /></label>
189 185 </p>
190 186
191 187 <p>
192 - <label for="<?php echo $this->get_field_id( 'lostpass' ); ?>"><?php _e( 'Lost Password URI:', 'bbpress' ); ?>
193 - <input class="widefat" id="<?php echo $this->get_field_id( 'lostpass' ); ?>" name="<?php echo $this->get_field_name( 'lostpass' ); ?>" type="text" value="<?php echo $lostpass; ?>" /></label>
188 + <label for="<?php echo $this->get_field_id( 'lostpass' ); ?>"><?php esc_html_e( 'Lost Password URI:', 'bbpress' ); ?>
189 + <input class="widefat" id="<?php echo $this->get_field_id( 'lostpass' ); ?>" name="<?php echo $this->get_field_name( 'lostpass' ); ?>" type="text" value="<?php echo esc_url( $settings['lostpass'] ); ?>" /></label>
194 190 </p>
195 191
196 192 <?php
197 193 }
194 +
195 + /**
196 + * Merge the widget settings into defaults array.
197 + *
198 + * @since 2.3.0 bbPress (r4802)
199 + *
200 + * @param $instance Instance
201 + */
202 + public function parse_settings( $instance = array() ) {
203 + return bbp_parse_args(
204 + $instance,
205 + array(
206 + 'title' => '',
207 + 'register' => '',
208 + 'lostpass' => ''
209 + ),
210 + 'login_widget_settings'
211 + );
212 + }
198 213 }
199 214
200 215 /**
201 216 * bbPress Views Widget
@@ -201,11 +216,9 @@
201 216 * bbPress Views Widget
202 217 *
203 218 * Adds a widget which displays the view list
204 219 *
205 - * @since bbPress (r3020)
206 - *
207 - * @uses WP_Widget
220 + * @since 2.0.0 bbPress (r3020)
208 221 */
209 222 class BBP_Views_Widget extends WP_Widget {
210 223
211 224 /**
@@ -212,28 +225,27 @@
212 225 * bbPress View Widget
213 226 *
214 227 * Registers the view widget
215 228 *
216 - * @since bbPress (r3020)
217 - *
218 - * @uses apply_filters() Calls 'bbp_views_widget_options' with the
219 - * widget options
229 + * @since 2.0.0 bbPress (r3020)
220 230 */
221 231 public function __construct() {
222 - $widget_ops = apply_filters( 'bbp_views_widget_options', array(
223 - 'classname' => 'widget_display_views',
224 - 'description' => __( 'A list of registered optional topic views.', 'bbpress' )
225 - ) );
232 + $widget_ops = apply_filters(
233 + 'bbp_views_widget_options',
234 + array(
235 + 'classname' => 'widget_display_views',
236 + 'description' => esc_html__( 'A list of registered optional topic views.', 'bbpress' ),
237 + 'customize_selective_refresh' => true
238 + )
239 + );
226 240
227 - parent::__construct( false, __( '(bbPress) Topic Views List', 'bbpress' ), $widget_ops );
241 + parent::__construct( false, esc_html__( '(bbPress) Topic Views List', 'bbpress' ), $widget_ops );
228 242 }
229 243
230 244 /**
231 245 * Register the widget
232 246 *
233 - * @since bbPress (r3389)
234 - *
235 - * @uses register_widget()
247 + * @since 2.0.0 bbPress (r3389)
236 248 */
237 249 public static function register_widget() {
238 250 register_widget( 'BBP_Views_Widget' );
239 251 }
@@ -240,52 +252,186 @@
240 252
241 253 /**
242 254 * Displays the output, the view list
243 255 *
244 - * @since bbPress (r3020)
256 + * @since 2.0.0 bbPress (r3020)
245 257 *
246 - * @param mixed $args Arguments
258 + * @param array $args Arguments
247 259 * @param array $instance Instance
248 - * @uses apply_filters() Calls 'bbp_view_widget_title' with the title
249 - * @uses bbp_get_views() To get the views
250 - * @uses bbp_view_url() To output the view url
251 - * @uses bbp_view_title() To output the view title
252 260 */
253 - public function widget( $args, $instance ) {
261 + public function widget( $args = array(), $instance = array() ) {
254 262
255 263 // Only output widget contents if views exist
256 - if ( bbp_get_views() ) :
264 + if ( ! bbp_get_views() ) {
265 + return;
266 + }
257 267
258 - extract( $args );
268 + // Get widget settings
269 + $settings = $this->parse_settings( $instance );
259 270
260 - $title = apply_filters( 'bbp_view_widget_title', $instance['title'] );
271 + // Typical WordPress filter
272 + $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base );
261 273
262 - echo $before_widget;
263 - echo $before_title . $title . $after_title; ?>
274 + // bbPress filter
275 + $settings['title'] = apply_filters( 'bbp_view_widget_title', $settings['title'], $instance, $this->id_base );
264 276
265 - <ul>
277 + // Start an output buffer
278 + ob_start();
266 279
267 - <?php foreach ( bbp_get_views() as $view => $args ) : ?>
280 + echo $args['before_widget'];
268 281
269 - <li><a class="bbp-view-title" href="<?php bbp_view_url( $view ); ?>" title="<?php bbp_view_title( $view ); ?>"><?php bbp_view_title( $view ); ?></a></li>
282 + if ( ! empty( $settings['title'] ) ) {
283 + echo $args['before_title'] . $settings['title'] . $args['after_title'];
284 + } ?>
270 285
271 - <?php endforeach; ?>
286 + <ul class="bbp-views-widget">
272 287
273 - </ul>
288 + <?php foreach ( array_keys( bbp_get_views() ) as $view ) : ?>
274 289
275 - <?php echo $after_widget;
290 + <li><a class="bbp-view-title" href="<?php bbp_view_url( $view ); ?>"><?php bbp_view_title( $view ); ?></a></li>
276 291
277 - endif;
292 + <?php endforeach; ?>
293 +
294 + </ul>
295 +
296 + <?php echo $args['after_widget'];
297 +
298 + // Output the current buffer
299 + echo ob_get_clean();
278 300 }
279 301
280 302 /**
281 303 * Update the view widget options
282 304 *
283 - * @since bbPress (r3020)
305 + * @since 2.0.0 bbPress (r3020)
284 306 *
285 307 * @param array $new_instance The new instance options
286 308 * @param array $old_instance The old instance options
287 309 */
310 + public function update( $new_instance = array(), $old_instance = array() ) {
311 + $instance = $old_instance;
312 + $instance['title'] = strip_tags( $new_instance['title'] );
313 +
314 + return $instance;
315 + }
316 +
317 + /**
318 + * Output the view widget options form
319 + *
320 + * @since 2.0.0 bbPress (r3020)
321 + *
322 + * @param $instance Instance
323 + */
324 + public function form( $instance = array() ) {
325 +
326 + // Get widget settings
327 + $settings = $this->parse_settings( $instance ); ?>
328 +
329 + <p>
330 + <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'bbpress' ); ?>
331 + <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $settings['title'] ); ?>" />
332 + </label>
333 + </p>
334 +
335 + <?php
336 + }
337 +
338 + /**
339 + * Merge the widget settings into defaults array.
340 + *
341 + * @since 2.3.0 bbPress (r4802)
342 + *
343 + * @param $instance Instance
344 + */
345 + public function parse_settings( $instance = array() ) {
346 + return bbp_parse_args(
347 + $instance,
348 + array(
349 + 'title' => ''
350 + ),
351 + 'view_widget_settings'
352 + );
353 + }
354 +}
355 +
356 +/**
357 + * bbPress Search Widget
358 + *
359 + * Adds a widget which displays the forum search form
360 + *
361 + * @since 2.3.0 bbPress (r4579)
362 + */
363 +class BBP_Search_Widget extends WP_Widget {
364 +
365 + /**
366 + * bbPress Search Widget
367 + *
368 + * Registers the search widget
369 + *
370 + * @since 2.3.0 bbPress (r4579)
371 + */
372 + public function __construct() {
373 + $widget_ops = apply_filters(
374 + 'bbp_search_widget_options',
375 + array(
376 + 'classname' => 'widget_display_search',
377 + 'description' => esc_html__( 'The bbPress forum search form.', 'bbpress' ),
378 + 'customize_selective_refresh' => true
379 + )
380 + );
381 +
382 + parent::__construct( false, esc_html__( '(bbPress) Forum Search Form', 'bbpress' ), $widget_ops );
383 + }
384 +
385 + /**
386 + * Register the widget
387 + *
388 + * @since 2.3.0 bbPress (r4579)
389 + */
390 + public static function register_widget() {
391 + register_widget( 'BBP_Search_Widget' );
392 + }
393 +
394 + /**
395 + * Displays the output, the search form
396 + *
397 + * @since 2.3.0 bbPress (r4579)
398 + */
399 + public function widget( $args, $instance ) {
400 +
401 + // Bail if search is disabled
402 + if ( ! bbp_allow_search() ) {
403 + return;
404 + }
405 +
406 + // Get widget settings
407 + $settings = $this->parse_settings( $instance );
408 +
409 + // Typical WordPress filter
410 + $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base );
411 +
412 + // bbPress filter
413 + $settings['title'] = apply_filters( 'bbp_search_widget_title', $settings['title'], $instance, $this->id_base );
414 +
415 + echo $args['before_widget'];
416 +
417 + if ( ! empty( $settings['title'] ) ) {
418 + echo $args['before_title'] . $settings['title'] . $args['after_title'];
419 + }
420 +
421 + bbp_get_template_part( 'form', 'search' );
422 +
423 + echo $args['after_widget'];
424 + }
425 +
426 + /**
427 + * Update the widget options
428 + *
429 + * @since 2.3.0 bbPress (r4579)
430 + *
431 + * @param array $new_instance The new instance options
432 + * @param array $old_instance The old instance options
433 + */
288 434 public function update( $new_instance, $old_instance ) {
289 435 $instance = $old_instance;
290 436 $instance['title'] = strip_tags( $new_instance['title'] );
291 437
@@ -292,27 +438,44 @@
292 438 return $instance;
293 439 }
294 440
295 441 /**
296 - * Output the view widget options form
442 + * Output the search widget options form
297 443 *
298 - * @since bbPress (r3020)
444 + * @since 2.3.0 bbPress (r4579)
299 445 *
300 446 * @param $instance Instance
301 - * @uses BBP_Views_Widget::get_field_id() To output the field id
302 - * @uses BBP_Views_Widget::get_field_name() To output the field name
303 447 */
304 448 public function form( $instance ) {
305 - $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : ''; ?>
306 449
450 + // Get widget settings
451 + $settings = $this->parse_settings( $instance ); ?>
452 +
307 453 <p>
308 - <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?>
309 - <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
454 + <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'bbpress' ); ?>
455 + <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $settings['title'] ); ?>" />
310 456 </label>
311 457 </p>
312 458
313 459 <?php
314 460 }
461 +
462 + /**
463 + * Merge the widget settings into defaults array.
464 + *
465 + * @since 2.3.0 bbPress (r4802)
466 + *
467 + * @param $instance Instance
468 + */
469 + public function parse_settings( $instance = array() ) {
470 + return bbp_parse_args(
471 + $instance,
472 + array(
473 + 'title' => esc_html__( 'Search Forums', 'bbpress' )
474 + ),
475 + 'search_widget_settings'
476 + );
477 + }
315 478 }
316 479
317 480 /**
318 481 * bbPress Forum Widget
@@ -318,11 +481,9 @@
318 481 * bbPress Forum Widget
319 482 *
320 483 * Adds a widget which displays the forum list
321 484 *
322 - * @since bbPress (r2653)
323 - *
324 - * @uses WP_Widget
485 + * @since 2.0.0 bbPress (r2653)
325 486 */
326 487 class BBP_Forums_Widget extends WP_Widget {
327 488
328 489 /**
@@ -329,28 +490,27 @@
329 490 * bbPress Forum Widget
330 491 *
331 492 * Registers the forum widget
332 493 *
333 - * @since bbPress (r2653)
334 - *
335 - * @uses apply_filters() Calls 'bbp_forums_widget_options' with the
336 - * widget options
494 + * @since 2.0.0 bbPress (r2653)
337 495 */
338 496 public function __construct() {
339 - $widget_ops = apply_filters( 'bbp_forums_widget_options', array(
340 - 'classname' => 'widget_display_forums',
341 - 'description' => __( 'A list of forums with an option to set the parent.', 'bbpress' )
342 - ) );
497 + $widget_ops = apply_filters(
498 + 'bbp_forums_widget_options',
499 + array(
500 + 'classname' => 'widget_display_forums',
501 + 'description' => esc_html__( 'A list of forums with an option to set the parent.', 'bbpress' ),
502 + 'customize_selective_refresh' => true
503 + )
504 + );
343 505
344 - parent::__construct( false, __( '(bbPress) Forums List', 'bbpress' ), $widget_ops );
506 + parent::__construct( false, esc_html__( '(bbPress) Forums List', 'bbpress' ), $widget_ops );
345 507 }
346 508
347 509 /**
348 510 * Register the widget
349 511 *
350 - * @since bbPress (r3389)
351 - *
352 - * @uses register_widget()
512 + * @since 2.0.0 bbPress (r3389)
353 513 */
354 514 public static function register_widget() {
355 515 register_widget( 'BBP_Forums_Widget' );
356 516 }
@@ -357,66 +517,84 @@
357 517
358 518 /**
359 519 * Displays the output, the forum list
360 520 *
361 - * @since bbPress (r2653)
521 + * @since 2.0.0 bbPress (r2653)
362 522 *
363 - * @param mixed $args Arguments
523 + * @param array $args Arguments
364 524 * @param array $instance Instance
365 - * @uses apply_filters() Calls 'bbp_forum_widget_title' with the title
366 - * @uses get_option() To get the forums per page option
367 - * @uses current_user_can() To check if the current user can read
368 - * private() To resety name
369 - * @uses bbp_has_forums() The main forum loop
370 - * @uses bbp_forums() To check whether there are more forums available
371 - * in the loop
372 - * @uses bbp_the_forum() Loads up the current forum in the loop
373 - * @uses bbp_forum_permalink() To display the forum permalink
374 - * @uses bbp_forum_title() To display the forum title
375 525 */
376 526 public function widget( $args, $instance ) {
377 - extract( $args );
378 527
379 - $title = apply_filters( 'bbp_forum_widget_title', $instance['title'] );
380 - $parent_forum = !empty( $instance['parent_forum'] ) ? $instance['parent_forum'] : '0';
528 + // Get widget settings
529 + $settings = $this->parse_settings( $instance );
381 530
531 + // Typical WordPress filter
532 + $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base );
533 +
534 + // bbPress filter
535 + $settings['title'] = apply_filters( 'bbp_forum_widget_title', $settings['title'], $instance, $this->id_base );
536 +
382 537 // Note: private and hidden forums will be excluded via the
383 - // bbp_pre_get_posts_exclude_forums filter and function.
384 - $widget_query = new WP_Query( array(
385 - 'post_parent' => $parent_forum,
386 - 'post_type' => bbp_get_forum_post_type(),
387 - 'posts_per_page' => get_option( '_bbp_forums_per_page', 50 ),
388 - 'orderby' => 'menu_order',
389 - 'order' => 'ASC'
390 - ) );
538 + // bbp_pre_get_posts_normalize_forum_visibility action and function.
539 + $widget_query = new WP_Query(
540 + array(
391 541
392 - if ( $widget_query->have_posts() ) :
542 + // What and how
543 + 'post_type' => bbp_get_forum_post_type(),
544 + 'post_status' => bbp_get_public_status_id(),
545 + 'post_parent' => $settings['parent_forum'],
546 + 'posts_per_page' => (int) get_option( '_bbp_forums_per_page', 50 ),
393 547
394 - echo $before_widget;
395 - echo $before_title . $title . $after_title; ?>
548 + // Order
549 + 'orderby' => 'menu_order title',
550 + 'order' => 'ASC',
396 551
397 - <ul>
552 + // Performance
553 + 'ignore_sticky_posts' => true,
554 + 'no_found_rows' => true,
555 + 'update_post_term_cache' => false,
556 + 'update_post_meta_cache' => false
557 + )
558 + );
398 559
399 - <?php while ( $widget_query->have_posts() ) : $widget_query->the_post(); ?>
560 + // Bail if no posts
561 + if ( ! $widget_query->have_posts() ) {
562 + return;
563 + }
400 564
401 - <li><a class="bbp-forum-title" href="<?php bbp_forum_permalink( $widget_query->post->ID ); ?>" title="<?php bbp_forum_title( $widget_query->post->ID ); ?>"><?php bbp_forum_title( $widget_query->post->ID ); ?></a></li>
565 + echo $args['before_widget'];
402 566
403 - <?php endwhile; ?>
567 + if ( ! empty( $settings['title'] ) ) {
568 + echo $args['before_title'] . $settings['title'] . $args['after_title'];
569 + } ?>
404 570
405 - </ul>
571 + <ul class="bbp-forums-widget">
406 572
407 - <?php echo $after_widget;
573 + <?php while ( $widget_query->have_posts() ) :
408 574
409 - // Reset the $post global
410 - wp_reset_postdata();
575 + $widget_query->the_post(); ?>
411 576
412 - endif;
577 + <li <?php echo ( bbp_get_forum_id() === $widget_query->post->ID ? ' class="bbp-forum-widget-current-forum"' : '' ); ?>>
578 + <a class="bbp-forum-title" href="<?php bbp_forum_permalink( $widget_query->post->ID ); ?>">
579 + <?php bbp_forum_title( $widget_query->post->ID ); ?>
580 + </a>
581 + </li>
582 +
583 + <?php endwhile; ?>
584 +
585 + </ul>
586 +
587 + <?php echo $args['after_widget'];
588 +
589 + // Reset the $post global
590 + wp_reset_postdata();
413 591 }
414 592
415 593 /**
416 594 * Update the forum widget options
417 595 *
418 - * @since bbPress (r2653)
596 + * @since 2.0.0 bbPress (r2653)
419 597 *
420 598 * @param array $new_instance The new instance options
421 599 * @param array $old_instance The old instance options
422 600 */
@@ -422,12 +600,12 @@
422 600 */
423 601 public function update( $new_instance, $old_instance ) {
424 602 $instance = $old_instance;
425 603 $instance['title'] = strip_tags( $new_instance['title'] );
426 - $instance['parent_forum'] = $new_instance['parent_forum'];
604 + $instance['parent_forum'] = sanitize_text_field( $new_instance['parent_forum'] );
427 605
428 606 // Force to any
429 - if ( !empty( $instance['parent_forum'] ) && !is_numeric( $instance['parent_forum'] ) ) {
607 + if ( ! empty( $instance['parent_forum'] ) && ! is_numeric( $instance['parent_forum'] ) ) {
430 608 $instance['parent_forum'] = 'any';
431 609 }
432 610
433 611 return $instance;
@@ -435,36 +613,53 @@
435 613
436 614 /**
437 615 * Output the forum widget options form
438 616 *
439 - * @since bbPress (r2653)
617 + * @since 2.0.0 bbPress (r2653)
440 618 *
441 619 * @param $instance Instance
442 - * @uses BBP_Forums_Widget::get_field_id() To output the field id
443 - * @uses BBP_Forums_Widget::get_field_name() To output the field name
444 620 */
445 621 public function form( $instance ) {
446 - $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
447 - $parent_forum = !empty( $instance['parent_forum'] ) ? esc_attr( $instance['parent_forum'] ) : '0'; ?>
448 622
623 + // Get widget settings
624 + $settings = $this->parse_settings( $instance ); ?>
625 +
449 626 <p>
450 - <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?>
451 - <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
627 + <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'bbpress' ); ?>
628 + <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $settings['title'] ); ?>" />
452 629 </label>
453 630 </p>
454 631
455 632 <p>
456 - <label for="<?php echo $this->get_field_id( 'parent_forum' ); ?>"><?php _e( 'Parent Forum ID:', 'bbpress' ); ?>
457 - <input class="widefat" id="<?php echo $this->get_field_id( 'parent_forum' ); ?>" name="<?php echo $this->get_field_name( 'parent_forum' ); ?>" type="text" value="<?php echo $parent_forum; ?>" />
633 + <label for="<?php echo $this->get_field_id( 'parent_forum' ); ?>"><?php esc_html_e( 'Parent Forum ID:', 'bbpress' ); ?>
634 + <input class="widefat" id="<?php echo $this->get_field_id( 'parent_forum' ); ?>" name="<?php echo $this->get_field_name( 'parent_forum' ); ?>" type="text" value="<?php echo esc_attr( $settings['parent_forum'] ); ?>" />
458 635 </label>
459 636
460 637 <br />
461 638
462 - <small><?php _e( '"0" to show only root - "any" to show all', 'bbpress' ); ?></small>
639 + <small><?php esc_html_e( '"0" to show only root - "any" to show all', 'bbpress' ); ?></small>
463 640 </p>
464 641
465 642 <?php
466 643 }
644 +
645 + /**
646 + * Merge the widget settings into defaults array.
647 + *
648 + * @since 2.3.0 bbPress (r4802)
649 + *
650 + * @param $instance Instance
651 + */
652 + public function parse_settings( $instance = array() ) {
653 + return bbp_parse_args(
654 + $instance,
655 + array(
656 + 'title' => esc_html__( 'Forums', 'bbpress' ),
657 + 'parent_forum' => 0
658 + ),
659 + 'forum_widget_settings'
660 + );
661 + }
467 662 }
468 663
469 664 /**
470 665 * bbPress Topic Widget
@@ -470,11 +665,9 @@
470 665 * bbPress Topic Widget
471 666 *
472 667 * Adds a widget which displays the topic list
473 668 *
474 - * @since bbPress (r2653)
475 - *
476 - * @uses WP_Widget
669 + * @since 2.0.0 bbPress (r2653)
477 670 */
478 671 class BBP_Topics_Widget extends WP_Widget {
479 672
480 673 /**
@@ -481,28 +674,27 @@
481 674 * bbPress Topic Widget
482 675 *
483 676 * Registers the topic widget
484 677 *
485 - * @since bbPress (r2653)
486 - *
487 - * @uses apply_filters() Calls 'bbp_topics_widget_options' with the
488 - * widget options
678 + * @since 2.0.0 bbPress (r2653)
489 679 */
490 680 public function __construct() {
491 - $widget_ops = apply_filters( 'bbp_topics_widget_options', array(
492 - 'classname' => 'widget_display_topics',
493 - 'description' => __( 'A list of recent topics, sorted by popularity or freshness.', 'bbpress' )
494 - ) );
681 + $widget_ops = apply_filters(
682 + 'bbp_topics_widget_options',
683 + array(
684 + 'classname' => 'widget_display_topics',
685 + 'description' => esc_html__( 'A list of recent topics, sorted by: newness, popularity, or recent replies.', 'bbpress' ),
686 + 'customize_selective_refresh' => true
687 + )
688 + );
495 689
496 - parent::__construct( false, __( '(bbPress) Recent Topics', 'bbpress' ), $widget_ops );
690 + parent::__construct( false, esc_html__( '(bbPress) Recent Topics', 'bbpress' ), $widget_ops );
497 691 }
498 692
499 693 /**
500 694 * Register the widget
501 695 *
502 - * @since bbPress (r3389)
503 - *
504 - * @uses register_widget()
696 + * @since 2.0.0 bbPress (r3389)
505 697 */
506 698 public static function register_widget() {
507 699 register_widget( 'BBP_Topics_Widget' );
508 700 }
@@ -509,46 +701,52 @@
509 701
510 702 /**
511 703 * Displays the output, the topic list
512 704 *
513 - * @since bbPress (r2653)
705 + * @since 2.0.0 bbPress (r2653)
514 706 *
515 - * @param mixed $args
707 + * @param array $args
516 708 * @param array $instance
517 - * @uses apply_filters() Calls 'bbp_topic_widget_title' with the title
518 - * @uses bbp_topic_permalink() To display the topic permalink
519 - * @uses bbp_topic_title() To display the topic title
520 - * @uses bbp_get_topic_last_active_time() To get the topic last active
521 - * time
522 - * @uses bbp_get_topic_id() To get the topic id
523 709 */
524 - public function widget( $args, $instance ) {
710 + public function widget( $args = array(), $instance = array() ) {
525 711
526 - extract( $args );
712 + // Get widget settings
713 + $settings = $this->parse_settings( $instance );
527 714
528 - $title = apply_filters( 'bbp_topic_widget_title', $instance['title'] );
529 - $max_shown = !empty( $instance['max_shown'] ) ? (int) $instance['max_shown'] : 5;
530 - $show_date = !empty( $instance['show_date'] ) ? 'on' : false;
531 - $show_user = !empty( $instance['show_user'] ) ? 'on' : false;
532 - $parent_forum = !empty( $instance['parent_forum'] ) ? $instance['parent_forum'] : 'any';
533 - $order_by = !empty( $instance['order_by'] ) ? $instance['order_by'] : false;
715 + // Typical WordPress filter
716 + $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base );
534 717
718 + // bbPress filter
719 + $settings['title'] = apply_filters( 'bbp_topic_widget_title', $settings['title'], $instance, $this->id_base );
720 +
535 721 // How do we want to order our results?
536 - switch ( $order_by ) {
722 + switch ( $settings['order_by'] ) {
537 723
538 724 // Order by most recent replies
539 725 case 'freshness' :
540 726 $topics_query = array(
541 - 'author' => 0,
727 +
728 + // What and how
542 729 'post_type' => bbp_get_topic_post_type(),
543 - 'post_parent' => $parent_forum,
544 - 'posts_per_page' => $max_shown,
545 - 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ),
546 - 'show_stickes' => false,
547 - 'meta_key' => '_bbp_last_active_time',
548 - 'orderby' => 'meta_value',
549 - 'order' => 'DESC',
550 - 'meta_query' => array( bbp_exclude_forum_ids( 'meta_query' ) )
730 + 'post_status' => bbp_get_public_topic_statuses(),
731 + 'post_parent' => $settings['parent_forum'],
732 + 'posts_per_page' => (int) $settings['max_shown'],
733 + 'meta_query' => array(
734 + array(
735 + 'key' => '_bbp_last_active_time',
736 + 'type' => 'DATETIME'
737 + )
738 + ),
739 +
740 + // Ordering
741 + 'orderby' => 'meta_value',
742 + 'order' => 'DESC',
743 +
744 + // Performance
745 + 'ignore_sticky_posts' => true,
746 + 'no_found_rows' => true,
747 + 'update_post_term_cache' => false,
748 + 'update_post_meta_cache' => false
551 749 );
552 750 break;
553 751
554 752 // Order by total number of replies
@@ -553,19 +751,31 @@
553 751
554 752 // Order by total number of replies
555 753 case 'popular' :
556 754 $topics_query = array(
557 - 'author' => 0,
755 +
756 + // What and how
558 757 'post_type' => bbp_get_topic_post_type(),
559 - 'post_parent' => $parent_forum,
560 - 'posts_per_page' => $max_shown,
561 - 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ),
562 - 'show_stickes' => false,
563 - 'meta_key' => '_bbp_reply_count',
564 - 'orderby' => 'meta_value',
565 - 'order' => 'DESC',
566 - 'meta_query' => array( bbp_exclude_forum_ids( 'meta_query' ) )
567 - );
758 + 'post_status' => bbp_get_public_topic_statuses(),
759 + 'post_parent' => $settings['parent_forum'],
760 + 'posts_per_page' => (int) $settings['max_shown'],
761 + 'meta_query' => array(
762 + array(
763 + 'key' => '_bbp_reply_count',
764 + 'type' => 'NUMERIC'
765 + )
766 + ),
767 +
768 + // Ordering
769 + 'orderby' => 'meta_value_num',
770 + 'order' => 'DESC',
771 +
772 + // Performance
773 + 'ignore_sticky_posts' => true,
774 + 'no_found_rows' => true,
775 + 'update_post_term_cache' => false,
776 + 'update_post_meta_cache' => false
777 + );
568 778 break;
569 779
570 780 // Order by which topic was created most recently
571 781 case 'newness' :
@@ -570,83 +780,131 @@
570 780 // Order by which topic was created most recently
571 781 case 'newness' :
572 782 default :
573 783 $topics_query = array(
574 - 'author' => 0,
784 +
785 + // What and how
575 786 'post_type' => bbp_get_topic_post_type(),
576 - 'post_parent' => $parent_forum,
577 - 'posts_per_page' => $max_shown,
578 - 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ),
579 - 'show_stickes' => false,
580 - 'order' => 'DESC',
581 - 'meta_query' => array( bbp_exclude_forum_ids( 'meta_query' ) )
582 - );
787 + 'post_status' => bbp_get_public_topic_statuses(),
788 + 'post_parent' => $settings['parent_forum'],
789 + 'posts_per_page' => (int) $settings['max_shown'],
790 +
791 + // Ordering
792 + 'orderby' => 'date',
793 + 'order' => 'DESC',
794 +
795 + // Performance
796 + 'ignore_sticky_posts' => true,
797 + 'no_found_rows' => true,
798 + 'update_post_term_cache' => false,
799 + 'update_post_meta_cache' => false
800 + );
583 801 break;
584 802 }
585 -
803 +
586 804 // Note: private and hidden forums will be excluded via the
587 - // bbp_pre_get_posts_exclude_forums filter and function.
805 + // bbp_pre_get_posts_normalize_forum_visibility action and function.
588 806 $widget_query = new WP_Query( $topics_query );
589 807
590 - // Topics exist
591 - if ( $widget_query->have_posts() ) :
592 -
593 - echo $before_widget;
594 - echo $before_title . $title . $after_title; ?>
808 + // Bail if no topics are found
809 + if ( ! $widget_query->have_posts() ) {
810 + return;
811 + }
595 812
596 - <ul>
813 + // Start an output buffer
814 + ob_start();
597 815
598 - <?php while ( $widget_query->have_posts() ) :
816 + echo $args['before_widget'];
599 817
600 - $widget_query->the_post();
601 - $topic_id = bbp_get_topic_id( $widget_query->post->ID );
602 - $author_link = bbp_get_topic_author_link( array( 'post_id' => $topic_id, 'type' => 'both', 'size' => 14 ) ); ?>
818 + if ( ! empty( $settings['title'] ) ) {
819 + echo $args['before_title'] . $settings['title'] . $args['after_title'];
820 + } ?>
603 821
604 - <li>
605 - <a class="bbp-forum-title" href="<?php bbp_topic_permalink( $topic_id ); ?>" title="<?php bbp_topic_title( $topic_id ); ?>"><?php bbp_topic_title( $topic_id ); ?></a>
822 + <ul class="bbp-topics-widget <?php echo esc_attr( $settings['order_by'] ); ?>">
606 823
607 - <?php if ( 'on' == $show_user ) : ?>
824 + <?php while ( $widget_query->have_posts() ) :
608 825
609 - <?php printf( _x( 'by %1$s', 'widgets', 'bbpress' ), '<span class="topic-author">' . $author_link . '</span>' ); ?>
826 + $widget_query->the_post();
827 + $topic_id = bbp_get_topic_id( $widget_query->post->ID );
828 + $author_link = '';
610 829
611 - <?php endif; ?>
830 + // Maybe get the topic author
831 + if ( ! empty( $settings['show_user'] ) ) :
832 + $author_link = bbp_get_topic_author_link(
833 + array(
834 + 'post_id' => $topic_id,
835 + 'type' => 'both',
836 + 'size' => 14
837 + )
838 + );
839 + endif; ?>
612 840
613 - <?php if ( 'on' == $show_date ) : ?>
841 + <li>
842 + <a class="bbp-forum-title" href="<?php bbp_topic_permalink( $topic_id ); ?>"><?php bbp_topic_title( $topic_id ); ?></a>
614 843
615 - <div><?php bbp_topic_last_active_time( $topic_id ); ?></div>
844 + <?php if ( ! empty( $author_link ) ) : ?>
616 845
617 - <?php endif; ?>
846 + <?php
847 + printf(
848 + /* translators: %1$s: Topic author link wrapped in span tag */
849 + esc_html_x( 'by %1$s', 'widgets', 'bbpress' ),
850 + '<span class="topic-author">' . $author_link . '</span>'
851 + );
852 + ?>
618 853
619 - </li>
854 + <?php endif; ?>
620 855
621 - <?php endwhile; ?>
856 + <?php if ( ! empty( $settings['show_date'] ) ) : ?>
622 857
623 - </ul>
858 + <div><?php bbp_topic_last_active_time( $topic_id ); ?></div>
624 859
625 - <?php echo $after_widget;
860 + <?php endif; ?>
626 861
627 - // Reset the $post global
628 - wp_reset_postdata();
862 + </li>
629 863
630 - endif;
864 + <?php endwhile; ?>
865 +
866 + </ul>
867 +
868 + <?php echo $args['after_widget'];
869 +
870 + // Reset the $post global
871 + wp_reset_postdata();
872 +
873 + // Output the current buffer
874 + echo ob_get_clean();
631 875 }
632 876
633 877 /**
634 878 * Update the topic widget options
635 879 *
636 - * @since bbPress (r2653)
880 + * @since 2.0.0 bbPress (r2653)
637 881 *
638 882 * @param array $new_instance The new instance options
639 883 * @param array $old_instance The old instance options
640 884 */
641 - public function update( $new_instance, $old_instance ) {
642 - $instance = $old_instance;
643 - $instance['title'] = strip_tags( $new_instance['title'] );
644 - $instance['max_shown'] = strip_tags( $new_instance['max_shown'] );
645 - $instance['show_date'] = strip_tags( $new_instance['show_date'] );
646 - $instance['show_user'] = strip_tags( $new_instance['show_user'] );
647 - $instance['order_by'] = strip_tags( $new_instance['order_by'] );
885 + public function update( $new_instance = array(), $old_instance = array() ) {
886 + $instance = $old_instance;
887 + $instance['title'] = strip_tags( $new_instance['title'] );
888 + $instance['order_by'] = strip_tags( $new_instance['order_by'] );
889 + $instance['parent_forum'] = sanitize_text_field( $new_instance['parent_forum'] );
890 + $instance['max_shown'] = (int) $new_instance['max_shown'];
648 891
892 + // Date
893 + $instance['show_date'] = isset( $new_instance['show_date'] )
894 + ? (bool) $new_instance['show_date']
895 + : false;
896 +
897 + // Author
898 + $instance['show_user'] = isset( $new_instance['show_user'] )
899 + ? (bool) $new_instance['show_user']
900 + : false;
901 +
902 + // Force to any
903 + if ( ! empty( $instance['parent_forum'] ) && ! is_numeric( $instance['parent_forum'] ) ) {
904 + $instance['parent_forum'] = 'any';
905 + }
906 +
649 907 return $instance;
650 908 }
651 909
652 910 /**
@@ -651,47 +909,200 @@
651 909
652 910 /**
653 911 * Output the topic widget options form
654 912 *
655 - * @since bbPress (r2653)
913 + * @since 2.0.0 bbPress (r2653)
656 914 *
657 915 * @param $instance Instance
658 - * @uses BBP_Topics_Widget::get_field_id() To output the field id
659 - * @uses BBP_Topics_Widget::get_field_name() To output the field name
660 916 */
661 - public function form( $instance ) {
662 - $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
663 - $max_shown = !empty( $instance['max_shown'] ) ? esc_attr( $instance['max_shown'] ) : '';
664 - $show_date = !empty( $instance['show_date'] ) ? esc_attr( $instance['show_date'] ) : '';
665 - $show_user = !empty( $instance['show_user'] ) ? esc_attr( $instance['show_user'] ) : '';
666 - $order_by = !empty( $instance['order_by'] ) ? esc_attr( $instance['order_by'] ) : ''; ?>
917 + public function form( $instance = array() ) {
667 918
668 - <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
669 - <p><label for="<?php echo $this->get_field_id( 'max_shown' ); ?>"><?php _e( 'Maximum topics to show:', 'bbpress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_shown' ); ?>" name="<?php echo $this->get_field_name( 'max_shown' ); ?>" type="text" value="<?php echo $max_shown; ?>" /></label></p>
670 - <p><label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Show post date:', 'bbpress' ); ?> <input type="checkbox" id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" <?php checked( 'on', $show_date ); ?> /></label></p>
671 - <p><label for="<?php echo $this->get_field_id( 'show_user' ); ?>"><?php _e( 'Show topic author:', 'bbpress' ); ?> <input type="checkbox" id="<?php echo $this->get_field_id( 'show_user' ); ?>" name="<?php echo $this->get_field_name( 'show_user' ); ?>" <?php checked( 'on', $show_user ); ?> /></label></p>
919 + // Get widget settings
920 + $settings = $this->parse_settings( $instance ); ?>
672 921
922 + <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'bbpress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $settings['title'] ); ?>" /></label></p>
923 + <p><label for="<?php echo $this->get_field_id( 'max_shown' ); ?>"><?php esc_html_e( 'Maximum topics to show:', 'bbpress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_shown' ); ?>" name="<?php echo $this->get_field_name( 'max_shown' ); ?>" type="text" value="<?php echo esc_attr( $settings['max_shown'] ); ?>" /></label></p>
924 +
673 925 <p>
674 - <label for="<?php echo $this->get_field_id( 'order_by' ); ?>"><?php _e( 'Order By:', 'bbpress' ); ?></label>
675 - <select name="<?php echo $this->get_field_name( 'order_by' ); ?>" id="<?php echo $this->get_field_name( 'order_by' ); ?>">
676 - <option <?php selected( $order_by, 'newness' ); ?> value="newness"><?php _e( 'Newest Topics', 'bbpress' ); ?></option>
677 - <option <?php selected( $order_by, 'popular' ); ?> value="popular"><?php _e( 'Popular Topics', 'bbpress' ); ?></option>
678 - <option <?php selected( $order_by, 'freshness' ); ?> value="freshness"><?php _e( 'Topics With Recent Replies', 'bbpress' ); ?></option>
926 + <label for="<?php echo $this->get_field_id( 'parent_forum' ); ?>"><?php esc_html_e( 'Parent Forum ID:', 'bbpress' ); ?>
927 + <input class="widefat" id="<?php echo $this->get_field_id( 'parent_forum' ); ?>" name="<?php echo $this->get_field_name( 'parent_forum' ); ?>" type="text" value="<?php echo esc_attr( $settings['parent_forum'] ); ?>" />
928 + </label>
929 +
930 + <br />
931 +
932 + <small><?php esc_html_e( '"0" to show only root - "any" to show all', 'bbpress' ); ?></small>
933 + </p>
934 +
935 + <p><label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php esc_html_e( 'Show post date:', 'bbpress' ); ?> <input type="checkbox" id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" <?php checked( true, $settings['show_date'] ); ?> value="1" /></label></p>
936 + <p><label for="<?php echo $this->get_field_id( 'show_user' ); ?>"><?php esc_html_e( 'Show topic author:', 'bbpress' ); ?> <input type="checkbox" id="<?php echo $this->get_field_id( 'show_user' ); ?>" name="<?php echo $this->get_field_name( 'show_user' ); ?>" <?php checked( true, $settings['show_user'] ); ?> value="1" /></label></p>
937 +
938 + <p>
939 + <label for="<?php echo $this->get_field_id( 'order_by' ); ?>"><?php esc_html_e( 'Order By:', 'bbpress' ); ?></label>
940 + <select name="<?php echo $this->get_field_name( 'order_by' ); ?>" id="<?php echo $this->get_field_id( 'order_by' ); ?>">
941 + <option <?php selected( $settings['order_by'], 'newness' ); ?> value="newness"><?php esc_html_e( 'Newest Topics', 'bbpress' ); ?></option>
942 + <option <?php selected( $settings['order_by'], 'popular' ); ?> value="popular"><?php esc_html_e( 'Popular Topics', 'bbpress' ); ?></option>
943 + <option <?php selected( $settings['order_by'], 'freshness' ); ?> value="freshness"><?php esc_html_e( 'Topics With Recent Replies', 'bbpress' ); ?></option>
679 944 </select>
680 945 </p>
681 946
682 947 <?php
683 948 }
949 +
950 + /**
951 + * Merge the widget settings into defaults array.
952 + *
953 + * @since 2.3.0 bbPress (r4802)
954 + *
955 + * @param $instance Instance
956 + */
957 + public function parse_settings( $instance = array() ) {
958 + return bbp_parse_args(
959 + $instance,
960 + array(
961 + 'title' => esc_html__( 'Recent Topics', 'bbpress' ),
962 + 'max_shown' => 5,
963 + 'show_date' => false,
964 + 'show_user' => false,
965 + 'parent_forum' => 'any',
966 + 'order_by' => false
967 + ),
968 + 'topic_widget_settings'
969 + );
970 + }
684 971 }
685 972
686 973 /**
974 + * bbPress Statistics Widget
975 + *
976 + * Adds a widget which displays the forum statistics
977 + *
978 + * @since 2.3.0 bbPress (r4509)
979 + */
980 +class BBP_Stats_Widget extends WP_Widget {
981 +
982 + /**
983 + * bbPress Statistics Widget
984 + *
985 + * Registers the statistics widget
986 + *
987 + * @since 2.3.0 bbPress (r4509)
988 + */
989 + public function __construct() {
990 + $widget_ops = apply_filters(
991 + 'bbp_stats_widget_options',
992 + array(
993 + 'classname' => 'widget_display_stats',
994 + 'description' => esc_html__( 'Some statistics from your forum.', 'bbpress' ),
995 + 'customize_selective_refresh' => true
996 + )
997 + );
998 +
999 + parent::__construct( false, esc_html__( '(bbPress) Statistics', 'bbpress' ), $widget_ops );
1000 + }
1001 +
1002 + /**
1003 + * Register the widget
1004 + *
1005 + * @since 2.3.0 bbPress (r4509)
1006 + */
1007 + public static function register_widget() {
1008 + register_widget( 'BBP_Stats_Widget' );
1009 + }
1010 +
1011 + /**
1012 + * Displays the output, the statistics
1013 + *
1014 + * @since 2.3.0 bbPress (r4509)
1015 + *
1016 + * @param array $args Arguments
1017 + * @param array $instance Instance
1018 + */
1019 + public function widget( $args = array(), $instance = array() ) {
1020 +
1021 + // Get widget settings
1022 + $settings = $this->parse_settings( $instance );
1023 +
1024 + // Typical WordPress filter
1025 + $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base );
1026 +
1027 + // bbPress widget title filter
1028 + $settings['title'] = apply_filters( 'bbp_stats_widget_title', $settings['title'], $instance, $this->id_base );
1029 +
1030 + echo $args['before_widget'];
1031 +
1032 + if ( ! empty( $settings['title'] ) ) {
1033 + echo $args['before_title'] . $settings['title'] . $args['after_title'];
1034 + }
1035 +
1036 + bbp_get_template_part( 'content', 'statistics' );
1037 +
1038 + echo $args['after_widget'];
1039 + }
1040 +
1041 + /**
1042 + * Update the statistics widget options
1043 + *
1044 + * @since 2.3.0 bbPress (r4509)
1045 + *
1046 + * @param array $new_instance The new instance options
1047 + * @param array $old_instance The old instance options
1048 + *
1049 + * @return array
1050 + */
1051 + public function update( $new_instance, $old_instance ) {
1052 + $instance = $old_instance;
1053 + $instance['title'] = strip_tags( $new_instance['title'] );
1054 +
1055 + return $instance;
1056 + }
1057 +
1058 + /**
1059 + * Output the statistics widget options form
1060 + *
1061 + * @since 2.3.0 bbPress (r4509)
1062 + *
1063 + * @param $instance
1064 + *
1065 + * @return string|void
1066 + */
1067 + public function form( $instance ) {
1068 +
1069 + // Get widget settings
1070 + $settings = $this->parse_settings( $instance ); ?>
1071 +
1072 + <p>
1073 + <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'bbpress' ); ?>
1074 + <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $settings['title'] ); ?>"/>
1075 + </label>
1076 + </p>
1077 +
1078 + <?php
1079 + }
1080 +
1081 + /**
1082 + * Merge the widget settings into defaults array.
1083 + *
1084 + * @since 2.3.0 bbPress (r4802)
1085 + *
1086 + * @param $instance Instance
1087 + */
1088 + public function parse_settings( $instance = array() ) {
1089 + return bbp_parse_args(
1090 + $instance,
1091 + array(
1092 + 'title' => esc_html__( 'Forum Statistics', 'bbpress' )
1093 + ),
1094 + 'stats_widget_settings'
1095 + );
1096 + }
1097 +}
1098 +
1099 +/**
687 1100 * bbPress Replies Widget
688 1101 *
689 1102 * Adds a widget which displays the replies list
690 1103 *
691 - * @since bbPress (r2653)
692 - *
693 - * @uses WP_Widget
1104 + * @since 2.0.0 bbPress (r2653)
694 1105 */
695 1106 class BBP_Replies_Widget extends WP_Widget {
696 1107
697 1108 /**
@@ -698,28 +1109,27 @@
698 1109 * bbPress Replies Widget
699 1110 *
700 1111 * Registers the replies widget
701 1112 *
702 - * @since bbPress (r2653)
703 - *
704 - * @uses apply_filters() Calls 'bbp_replies_widget_options' with the
705 - * widget options
1113 + * @since 2.0.0 bbPress (r2653)
706 1114 */
707 1115 public function __construct() {
708 - $widget_ops = apply_filters( 'bbp_replies_widget_options', array(
709 - 'classname' => 'widget_display_replies',
710 - 'description' => __( 'A list of the most recent replies.', 'bbpress' )
711 - ) );
1116 + $widget_ops = apply_filters(
1117 + 'bbp_replies_widget_options',
1118 + array(
1119 + 'classname' => 'widget_display_replies',
1120 + 'description' => esc_html__( 'A list of the most recent replies.', 'bbpress' ),
1121 + 'customize_selective_refresh' => true
1122 + )
1123 + );
712 1124
713 - parent::__construct( false, __( '(bbPress) Recent Replies', 'bbpress' ), $widget_ops );
1125 + parent::__construct( false, esc_html__( '(bbPress) Recent Replies', 'bbpress' ), $widget_ops );
714 1126 }
715 1127
716 1128 /**
717 1129 * Register the widget
718 1130 *
719 - * @since bbPress (r3389)
720 - *
721 - * @uses register_widget()
1131 + * @since 2.0.0 bbPress (r3389)
722 1132 */
723 1133 public static function register_widget() {
724 1134 register_widget( 'BBP_Replies_Widget' );
725 1135 }
@@ -726,116 +1136,146 @@
726 1136
727 1137 /**
728 1138 * Displays the output, the replies list
729 1139 *
730 - * @since bbPress (r2653)
1140 + * @since 2.0.0 bbPress (r2653)
731 1141 *
732 - * @param mixed $args
1142 + * @param array $args
733 1143 * @param array $instance
734 - * @uses apply_filters() Calls 'bbp_reply_widget_title' with the title
735 - * @uses bbp_get_reply_author_link() To get the reply author link
736 - * @uses bbp_get_reply_author() To get the reply author name
737 - * @uses bbp_get_reply_id() To get the reply id
738 - * @uses bbp_get_reply_url() To get the reply url
739 - * @uses bbp_get_reply_excerpt() To get the reply excerpt
740 - * @uses bbp_get_reply_topic_title() To get the reply topic title
741 - * @uses get_the_date() To get the date of the reply
742 - * @uses get_the_time() To get the time of the reply
743 1144 */
744 1145 public function widget( $args, $instance ) {
745 1146
746 - extract( $args );
1147 + // Get widget settings
1148 + $settings = $this->parse_settings( $instance );
747 1149
748 - $title = apply_filters( 'bbp_replies_widget_title', $instance['title'] );
749 - $max_shown = !empty( $instance['max_shown'] ) ? $instance['max_shown'] : '5';
750 - $show_date = !empty( $instance['show_date'] ) ? 'on' : false;
751 - $show_user = !empty( $instance['show_user'] ) ? 'on' : false;
752 - $post_types = !empty( $instance['post_type'] ) ? array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) : bbp_get_reply_post_type();
1150 + // Typical WordPress filter
1151 + $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base );
753 1152
1153 + // bbPress filter
1154 + $settings['title'] = apply_filters( 'bbp_replies_widget_title', $settings['title'], $instance, $this->id_base );
1155 +
754 1156 // Note: private and hidden forums will be excluded via the
755 - // bbp_pre_get_posts_exclude_forums filter and function.
756 - $widget_query = new WP_Query( array(
757 - 'post_type' => $post_types,
758 - 'post_status' => join( ',', array( bbp_get_public_status_id(), bbp_get_closed_status_id() ) ),
759 - 'posts_per_page' => $max_shown,
760 - 'meta_query' => array( bbp_exclude_forum_ids( 'meta_query' ) )
761 - ) );
1157 + // bbp_pre_get_posts_normalize_forum_visibility action and function.
1158 + $widget_query = new WP_Query(
1159 + array(
762 1160
763 - // Get replies and display them
764 - if ( $widget_query->have_posts() ) :
1161 + // What and when
1162 + 'post_type' => bbp_get_reply_post_type(),
1163 + 'post_status' => bbp_get_public_reply_statuses(),
1164 + 'posts_per_page' => (int) $settings['max_shown'],
765 1165
766 - echo $before_widget;
767 - echo $before_title . $title . $after_title; ?>
1166 + // Performance
1167 + 'ignore_sticky_posts' => true,
1168 + 'no_found_rows' => true,
1169 + 'update_post_term_cache' => false,
1170 + 'update_post_meta_cache' => false
1171 + )
1172 + );
768 1173
769 - <ul>
1174 + // Bail if no replies
1175 + if ( ! $widget_query->have_posts() ) {
1176 + return;
1177 + }
770 1178
771 - <?php while ( $widget_query->have_posts() ) : $widget_query->the_post(); ?>
1179 + // Start an output buffer
1180 + ob_start();
772 1181
773 - <li>
1182 + echo $args['before_widget'];
774 1183
775 - <?php
1184 + if ( ! empty( $settings['title'] ) ) {
1185 + echo $args['before_title'] . $settings['title'] . $args['after_title'];
1186 + } ?>
776 1187
777 - $reply_id = bbp_get_reply_id( $widget_query->post->ID );
778 - $author_link = bbp_get_reply_author_link( array( 'post_id' => $reply_id, 'type' => 'both', 'size' => 14 ) );
779 - $reply_link = '<a class="bbp-reply-topic-title" href="' . esc_url( bbp_get_reply_url( $reply_id ) ) . '" title="' . bbp_get_reply_excerpt( $reply_id, 50 ) . '">' . bbp_get_reply_topic_title( $reply_id ) . '</a>';
1188 + <ul class="bbp-replies-widget">
780 1189
781 - // Reply author, link, and timestamp
782 - if ( ( 'on' == $show_date ) && ( 'on' == $show_user ) ) :
1190 + <?php while ( $widget_query->have_posts() ) :
783 1191
784 - // translators: 1: reply author, 2: reply link, 3: reply timestamp
785 - printf( _x( '%1$s on %2$s %3$s', 'widgets', 'bbpress' ), $author_link, $reply_link, '<div>' . bbp_get_time_since( get_the_time( 'U' ) ) . '</div>' );
1192 + $widget_query->the_post(); ?>
786 1193
787 - // Reply link and timestamp
788 - elseif ( $show_date == 'on' ) :
1194 + <li>
789 1195
790 - // translators: 1: reply link, 2: reply timestamp
791 - printf( _x( '%1$s %2$s', 'widgets', 'bbpress' ), $reply_link, '<div>' . bbp_get_time_since( get_the_time( 'U' ) ) . '</div>' );
1196 + <?php
792 1197
793 - // Reply author and title
794 - elseif ( $show_user == 'on' ) :
1198 + // Verify the reply ID
1199 + $reply_id = bbp_get_reply_id( $widget_query->post->ID );
1200 + $reply_link = '<a class="bbp-reply-topic-title" href="' . esc_url( bbp_get_reply_url( $reply_id ) ) . '" title="' . esc_attr( bbp_get_reply_excerpt( $reply_id, 50 ) ) . '">' . esc_html( bbp_get_reply_topic_title( $reply_id ) ) . '</a>';
1201 + $time = get_the_time( 'U', $reply_id );
1202 + $show_date = '<time datetime="' . gmdate( 'Y-m-d H:i:s', $time ) . '">' . esc_html( bbp_get_time_since( $time ) ) . '</time>';
795 1203
796 - // translators: 1: reply author, 2: reply link
797 - printf( _x( '%1$s on %2$s', 'widgets', 'bbpress' ), $author_link, $reply_link );
1204 + // Only query user if showing them
1205 + if ( ! empty( $settings['show_user'] ) ) :
1206 + $author_link = bbp_get_reply_author_link(
1207 + array(
1208 + 'post_id' => $reply_id,
1209 + 'type' => 'both',
1210 + 'size' => 14
1211 + )
1212 + );
1213 + else :
1214 + $author_link = false;
1215 + endif;
798 1216
799 - // Only the reply title
800 - else :
1217 + // Reply author, link, and timestamp
1218 + if ( ! empty( $settings['show_date'] ) && ! empty( $author_link ) ) :
801 1219
802 - // translators: 1: reply link
803 - printf( _x( '%1$s', 'widgets', 'bbpress' ), $reply_link );
1220 + // translators: 1: reply author, 2: reply link, 3: reply timestamp
1221 + printf( esc_html_x( '%1$s on %2$s %3$s', 'widgets', 'bbpress' ), $author_link, $reply_link, $show_date );
804 1222
805 - endif;
1223 + // Reply link and timestamp
1224 + elseif ( ! empty( $settings['show_date'] ) ) :
1225 + echo $reply_link . ' ' . $show_date;
806 1226
807 - ?>
1227 + // Reply author and title
1228 + elseif ( ! empty( $author_link ) ) :
808 1229
809 - </li>
1230 + // translators: 1: reply author, 2: reply link
1231 + printf( esc_html_x( '%1$s on %2$s', 'widgets', 'bbpress' ), $author_link, $reply_link );
810 1232
811 - <?php endwhile; ?>
1233 + // Only the reply title
1234 + else :
1235 + echo $reply_link;
1236 + endif;
812 1237
813 - </ul>
1238 + ?>
814 1239
815 - <?php echo $after_widget;
1240 + </li>
816 1241
817 - // Reset the $post global
818 - wp_reset_postdata();
1242 + <?php endwhile; ?>
819 1243
820 - endif;
1244 + </ul>
1245 +
1246 + <?php echo $args['after_widget'];
1247 +
1248 + // Reset the $post global
1249 + wp_reset_postdata();
1250 +
1251 + // Output the current buffer
1252 + echo ob_get_clean();
821 1253 }
822 1254
823 1255 /**
824 1256 * Update the reply widget options
825 1257 *
826 - * @since bbPress (r2653)
1258 + * @since 2.0.0 bbPress (r2653)
827 1259 *
828 1260 * @param array $new_instance The new instance options
829 1261 * @param array $old_instance The old instance options
830 1262 */
831 - public function update( $new_instance, $old_instance ) {
1263 + public function update( $new_instance = array(), $old_instance = array() ) {
832 1264 $instance = $old_instance;
833 - $instance['title'] = strip_tags( $new_instance['title'] );
834 - $instance['max_shown'] = strip_tags( $new_instance['max_shown'] );
835 - $instance['show_date'] = strip_tags( $new_instance['show_date'] );
836 - $instance['show_user'] = strip_tags( $new_instance['show_user'] );
1265 + $instance['title'] = strip_tags( $new_instance['title'] );
1266 + $instance['max_shown'] = (int) $new_instance['max_shown'];
837 1267
1268 + // Date
1269 + $instance['show_date'] = isset( $new_instance['show_date'] )
1270 + ? (bool) $new_instance['show_date']
1271 + : false;
1272 +
1273 + // Author
1274 + $instance['show_user'] = isset( $new_instance['show_user'] )
1275 + ? (bool) $new_instance['show_user']
1276 + : false;
1277 +
838 1278 return $instance;
839 1279 }
840 1280
841 1281 /**
@@ -840,24 +1280,41 @@
840 1280
841 1281 /**
842 1282 * Output the reply widget options form
843 1283 *
844 - * @since bbPress (r2653)
1284 + * @since 2.0.0 bbPress (r2653)
845 1285 *
846 1286 * @param $instance Instance
847 - * @uses BBP_Replies_Widget::get_field_id() To output the field id
848 - * @uses BBP_Replies_Widget::get_field_name() To output the field name
849 1287 */
850 - public function form( $instance ) {
851 - $title = !empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
852 - $max_shown = !empty( $instance['max_shown'] ) ? esc_attr( $instance['max_shown'] ) : '';
853 - $show_date = !empty( $instance['show_date'] ) ? esc_attr( $instance['show_date'] ) : '';
854 - $show_user = !empty( $instance['show_user'] ) ? esc_attr( $instance['show_user'] ) : ''; ?>
1288 + public function form( $instance = array() ) {
855 1289
856 - <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
857 - <p><label for="<?php echo $this->get_field_id( 'max_shown' ); ?>"><?php _e( 'Maximum replies to show:', 'bbpress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_shown' ); ?>" name="<?php echo $this->get_field_name( 'max_shown' ); ?>" type="text" value="<?php echo $max_shown; ?>" /></label></p>
858 - <p><label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Show post date:', 'bbpress' ); ?> <input type="checkbox" id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" <?php checked( 'on', $show_date ); ?> /></label></p>
859 - <p><label for="<?php echo $this->get_field_id( 'show_user' ); ?>"><?php _e( 'Show reply author:', 'bbpress' ); ?> <input type="checkbox" id="<?php echo $this->get_field_id( 'show_user' ); ?>" name="<?php echo $this->get_field_name( 'show_user' ); ?>" <?php checked( 'on', $show_user ); ?> /></label></p>
1290 + // Get widget settings
1291 + $settings = $this->parse_settings( $instance ); ?>
860 1292
1293 + <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'bbpress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $settings['title'] ); ?>" /></label></p>
1294 + <p><label for="<?php echo $this->get_field_id( 'max_shown' ); ?>"><?php esc_html_e( 'Maximum replies to show:', 'bbpress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_shown' ); ?>" name="<?php echo $this->get_field_name( 'max_shown' ); ?>" type="text" value="<?php echo esc_attr( $settings['max_shown'] ); ?>" /></label></p>
1295 + <p><label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php esc_html_e( 'Show post date:', 'bbpress' ); ?> <input type="checkbox" id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" <?php checked( true, $settings['show_date'] ); ?> value="1" /></label></p>
1296 + <p><label for="<?php echo $this->get_field_id( 'show_user' ); ?>"><?php esc_html_e( 'Show reply author:', 'bbpress' ); ?> <input type="checkbox" id="<?php echo $this->get_field_id( 'show_user' ); ?>" name="<?php echo $this->get_field_name( 'show_user' ); ?>" <?php checked( true, $settings['show_user'] ); ?> value="1" /></label></p>
1297 +
861 1298 <?php
1299 + }
1300 +
1301 + /**
1302 + * Merge the widget settings into defaults array.
1303 + *
1304 + * @since 2.3.0 bbPress (r4802)
1305 + *
1306 + * @param $instance Instance
1307 + */
1308 + public function parse_settings( $instance = array() ) {
1309 + return bbp_parse_args(
1310 + $instance,
1311 + array(
1312 + 'title' => esc_html__( 'Recent Replies', 'bbpress' ),
1313 + 'max_shown' => 5,
1314 + 'show_date' => false,
1315 + 'show_user' => false
1316 + ),
1317 + 'replies_widget_settings'
1318 + );
862 1319 }
863 1320 }