BBP_Login_Widget

BbPress Login Widget.

Defined (1)

The class is defined in the following location(s).

/includes/common/widgets.php  
  1. class BBP_Login_Widget extends WP_Widget { 
  2.  
  3. /** 
  4. * bbPress Login Widget 
  5. * Registers the login widget 
  6. * @since bbPress (r2827) 
  7. * @uses apply_filters() Calls 'bbp_login_widget_options' with the 
  8. * widget options 
  9. */ 
  10. public function __construct() { 
  11. $widget_ops = apply_filters( 'bbp_login_widget_options', array( 
  12. 'classname' => 'bbp_widget_login',  
  13. 'description' => __( 'A simple login form with optional links to sign-up and lost password pages.', 'bbpress' ) 
  14. ) ); 
  15.  
  16. parent::__construct( false, __( '(bbPress) Login Widget', 'bbpress' ), $widget_ops ); 
  17.  
  18. /** 
  19. * Register the widget 
  20. * @since bbPress (r3389) 
  21. * @uses register_widget() 
  22. */ 
  23. public static function register_widget() { 
  24. register_widget( 'BBP_Login_Widget' ); 
  25.  
  26. /** 
  27. * Displays the output, the login form 
  28. * @since bbPress (r2827) 
  29. * @param mixed $args Arguments 
  30. * @param array $instance Instance 
  31. * @uses apply_filters() Calls 'bbp_login_widget_title' with the title 
  32. * @uses get_template_part() To get the login/logged in form 
  33. */ 
  34. public function widget( $args = array(), $instance = array() ) { 
  35.  
  36. // Get widget settings 
  37. $settings = $this->parse_settings( $instance ); 
  38.  
  39. // Typical WordPress filter 
  40. $settings['title'] = apply_filters( 'widget_title', $settings['title'], $instance, $this->id_base ); 
  41.  
  42. // bbPress filters 
  43. $settings['title'] = apply_filters( 'bbp_login_widget_title', $settings['title'], $instance, $this->id_base ); 
  44. $settings['register'] = apply_filters( 'bbp_login_widget_register', $settings['register'], $instance, $this->id_base ); 
  45. $settings['lostpass'] = apply_filters( 'bbp_login_widget_lostpass', $settings['lostpass'], $instance, $this->id_base ); 
  46.  
  47. echo $args['before_widget']; 
  48.  
  49. if ( !empty( $settings['title'] ) ) { 
  50. echo $args['before_title'] . $settings['title'] . $args['after_title']; 
  51.  
  52. if ( !is_user_logged_in() ) : ?> 
  53.  
  54. <form method="post" action="<?php bbp_wp_login_action( array( 'context' => 'login_post' ) ); ?>" class="bbp-login-form"> 
  55. <fieldset> 
  56. <legend><?php _e( 'Log In', 'bbpress' ); ?></legend> 
  57.  
  58. <div class="bbp-username"> 
  59. <label for="user_login"><?php _e( 'Username', 'bbpress' ); ?>: </label> 
  60. <input type="text" name="log" value="<?php bbp_sanitize_val( 'user_login', 'text' ); ?>" size="20" id="user_login" tabindex="<?php bbp_tab_index(); ?>" /> 
  61. </div> 
  62.  
  63. <div class="bbp-password"> 
  64. <label for="user_pass"><?php _e( 'Password', 'bbpress' ); ?>: </label> 
  65. <input type="password" name="pwd" value="<?php bbp_sanitize_val( 'user_pass', 'password' ); ?>" size="20" id="user_pass" tabindex="<?php bbp_tab_index(); ?>" /> 
  66. </div> 
  67.  
  68. <div class="bbp-remember-me"> 
  69. <input type="checkbox" name="rememberme" value="forever" <?php checked( bbp_get_sanitize_val( 'rememberme', 'checkbox' ), true, true ); ?> id="rememberme" tabindex="<?php bbp_tab_index(); ?>" /> 
  70. <label for="rememberme"><?php _e( 'Remember Me', 'bbpress' ); ?></label> 
  71. </div> 
  72.  
  73. <div class="bbp-submit-wrapper"> 
  74.  
  75. <?php do_action( 'login_form' ); ?> 
  76.  
  77. <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> 
  78.  
  79. <?php bbp_user_login_fields(); ?> 
  80.  
  81. </div> 
  82.  
  83. <?php if ( !empty( $settings['register'] ) || !empty( $settings['lostpass'] ) ) : ?> 
  84.  
  85. <div class="bbp-login-links"> 
  86.  
  87. <?php if ( !empty( $settings['register'] ) ) : ?> 
  88.  
  89. <a href="<?php echo esc_url( $settings['register'] ); ?>" title="<?php esc_attr_e( 'Register', 'bbpress' ); ?>" class="bbp-register-link"><?php _e( 'Register', 'bbpress' ); ?></a> 
  90.  
  91. <?php endif; ?> 
  92.  
  93. <?php if ( !empty( $settings['lostpass'] ) ) : ?> 
  94.  
  95. <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> 
  96.  
  97. <?php endif; ?> 
  98.  
  99. </div> 
  100.  
  101. <?php endif; ?> 
  102.  
  103. </fieldset> 
  104. </form> 
  105.  
  106. <?php else : ?> 
  107.  
  108. <div class="bbp-logged-in"> 
  109. <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> 
  110. <h4><?php bbp_user_profile_link( bbp_get_current_user_id() ); ?></h4> 
  111.  
  112. <?php bbp_logout_link(); ?> 
  113. </div> 
  114.  
  115. <?php endif; 
  116.  
  117. echo $args['after_widget']; 
  118.  
  119. /** 
  120. * Update the login widget options 
  121. * @since bbPress (r2827) 
  122. * @param array $new_instance The new instance options 
  123. * @param array $old_instance The old instance options 
  124. */ 
  125. public function update( $new_instance, $old_instance ) { 
  126. $instance = $old_instance; 
  127. $instance['title'] = strip_tags( $new_instance['title'] ); 
  128. $instance['register'] = esc_url_raw( $new_instance['register'] ); 
  129. $instance['lostpass'] = esc_url_raw( $new_instance['lostpass'] ); 
  130.  
  131. return $instance; 
  132.  
  133. /** 
  134. * Output the login widget options form 
  135. * @since bbPress (r2827) 
  136. * @param $instance Instance 
  137. * @uses BBP_Login_Widget::get_field_id() To output the field id 
  138. * @uses BBP_Login_Widget::get_field_name() To output the field name 
  139. */ 
  140. public function form( $instance = array() ) { 
  141.  
  142. // Get widget settings 
  143. $settings = $this->parse_settings( $instance ); ?> 
  144.  
  145. <p> 
  146. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'bbpress' ); ?> 
  147. <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> 
  148. </p> 
  149.  
  150. <p> 
  151. <label for="<?php echo $this->get_field_id( 'register' ); ?>"><?php _e( 'Register URI:', 'bbpress' ); ?> 
  152. <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> 
  153. </p> 
  154.  
  155. <p> 
  156. <label for="<?php echo $this->get_field_id( 'lostpass' ); ?>"><?php _e( 'Lost Password URI:', 'bbpress' ); ?> 
  157. <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> 
  158. </p> 
  159.  
  160. <?php 
  161.  
  162. /** 
  163. * Merge the widget settings into defaults array. 
  164. * @since bbPress (r4802) 
  165. * @param $instance Instance 
  166. * @uses bbp_parse_args() To merge widget settings into defaults 
  167. */ 
  168. public function parse_settings( $instance = array() ) { 
  169. return bbp_parse_args( $instance, array( 
  170. 'title' => '',  
  171. 'register' => '',  
  172. 'lostpass' => '' 
  173. ), 'login_widget_settings' );