/includes/common/widgets.php

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