BP_Core_Login_Widget

BuddyPress Login Widget.

Defined (1)

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

/bp-core/classes/class-bp-core-login-widget.php  
  1. class BP_Core_Login_Widget extends WP_Widget { 
  2.  
  3. /** 
  4. * Constructor method. 
  5. * @since 1.9.0 
  6. */ 
  7. public function __construct() { 
  8. parent::__construct( 
  9. false,  
  10. _x( '(BuddyPress) Log In', 'Title of the login widget', 'buddypress' ),  
  11. array( 
  12. 'description' => __( 'Show a Log In form to logged-out visitors, and a Log Out link to those who are logged in.', 'buddypress' ),  
  13. 'classname' => 'widget_bp_core_login_widget buddypress widget',  
  14. 'customize_selective_refresh' => true,  
  15. ); 
  16.  
  17. /** 
  18. * Display the login widget. 
  19. * @since 1.9.0 
  20. * @see WP_Widget::widget() for description of parameters. 
  21. * @param array $args Widget arguments. 
  22. * @param array $instance Widget settings, as saved by the user. 
  23. */ 
  24. public function widget( $args, $instance ) { 
  25. $title = isset( $instance['title'] ) ? $instance['title'] : ''; 
  26.  
  27. /** 
  28. * Filters the title of the Login widget. 
  29. * @since 1.9.0 
  30. * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter. 
  31. * @param string $title The widget title. 
  32. * @param array $instance The settings for the particular instance of the widget. 
  33. * @param string $id_base Root ID for all widgets of this type. 
  34. */ 
  35. $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 
  36.  
  37. echo $args['before_widget']; 
  38.  
  39. echo $args['before_title'] . esc_html( $title ) . $args['after_title']; ?> 
  40.  
  41. <?php if ( is_user_logged_in() ) : ?> 
  42.  
  43. <?php 
  44. /** 
  45. * Fires before the display of widget content if logged in. 
  46. * @since 1.9.0 
  47. */ 
  48. do_action( 'bp_before_login_widget_loggedin' ); ?> 
  49.  
  50. <div class="bp-login-widget-user-avatar"> 
  51. <a href="<?php echo bp_loggedin_user_domain(); ?>"> 
  52. <?php bp_loggedin_user_avatar( 'type=thumb&width=50&height=50' ); ?> 
  53. </a> 
  54. </div> 
  55.  
  56. <div class="bp-login-widget-user-links"> 
  57. <div class="bp-login-widget-user-link"><?php echo bp_core_get_userlink( bp_loggedin_user_id() ); ?></div> 
  58. <div class="bp-login-widget-user-logout"><a class="logout" href="<?php echo wp_logout_url( bp_get_requested_url() ); ?>"><?php _e( 'Log Out', 'buddypress' ); ?></a></div> 
  59. </div> 
  60.  
  61. <?php 
  62.  
  63. /** 
  64. * Fires after the display of widget content if logged in. 
  65. * @since 1.9.0 
  66. */ 
  67. do_action( 'bp_after_login_widget_loggedin' ); ?> 
  68.  
  69. <?php else : ?> 
  70.  
  71. <?php 
  72.  
  73. /** 
  74. * Fires before the display of widget content if logged out. 
  75. * @since 1.9.0 
  76. */ 
  77. do_action( 'bp_before_login_widget_loggedout' ); ?> 
  78.  
  79. <form name="bp-login-form" id="bp-login-widget-form" class="standard-form" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post"> 
  80. <label for="bp-login-widget-user-login"><?php _e( 'Username', 'buddypress' ); ?></label> 
  81. <input type="text" name="log" id="bp-login-widget-user-login" class="input" value="" /> 
  82.  
  83. <label for="bp-login-widget-user-pass"><?php _e( 'Password', 'buddypress' ); ?></label> 
  84. <input type="password" name="pwd" id="bp-login-widget-user-pass" class="input" value="" <?php bp_form_field_attributes( 'password' ) ?> /> 
  85.  
  86. <div class="forgetmenot"><label for="bp-login-widget-rememberme"><input name="rememberme" type="checkbox" id="bp-login-widget-rememberme" value="forever" /> <?php _e( 'Remember Me', 'buddypress' ); ?></label></div> 
  87.  
  88. <input type="submit" name="wp-submit" id="bp-login-widget-submit" value="<?php esc_attr_e( 'Log In', 'buddypress' ); ?>" /> 
  89.  
  90. <?php if ( bp_get_signup_allowed() ) : ?> 
  91.  
  92. <span class="bp-login-widget-register-link"><a href="<?php echo esc_url( bp_get_signup_page() ); ?>"><?php _e( 'Register', 'buddypress' ); ?></a></span> 
  93.  
  94. <?php endif; ?> 
  95.  
  96. <?php 
  97.  
  98. /** 
  99. * Fires inside the display of the login widget form. 
  100. * @since 2.4.0 
  101. */ 
  102. do_action( 'bp_login_widget_form' ); ?> 
  103.  
  104. </form> 
  105.  
  106. <?php 
  107.  
  108. /** 
  109. * Fires after the display of widget content if logged out. 
  110. * @since 1.9.0 
  111. */ 
  112. do_action( 'bp_after_login_widget_loggedout' ); ?> 
  113.  
  114. <?php endif; 
  115.  
  116. echo $args['after_widget']; 
  117.  
  118. /** 
  119. * Update the login widget options. 
  120. * @since 1.9.0 
  121. * @param array $new_instance The new instance options. 
  122. * @param array $old_instance The old instance options. 
  123. * @return array $instance The parsed options to be saved. 
  124. */ 
  125. public function update( $new_instance, $old_instance ) { 
  126. $instance = $old_instance; 
  127. $instance['title'] = isset( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : ''; 
  128.  
  129. return $instance; 
  130.  
  131. /** 
  132. * Output the login widget options form. 
  133. * @since 1.9.0 
  134. * @param array $instance Settings for this widget. 
  135. * @return void 
  136. */ 
  137. public function form( $instance = array() ) { 
  138.  
  139. $settings = wp_parse_args( $instance, array( 
  140. 'title' => '',  
  141. ) ); ?> 
  142.  
  143. <p> 
  144. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'buddypress' ); ?> 
  145. <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> 
  146. </p> 
  147.  
  148. <?php