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