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