Skip to content

Instantly share code, notes, and snippets.

@hnla
Created August 16, 2013 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hnla/6248724 to your computer and use it in GitHub Desktop.
Save hnla/6248724 to your computer and use it in GitHub Desktop.
An implementation of the classic BuddyPress login form and logged in avatar,logout link provided as a widget.
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