/bp-core/classes/class-bp-core-login-widget.php

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