| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* bbPress Widgets. |
| 5 |
* |
| 6 |
* Contains the forum list, topic list, reply list and login form widgets. |
| 7 |
* |
| 8 |
* @package bbPress |
| 9 |
* @subpackage Widgets |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if accessed directly |
| 13 |
defined( 'ABSPATH' ) || exit; |
| 14 |
|
| 15 |
/** |
| 16 |
* bbPress Login Widget. |
| 17 |
* |
| 18 |
* Adds a widget which displays the login form. |
| 19 |
* |
| 20 |
* @since 2.0.0 bbPress (r2827) |
| 21 |
*/ |
| 22 |
class BBP_Login_Widget extends WP_Widget { |
| 23 |
|
| 24 |
/** |
| 25 |
* bbPress Login Widget. |
| 26 |
* |
| 27 |
* Registers the login widget. |
| 28 |
* |
| 29 |
* @since 2.0.0 bbPress (r2827) |
| 30 |
*/ |
| 31 |
public function __construct() { |
| 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 |
); |
| 40 |
|
| 41 |
parent::__construct( false, esc_html__( '(bbPress) Login Widget', 'bbpress' ), $widget_ops ); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Register the widget. |
| 46 |
* |
| 47 |
* @since 2.0.0 bbPress (r3389) |
| 48 |
*/ |
| 49 |
public static function register_widget() { |
| 50 |
register_widget( 'BBP_Login_Widget' ); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Displays the output, the login form. |
| 55 |
* |
| 56 |
* @since 2.0.0 bbPress (r2827) |
| 57 |
* |
| 58 |
* @param array $args Arguments. |
| 59 |
* @param array $instance Instance. |
| 60 |
*/ |
| 61 |
public function widget( $args = array(), $instance = array() ) { |
| 62 |
|
| 63 |
// Get widget settings |
| 64 |
$settings = $this->parse_settings( $instance ); |
| 65 |
|
| 66 |
// Typical WordPress filter |
| 67 |
$settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base ); |
| 68 |
|
| 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 ); |
| 73 |
|
| 74 |
echo $args['before_widget']; |
| 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 |
|
| 82 |
<form method="post" action="<?php bbp_wp_login_action( array( 'context' => 'login_post' ) ); ?>" class="bbp-login-form"> |
| 83 |
<fieldset class="bbp-form"> |
| 84 |
<legend><?php esc_html_e( 'Log In', 'bbpress' ); ?></legend> |
| 85 |
|
| 86 |
<div class="bbp-username"> |
| 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" /> |
| 89 |
</div> |
| 90 |
|
| 91 |
<div class="bbp-password"> |
| 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" /> |
| 94 |
</div> |
| 95 |
|
| 96 |
<div class="bbp-remember-me"> |
| 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> |
| 99 |
</div> |
| 100 |
|
| 101 |
<?php do_action( 'login_form' ); ?> |
| 102 |
|
| 103 |
<div class="bbp-submit-wrapper"> |
| 104 |
|
| 105 |
<button type="submit" name="user-submit" id="user-submit" class="button submit user-submit"><?php esc_html_e( 'Log In', 'bbpress' ); ?></button> |
| 106 |
|
| 107 |
<?php bbp_user_login_fields(); ?> |
| 108 |
|
| 109 |
</div> |
| 110 |
|
| 111 |
<?php if ( ! empty( $settings['register'] ) || ! empty( $settings['lostpass'] ) ) : ?> |
| 112 |
|
| 113 |
<div class="bbp-login-links"> |
| 114 |
|
| 115 |
<?php if ( ! empty( $settings['register'] ) ) : ?> |
| 116 |
|
| 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> |
| 118 |
|
| 119 |
<?php endif; ?> |
| 120 |
|
| 121 |
<?php if ( ! empty( $settings['lostpass'] ) ) : ?> |
| 122 |
|
| 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> |
| 124 |
|
| 125 |
<?php endif; ?> |
| 126 |
|
| 127 |
</div> |
| 128 |
|
| 129 |
<?php endif; ?> |
| 130 |
|
| 131 |
</fieldset> |
| 132 |
</form> |
| 133 |
|
| 134 |
<?php else : ?> |
| 135 |
|
| 136 |
<div class="bbp-logged-in"> |
| 137 |
<a href="<?php bbp_user_profile_url( bbp_get_current_user_id() ); ?>" class="submit user-submit"><?php echo get_avatar( bbp_get_current_user_id(), '40' ); ?></a> |
| 138 |
<h4><?php bbp_user_profile_link( bbp_get_current_user_id() ); ?></h4> |
| 139 |
|
| 140 |
<?php bbp_logout_link(); ?> |
| 141 |
</div> |
| 142 |
|
| 143 |
<?php endif; |
| 144 |
|
| 145 |
echo $args['after_widget']; |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* Update the login widget options. |
| 150 |
* |
| 151 |
* @since 2.0.0 bbPress (r2827) |
| 152 |
* |
| 153 |
* @param array $new_instance The new instance options. |
| 154 |
* @param array $old_instance The old instance options. |
| 155 |
*/ |
| 156 |
public function update( $new_instance, $old_instance ) { |
| 157 |
$instance = $old_instance; |
| 158 |
$instance['title'] = wp_strip_all_tags( $new_instance['title'] ); |
| 159 |
$instance['register'] = esc_url_raw( $new_instance['register'] ); |
| 160 |
$instance['lostpass'] = esc_url_raw( $new_instance['lostpass'] ); |
| 161 |
|
| 162 |
return $instance; |
| 163 |
} |
| 164 |
|
| 165 |
/** |
| 166 |
* Output the login widget options form. |
| 167 |
* |
| 168 |
* @since 2.0.0 bbPress (r2827) |
| 169 |
* |
| 170 |
* @param $instance Instance. |
| 171 |
*/ |
| 172 |
public function form( $instance = array() ) { |
| 173 |
|
| 174 |
// Get widget settings |
| 175 |
$settings = $this->parse_settings( $instance ); ?> |
| 176 |
|
| 177 |
<p> |
| 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> |
| 180 |
</p> |
| 181 |
|
| 182 |
<p> |
| 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> |
| 185 |
</p> |
| 186 |
|
| 187 |
<p> |
| 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> |
| 190 |
</p> |
| 191 |
|
| 192 |
<?php |
| 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 |
} |
| 213 |
} |
| 214 |
|
| 215 |
/** |
| 216 |
* bbPress Views Widget. |
| 217 |
* |
| 218 |
* Adds a widget which displays the view list. |
| 219 |
* |
| 220 |
* @since 2.0.0 bbPress (r3020) |
| 221 |
*/ |
| 222 |
class BBP_Views_Widget extends WP_Widget { |
| 223 |
|
| 224 |
/** |
| 225 |
* bbPress View Widget. |
| 226 |
* |
| 227 |
* Registers the view widget. |
| 228 |
* |
| 229 |
* @since 2.0.0 bbPress (r3020) |
| 230 |
*/ |
| 231 |
public function __construct() { |
| 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 |
); |
| 240 |
|
| 241 |
parent::__construct( false, esc_html__( '(bbPress) Topic Views List', 'bbpress' ), $widget_ops ); |
| 242 |
} |
| 243 |
|
| 244 |
/** |
| 245 |
* Register the widget. |
| 246 |
* |
| 247 |
* @since 2.0.0 bbPress (r3389) |
| 248 |
*/ |
| 249 |
public static function register_widget() { |
| 250 |
register_widget( 'BBP_Views_Widget' ); |
| 251 |
} |
| 252 |
|
| 253 |
/** |
| 254 |
* Displays the output, the view list. |
| 255 |
* |
| 256 |
* @since 2.0.0 bbPress (r3020) |
| 257 |
* |
| 258 |
* @param array $args Arguments. |
| 259 |
* @param array $instance Instance. |
| 260 |
*/ |
| 261 |
public function widget( $args = array(), $instance = array() ) { |
| 262 |
|
| 263 |
// Only output widget contents if views exist |
| 264 |
if ( ! bbp_get_views() ) { |
| 265 |
return; |
| 266 |
} |
| 267 |
|
| 268 |
// Get widget settings |
| 269 |
$settings = $this->parse_settings( $instance ); |
| 270 |
|
| 271 |
// Typical WordPress filter |
| 272 |
$settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base ); |
| 273 |
|
| 274 |
// bbPress filter |
| 275 |
$settings['title'] = apply_filters( 'bbp_view_widget_title', $settings['title'], $instance, $this->id_base ); |
| 276 |
|
| 277 |
// Start an output buffer |
| 278 |
ob_start(); |
| 279 |
|
| 280 |
echo $args['before_widget']; |
| 281 |
|
| 282 |
if ( ! empty( $settings['title'] ) ) { |
| 283 |
echo $args['before_title'] . $settings['title'] . $args['after_title']; |
| 284 |
} ?> |
| 285 |
|
| 286 |
<ul class="bbp-views-widget"> |
| 287 |
|
| 288 |
<?php foreach ( array_keys( bbp_get_views() ) as $view ) : ?> |
| 289 |
|
| 290 |
<li><a class="bbp-view-title" href="<?php bbp_view_url( $view ); ?>"><?php bbp_view_title( $view ); ?></a></li> |
| 291 |
|
| 292 |
<?php endforeach; ?> |
| 293 |
|
| 294 |
</ul> |
| 295 |
|
| 296 |
<?php echo $args['after_widget']; |
| 297 |
|
| 298 |
// Output the current buffer |
| 299 |
echo ob_get_clean(); |
| 300 |
} |
| 301 |
|
| 302 |
/** |
| 303 |
* Update the view widget options. |
| 304 |
* |
| 305 |
* @since 2.0.0 bbPress (r3020) |
| 306 |
* |
| 307 |
* @param array $new_instance The new instance options. |
| 308 |
* @param array $old_instance The old instance options. |
| 309 |
*/ |
| 310 |
public function update( $new_instance = array(), $old_instance = array() ) { |
| 311 |
$instance = $old_instance; |
| 312 |
$instance['title'] = wp_strip_all_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 |
*/ |
| 434 |
public function update( $new_instance, $old_instance ) { |
| 435 |
$instance = $old_instance; |
| 436 |
$instance['title'] = wp_strip_all_tags( $new_instance['title'] ); |
| 437 |
|
| 438 |
return $instance; |
| 439 |
} |
| 440 |
|
| 441 |
/** |
| 442 |
* Output the search widget options form. |
| 443 |
* |
| 444 |
* @since 2.3.0 bbPress (r4579) |
| 445 |
* |
| 446 |
* @param $instance Instance. |
| 447 |
*/ |
| 448 |
public function form( $instance ) { |
| 449 |
|
| 450 |
// Get widget settings |
| 451 |
$settings = $this->parse_settings( $instance ); ?> |
| 452 |
|
| 453 |
<p> |
| 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'] ); ?>" /> |
| 456 |
</label> |
| 457 |
</p> |
| 458 |
|
| 459 |
<?php |
| 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 |
} |
| 478 |
} |
| 479 |
|
| 480 |
/** |
| 481 |
* bbPress Forum Widget. |
| 482 |
* |
| 483 |
* Adds a widget which displays the forum list. |
| 484 |
* |
| 485 |
* @since 2.0.0 bbPress (r2653) |
| 486 |
*/ |
| 487 |
class BBP_Forums_Widget extends WP_Widget { |
| 488 |
|
| 489 |
/** |
| 490 |
* bbPress Forum Widget. |
| 491 |
* |
| 492 |
* Registers the forum widget. |
| 493 |
* |
| 494 |
* @since 2.0.0 bbPress (r2653) |
| 495 |
*/ |
| 496 |
public function __construct() { |
| 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 |
); |
| 505 |
|
| 506 |
parent::__construct( false, esc_html__( '(bbPress) Forums List', 'bbpress' ), $widget_ops ); |
| 507 |
} |
| 508 |
|
| 509 |
/** |
| 510 |
* Register the widget. |
| 511 |
* |
| 512 |
* @since 2.0.0 bbPress (r3389) |
| 513 |
*/ |
| 514 |
public static function register_widget() { |
| 515 |
register_widget( 'BBP_Forums_Widget' ); |
| 516 |
} |
| 517 |
|
| 518 |
/** |
| 519 |
* Displays the output, the forum list. |
| 520 |
* |
| 521 |
* @since 2.0.0 bbPress (r2653) |
| 522 |
* |
| 523 |
* @param array $args Arguments. |
| 524 |
* @param array $instance Instance. |
| 525 |
*/ |
| 526 |
public function widget( $args, $instance ) { |
| 527 |
|
| 528 |
// Get widget settings |
| 529 |
$settings = $this->parse_settings( $instance ); |
| 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 |
|
| 537 |
// Note: private and hidden forums will be excluded via the |
| 538 |
// bbp_pre_get_posts_normalize_forum_visibility action and function. |
| 539 |
$widget_query = new WP_Query( |
| 540 |
array( |
| 541 |
|
| 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 ), |
| 547 |
|
| 548 |
// Order |
| 549 |
'orderby' => 'menu_order title', |
| 550 |
'order' => 'ASC', |
| 551 |
|
| 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 |
); |
| 559 |
|
| 560 |
// Bail if no posts |
| 561 |
if ( ! $widget_query->have_posts() ) { |
| 562 |
return; |
| 563 |
} |
| 564 |
|
| 565 |
echo $args['before_widget']; |
| 566 |
|
| 567 |
if ( ! empty( $settings['title'] ) ) { |
| 568 |
echo $args['before_title'] . $settings['title'] . $args['after_title']; |
| 569 |
} ?> |
| 570 |
|
| 571 |
<ul class="bbp-forums-widget"> |
| 572 |
|
| 573 |
<?php while ( $widget_query->have_posts() ) : |
| 574 |
|
| 575 |
$widget_query->the_post(); ?> |
| 576 |
|
| 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(); |
| 591 |
} |
| 592 |
|
| 593 |
/** |
| 594 |
* Update the forum widget options. |
| 595 |
* |
| 596 |
* @since 2.0.0 bbPress (r2653) |
| 597 |
* |
| 598 |
* @param array $new_instance The new instance options. |
| 599 |
* @param array $old_instance The old instance options. |
| 600 |
*/ |
| 601 |
public function update( $new_instance, $old_instance ) { |
| 602 |
$instance = $old_instance; |
| 603 |
$instance['title'] = wp_strip_all_tags( $new_instance['title'] ); |
| 604 |
$instance['parent_forum'] = sanitize_text_field( $new_instance['parent_forum'] ); |
| 605 |
|
| 606 |
// Force to any |
| 607 |
if ( ! empty( $instance['parent_forum'] ) && ! is_numeric( $instance['parent_forum'] ) ) { |
| 608 |
$instance['parent_forum'] = 'any'; |
| 609 |
} |
| 610 |
|
| 611 |
return $instance; |
| 612 |
} |
| 613 |
|
| 614 |
/** |
| 615 |
* Output the forum widget options form. |
| 616 |
* |
| 617 |
* @since 2.0.0 bbPress (r2653) |
| 618 |
* |
| 619 |
* @param $instance Instance. |
| 620 |
*/ |
| 621 |
public function form( $instance ) { |
| 622 |
|
| 623 |
// Get widget settings |
| 624 |
$settings = $this->parse_settings( $instance ); ?> |
| 625 |
|
| 626 |
<p> |
| 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'] ); ?>" /> |
| 629 |
</label> |
| 630 |
</p> |
| 631 |
|
| 632 |
<p> |
| 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'] ); ?>" /> |
| 635 |
</label> |
| 636 |
|
| 637 |
<br /> |
| 638 |
|
| 639 |
<small><?php esc_html_e( '"0" to show only root - "any" to show all', 'bbpress' ); ?></small> |
| 640 |
</p> |
| 641 |
|
| 642 |
<?php |
| 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 |
} |
| 662 |
} |
| 663 |
|
| 664 |
/** |
| 665 |
* bbPress Topic Widget. |
| 666 |
* |
| 667 |
* Adds a widget which displays the topic list. |
| 668 |
* |
| 669 |
* @since 2.0.0 bbPress (r2653) |
| 670 |
*/ |
| 671 |
class BBP_Topics_Widget extends WP_Widget { |
| 672 |
|
| 673 |
/** |
| 674 |
* bbPress Topic Widget. |
| 675 |
* |
| 676 |
* Registers the topic widget. |
| 677 |
* |
| 678 |
* @since 2.0.0 bbPress (r2653) |
| 679 |
*/ |
| 680 |
public function __construct() { |
| 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 |
); |
| 689 |
|
| 690 |
parent::__construct( false, esc_html__( '(bbPress) Recent Topics', 'bbpress' ), $widget_ops ); |
| 691 |
} |
| 692 |
|
| 693 |
/** |
| 694 |
* Register the widget. |
| 695 |
* |
| 696 |
* @since 2.0.0 bbPress (r3389) |
| 697 |
*/ |
| 698 |
public static function register_widget() { |
| 699 |
register_widget( 'BBP_Topics_Widget' ); |
| 700 |
} |
| 701 |
|
| 702 |
/** |
| 703 |
* Displays the output, the topic list. |
| 704 |
* |
| 705 |
* @since 2.0.0 bbPress (r2653) |
| 706 |
* |
| 707 |
* @param array $args |
| 708 |
* @param array $instance |
| 709 |
*/ |
| 710 |
public function widget( $args = array(), $instance = array() ) { |
| 711 |
|
| 712 |
// Get widget settings |
| 713 |
$settings = $this->parse_settings( $instance ); |
| 714 |
|
| 715 |
// Typical WordPress filter |
| 716 |
$settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base ); |
| 717 |
|
| 718 |
// bbPress filter |
| 719 |
$settings['title'] = apply_filters( 'bbp_topic_widget_title', $settings['title'], $instance, $this->id_base ); |
| 720 |
|
| 721 |
// How do we want to order our results? |
| 722 |
switch ( $settings['order_by'] ) { |
| 723 |
|
| 724 |
// Order by most recent replies |
| 725 |
case 'freshness' : |
| 726 |
$topics_query = array( |
| 727 |
|
| 728 |
// What and how |
| 729 |
'post_type' => bbp_get_topic_post_type(), |
| 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 |
| 749 |
); |
| 750 |
break; |
| 751 |
|
| 752 |
// Order by total number of replies |
| 753 |
case 'popular' : |
| 754 |
$topics_query = array( |
| 755 |
|
| 756 |
// What and how |
| 757 |
'post_type' => bbp_get_topic_post_type(), |
| 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 |
); |
| 778 |
break; |
| 779 |
|
| 780 |
// Order by which topic was created most recently |
| 781 |
case 'newness' : |
| 782 |
default : |
| 783 |
$topics_query = array( |
| 784 |
|
| 785 |
// What and how |
| 786 |
'post_type' => bbp_get_topic_post_type(), |
| 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 |
); |
| 801 |
break; |
| 802 |
} |
| 803 |
|
| 804 |
// Note: private and hidden forums will be excluded via the |
| 805 |
// bbp_pre_get_posts_normalize_forum_visibility action and function. |
| 806 |
$widget_query = new WP_Query( $topics_query ); |
| 807 |
|
| 808 |
// Bail if no topics are found |
| 809 |
if ( ! $widget_query->have_posts() ) { |
| 810 |
return; |
| 811 |
} |
| 812 |
|
| 813 |
// Start an output buffer |
| 814 |
ob_start(); |
| 815 |
|
| 816 |
echo $args['before_widget']; |
| 817 |
|
| 818 |
if ( ! empty( $settings['title'] ) ) { |
| 819 |
echo $args['before_title'] . $settings['title'] . $args['after_title']; |
| 820 |
} ?> |
| 821 |
|
| 822 |
<ul class="bbp-topics-widget <?php echo esc_attr( $settings['order_by'] ); ?>"> |
| 823 |
|
| 824 |
<?php while ( $widget_query->have_posts() ) : |
| 825 |
|
| 826 |
$widget_query->the_post(); |
| 827 |
$topic_id = bbp_get_topic_id( $widget_query->post->ID ); |
| 828 |
$author_link = ''; |
| 829 |
|
| 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; ?> |
| 840 |
|
| 841 |
<li> |
| 842 |
<a class="bbp-forum-title" href="<?php bbp_topic_permalink( $topic_id ); ?>"><?php bbp_topic_title( $topic_id ); ?></a> |
| 843 |
|
| 844 |
<?php if ( ! empty( $author_link ) ) : ?> |
| 845 |
|
| 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 |
?> |
| 853 |
|
| 854 |
<?php endif; ?> |
| 855 |
|
| 856 |
<?php if ( ! empty( $settings['show_date'] ) ) : ?> |
| 857 |
|
| 858 |
<div><?php bbp_topic_last_active_time( $topic_id ); ?></div> |
| 859 |
|
| 860 |
<?php endif; ?> |
| 861 |
|
| 862 |
</li> |
| 863 |
|
| 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(); |
| 875 |
} |
| 876 |
|
| 877 |
/** |
| 878 |
* Update the topic widget options. |
| 879 |
* |
| 880 |
* @since 2.0.0 bbPress (r2653) |
| 881 |
* |
| 882 |
* @param array $new_instance The new instance options. |
| 883 |
* @param array $old_instance The old instance options. |
| 884 |
*/ |
| 885 |
public function update( $new_instance = array(), $old_instance = array() ) { |
| 886 |
$instance = $old_instance; |
| 887 |
$instance['title'] = wp_strip_all_tags( $new_instance['title'] ); |
| 888 |
$instance['order_by'] = wp_strip_all_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']; |
| 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 |
|
| 907 |
return $instance; |
| 908 |
} |
| 909 |
|
| 910 |
/** |
| 911 |
* Output the topic widget options form. |
| 912 |
* |
| 913 |
* @since 2.0.0 bbPress (r2653) |
| 914 |
* |
| 915 |
* @param $instance Instance. |
| 916 |
*/ |
| 917 |
public function form( $instance = array() ) { |
| 918 |
|
| 919 |
// Get widget settings |
| 920 |
$settings = $this->parse_settings( $instance ); ?> |
| 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 |
|
| 925 |
<p> |
| 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> |
| 944 |
</select> |
| 945 |
</p> |
| 946 |
|
| 947 |
<?php |
| 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 |
} |
| 971 |
} |
| 972 |
|
| 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'] = wp_strip_all_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 |
/** |
| 1100 |
* bbPress Replies Widget. |
| 1101 |
* |
| 1102 |
* Adds a widget which displays the replies list. |
| 1103 |
* |
| 1104 |
* @since 2.0.0 bbPress (r2653) |
| 1105 |
*/ |
| 1106 |
class BBP_Replies_Widget extends WP_Widget { |
| 1107 |
|
| 1108 |
/** |
| 1109 |
* bbPress Replies Widget. |
| 1110 |
* |
| 1111 |
* Registers the replies widget. |
| 1112 |
* |
| 1113 |
* @since 2.0.0 bbPress (r2653) |
| 1114 |
*/ |
| 1115 |
public function __construct() { |
| 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 |
); |
| 1124 |
|
| 1125 |
parent::__construct( false, esc_html__( '(bbPress) Recent Replies', 'bbpress' ), $widget_ops ); |
| 1126 |
} |
| 1127 |
|
| 1128 |
/** |
| 1129 |
* Register the widget. |
| 1130 |
* |
| 1131 |
* @since 2.0.0 bbPress (r3389) |
| 1132 |
*/ |
| 1133 |
public static function register_widget() { |
| 1134 |
register_widget( 'BBP_Replies_Widget' ); |
| 1135 |
} |
| 1136 |
|
| 1137 |
/** |
| 1138 |
* Displays the output, the replies list. |
| 1139 |
* |
| 1140 |
* @since 2.0.0 bbPress (r2653) |
| 1141 |
* |
| 1142 |
* @param array $args |
| 1143 |
* @param array $instance |
| 1144 |
*/ |
| 1145 |
public function widget( $args, $instance ) { |
| 1146 |
|
| 1147 |
// Get widget settings |
| 1148 |
$settings = $this->parse_settings( $instance ); |
| 1149 |
|
| 1150 |
// Typical WordPress filter |
| 1151 |
$settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base ); |
| 1152 |
|
| 1153 |
// bbPress filter |
| 1154 |
$settings['title'] = apply_filters( 'bbp_replies_widget_title', $settings['title'], $instance, $this->id_base ); |
| 1155 |
|
| 1156 |
// Note: private and hidden forums will be excluded via the |
| 1157 |
// bbp_pre_get_posts_normalize_forum_visibility action and function. |
| 1158 |
$widget_query = new WP_Query( |
| 1159 |
array( |
| 1160 |
|
| 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'], |
| 1165 |
|
| 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 |
); |
| 1173 |
|
| 1174 |
// Bail if no replies |
| 1175 |
if ( ! $widget_query->have_posts() ) { |
| 1176 |
return; |
| 1177 |
} |
| 1178 |
|
| 1179 |
// Start an output buffer |
| 1180 |
ob_start(); |
| 1181 |
|
| 1182 |
echo $args['before_widget']; |
| 1183 |
|
| 1184 |
if ( ! empty( $settings['title'] ) ) { |
| 1185 |
echo $args['before_title'] . $settings['title'] . $args['after_title']; |
| 1186 |
} ?> |
| 1187 |
|
| 1188 |
<ul class="bbp-replies-widget"> |
| 1189 |
|
| 1190 |
<?php while ( $widget_query->have_posts() ) : |
| 1191 |
|
| 1192 |
$widget_query->the_post(); ?> |
| 1193 |
|
| 1194 |
<li> |
| 1195 |
|
| 1196 |
<?php |
| 1197 |
|
| 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>'; |
| 1203 |
|
| 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; |
| 1216 |
|
| 1217 |
// Reply author, link, and timestamp |
| 1218 |
if ( ! empty( $settings['show_date'] ) && ! empty( $author_link ) ) : |
| 1219 |
|
| 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 ); |
| 1222 |
|
| 1223 |
// Reply link and timestamp |
| 1224 |
elseif ( ! empty( $settings['show_date'] ) ) : |
| 1225 |
echo $reply_link . ' ' . $show_date; |
| 1226 |
|
| 1227 |
// Reply author and title |
| 1228 |
elseif ( ! empty( $author_link ) ) : |
| 1229 |
|
| 1230 |
/* translators: 1: reply author, 2: reply link */ |
| 1231 |
printf( esc_html_x( '%1$s on %2$s', 'widgets', 'bbpress' ), $author_link, $reply_link ); |
| 1232 |
|
| 1233 |
// Only the reply title |
| 1234 |
else : |
| 1235 |
echo $reply_link; |
| 1236 |
endif; |
| 1237 |
|
| 1238 |
?> |
| 1239 |
|
| 1240 |
</li> |
| 1241 |
|
| 1242 |
<?php endwhile; ?> |
| 1243 |
|
| 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(); |
| 1253 |
} |
| 1254 |
|
| 1255 |
/** |
| 1256 |
* Update the reply widget options. |
| 1257 |
* |
| 1258 |
* @since 2.0.0 bbPress (r2653) |
| 1259 |
* |
| 1260 |
* @param array $new_instance The new instance options. |
| 1261 |
* @param array $old_instance The old instance options. |
| 1262 |
*/ |
| 1263 |
public function update( $new_instance = array(), $old_instance = array() ) { |
| 1264 |
$instance = $old_instance; |
| 1265 |
$instance['title'] = wp_strip_all_tags( $new_instance['title'] ); |
| 1266 |
$instance['max_shown'] = (int) $new_instance['max_shown']; |
| 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 |
|
| 1278 |
return $instance; |
| 1279 |
} |
| 1280 |
|
| 1281 |
/** |
| 1282 |
* Output the reply widget options form. |
| 1283 |
* |
| 1284 |
* @since 2.0.0 bbPress (r2653) |
| 1285 |
* |
| 1286 |
* @param $instance Instance. |
| 1287 |
*/ |
| 1288 |
public function form( $instance = array() ) { |
| 1289 |
|
| 1290 |
// Get widget settings |
| 1291 |
$settings = $this->parse_settings( $instance ); ?> |
| 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 |
|
| 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 |
); |
| 1319 |
} |
| 1320 |
} |
| 1321 |
|