Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

An implementation of the classic BuddyPress login form and logged in avatar,logout link provided as a widget.

View hnla BP login form widget
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
add_action('widgets_init', create_function('', 'return register_widget("HNLA_loggin_Widget");') );
 
class HNLA_loggin_Widget extends WP_Widget {
 
function __construct() {
parent::__construct(
'HNLA_loggin_Widget',
'BP Login, Logout form',
array( 'description' => __('Displays the standard BP login form and logged in avatar, logout link', 'hnla'), )
);
}
 
public function widget( $args, $instance ) {
global $bp, $current_user, $wpdb;
extract( $args );
$title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance );
echo $before_widget;
// If we have an empty title field in the widget we'll remove the heading tag markup as well
if( !empty( $title ) ) {
echo $before_title .
$title .
$after_title;
}
// Do our content to display ?>
<div class="sidebar-login">
<?php if( !is_user_logged_in() ) :?>
<p id="login-text">
<?php _e( 'To start connecting please log in first.', 'hnla' ) ?>
</p>
 
<?php if ( bp_get_signup_allowed() ) : ?>
<?php printf( __( ' You can also <a href="%s" title="Create an account">create an account</a>.', 'hnla' ), site_url( BP_REGISTER_SLUG . '/' ) ) ?>
<?php endif; ?>
<form name="login-form" id="sidebar-login-form" class="standard-form" action="<?php echo site_url( 'wp-login.php', 'login_post' ) ?>" method="post">
<label><?php _e( 'Username', 'hnla' ) ?>
<input type="text" name="log" id="sidebar-user-login" class="input focused" value="<?php if ( isset( $user_login) ) echo esc_attr(stripslashes($user_login)); ?>" /></label>
 
<label><?php _e( 'Password', 'hnla' ) ?>
<input type="password" name="pwd" id="sidebar-user-pass" class="input" value="" /></label>
 
<p class="forgetmenot"><label><input name="rememberme" type="checkbox" id="sidebar-rememberme" value="forever" /> <?php _e( 'Remember Me', 'hnla' ) ?></label></p>
 
<?php do_action( 'bp_sidebar_login_form' ) ?>
<input type="submit" name="wp-submit" id="sidebar-wp-submit" value="<?php _e('Log In'); ?>" />
<input type="hidden" name="testcookie" value="1" />
</form>
<?php else: ?>
<div id="sidebar-me">
<a href="<?php echo bp_loggedin_user_domain(); ?>">
<?php bp_loggedin_user_avatar( 'type=thumb&width=40&height=40' ); ?>
</a>
 
<h4><?php echo bp_core_get_userlink( bp_loggedin_user_id() ); ?></h4>
<a class="button logout" href="<?php echo wp_logout_url( wp_guess_url() ); ?>"><?php _e( 'Log Out', 'hnla' ); ?></a>
 
<?php do_action( 'bp_sidebar_me' ); ?>
</div>
<?php endif; ?>
</div><!-- // .sidebar-login -->
<?php
echo $after_widget;
// end markup generation
} // close widget function
 
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
return $instance;
}
public function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '') );
$title = strip_tags($instance['title']);
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<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($title); ?>" />
</p>
<?php
}
 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.