<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][7450] trunk: Introduce BuddyPress Login Widget</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/7450">7450</a></dd>
<dt>Author</dt> <dd>boonebgorges</dd>
<dt>Date</dt> <dd>2013-10-20 18:28:48 +0000 (Sun, 20 Oct 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Introduce BuddyPress Login Widget
This sidebar widget shows a set of login fields to logged-out users, along with
a link to the Register page (if registration is enabled). Logged-in users will
see their avatar, a link to their profile, and a Log Out link (as in the old
bp-default sidebar). This is particularly important now that BP can be used
with any theme, even themes that do not have obvious login mechanisms on the
front end.
Borrowed in part from bbPress, and in part from the BuddyPress Default theme.
Props modemlooper for an initial patch.
Fixes <a href="http://buddypress.trac.wordpress.org/ticket/1474">#1474</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpcorebpcorewidgetsphp">trunk/bp-core/bp-core-widgets.php</a></li>
<li><a href="#trunkbptemplatesbplegacycssbuddypresscss">trunk/bp-templates/bp-legacy/css/buddypress.css</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpcorebpcorewidgetsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core/bp-core-widgets.php (7449 => 7450)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core/bp-core-widgets.php 2013-10-20 00:06:35 UTC (rev 7449)
+++ trunk/bp-core/bp-core-widgets.php 2013-10-20 18:28:48 UTC (rev 7450)
</span><span class="lines">@@ -11,12 +11,134 @@
</span><span class="cx">
</span><span class="cx"> /* Register widgets for the core component */
</span><span class="cx"> function bp_core_register_widgets() {
</span><ins>+ add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Login_Widget");') );
</ins><span class="cx"> add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Members_Widget");') );
</span><span class="cx"> add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Whos_Online_Widget");') );
</span><span class="cx"> add_action('widgets_init', create_function('', 'return register_widget("BP_Core_Recently_Active_Widget");') );
</span><span class="cx"> }
</span><span class="cx"> add_action( 'bp_register_widgets', 'bp_core_register_widgets' );
</span><span class="cx">
</span><ins>+/**
+ * BuddyPress Login Widget
+ *
+ * @since BuddyPress (1.9.0)
+ */
+class BP_Core_Login_Widget extends WP_Widget {
+
+ /**
+ * Constructor method.
+ */
+ public function __construct() {
+ parent::__construct(
+ false,
+ _x( '(BuddyPress) Log In', 'Title of the login widget', 'buddypress' ),
+ array(
+ 'description' => __( 'Show a Log In form to logged-out visitors, and a Log Out link to those who are logged in.', 'buddypress' ),
+ 'classname' => 'widget_bp_core_login_widget buddypress widget',
+ )
+ );
+ }
+
+ /**
+ * Display the login widget.
+ *
+ * @see WP_Widget::widget() for description of parameters.
+ *
+ * @param array $args Widget arguments.
+ * @param array $instance Widget settings, as saved by the user.
+ */
+ public function widget( $args, $instance ) {
+ $title = apply_filters( 'widget_title', $instance['title'] );
+
+ echo $args['before_widget'];
+
+ echo $args['before_title'] . esc_html( $title ) . $args['after_title']; ?>
+
+ <?php if ( is_user_logged_in() ) : ?>
+
+ <?php do_action( 'bp_before_login_widget_loggedin' ); ?>
+
+ <div class="bp-login-widget-user-avatar">
+ <a href="<?php echo bp_loggedin_user_domain(); ?>">
+ <?php bp_loggedin_user_avatar( 'type=thumb&width=50&height=50' ); ?>
+ </a>
+ </div>
+
+ <div class="bp-login-widget-user-links">
+ <div class="bp-login-widget-user-link"><?php echo bp_core_get_userlink( bp_loggedin_user_id() ); ?></div>
+ <div class="bp-login-widget-user-logout"><a class="logout" href="<?php echo wp_logout_url( wp_guess_url() ); ?>"><?php _e( 'Log Out', 'buddypress' ); ?></a></div>
+ </div>
+
+ <?php do_action( 'bp_after_login_widget_loggedin' ); ?>
+
+ <?php else : ?>
+
+ <?php do_action( 'bp_before_login_widget_loggedout' ); ?>
+
+ <form name="bp-login-form" id="bp-login-widget-form" class="standard-form" action="<?php echo site_url( 'wp-login.php', 'login_post' ); ?>" method="post">
+ <label for="bp-login-widget-user-login"><?php _e( 'Username', 'buddypress' ); ?></label>
+ <input type="text" name="log" id="bp-login-widget-user-login" class="input" value="" />
+
+ <label for="bp-login-widget-user-pass"><?php _e( 'Password', 'buddypress' ); ?></label>
+ <input type="password" name="pwd" id="bp-login-widget-user-pass" class="input" value="" />
+
+ <div class="forgetmenot"><label><input name="rememberme" type="checkbox" id="bp-login-widget-rememberme" value="forever" /> <?php _e( 'Remember Me', 'buddypress' ); ?></label></div>
+
+ <input type="submit" name="wp-submit" id="bp-login-widget-submit" value="<?php _e( 'Log In', 'buddypress' ); ?>" />
+
+ <?php if ( bp_get_signup_allowed() ) : ?>
+
+ <span class="bp-login-widget-register-link"><?php printf( __( '<a href="%s" title="Register for a new account">Register</a>', 'buddypress' ), bp_get_signup_page() ); ?></span>
+
+ <?php endif; ?>
+
+ <input type="hidden" name="testcookie" value="1" />
+ </form>
+
+
+ <?php do_action( 'bp_after_login_widget_loggedout' ); ?>
+
+ <?php endif;
+
+ echo $args['after_widget'];
+ }
+
+ /**
+ * Update the login widget options.
+ *
+ * @param array $new_instance The new instance options.
+ * @param array $old_instance The old instance options.
+ * @return array $instance The parsed options to be saved.
+ */
+ public function update( $new_instance, $old_instance ) {
+ $instance = $old_instance;
+ $instance['title'] = strip_tags( $new_instance['title'] );
+ $instance['register'] = esc_url_raw( $new_instance['register'] );
+ $instance['lostpass'] = esc_url_raw( $new_instance['lostpass'] );
+
+ return $instance;
+ }
+
+ /**
+ * Output the login widget options form.
+ *
+ * @param $instance Settings for this widget.
+ */
+ public function form( $instance = array() ) {
+
+ $settings = wp_parse_args( $instance, array(
+ 'title' => '',
+ ) ); ?>
+
+ <p>
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'buddypress' ); ?>
+ <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>
+ </p>
+
+ <?php
+ }
+}
+
</ins><span class="cx"> /*** MEMBERS WIDGET *****************/
</span><span class="cx">
</span><span class="cx"> class BP_Core_Members_Widget extends WP_Widget {
</span></span></pre></div>
<a id="trunkbptemplatesbplegacycssbuddypresscss"></a>
<div class="modfile"><h4>Modified: trunk/bp-templates/bp-legacy/css/buddypress.css (7449 => 7450)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-templates/bp-legacy/css/buddypress.css 2013-10-20 00:06:35 UTC (rev 7449)
+++ trunk/bp-templates/bp-legacy/css/buddypress.css 2013-10-20 18:28:48 UTC (rev 7450)
</span><span class="lines">@@ -1427,6 +1427,32 @@
</span><span class="cx"> overflow: hidden;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+.widget.buddypress #bp-login-widget-form label {
+ display: block;
+ margin: 1rem 0 .5rem;
+}
+
+.widget.buddypress #bp-login-widget-form #bp-login-widget-submit {
+ margin-right: 10px;
+}
+
+.widget.buddypress .bp-login-widget-user-avatar {
+ float: left;
+ width: 60px;
+}
+
+.widget.buddypress .bp-login-widget-user-links > div {
+ padding-left: 60px;
+}
+
+.widget.buddypress .bp-login-widget-user-links > div {
+ margin-bottom: .5rem;
+}
+
+.widget.buddypress .bp-login-widget-user-links > div.bp-login-widget-user-link a {
+ font-weight: bold;
+}
+
</ins><span class="cx"> /*--------------------------------------------------------------
</span><span class="cx"> 4.0 - Media Queries
</span><span class="cx"> --------------------------------------------------------------*/
</span></span></pre>
</div>
</div>
</body>
</html>