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