I was looking at BP Tricks and thought ‘You know what would rock my site? A sidebar profile controller!’ Turns out this is pretty easy and only ‘requires’ two plugins.
My final product (see left) isn’t super impressive, but it’s pretty simple and easy to use. The basic idea is that I have two master widgets. One is what the non-logged in user sees (a simple signup window) and one is what the logged in user sees. The logged in user should be able to see their profile info, their notifications and anythign else I want. Before I got started I made a list of what I wanted them to see.
- Profile – This lists your profile, edit links, settings links, and a logout link
- Notifications – This lists everything that can email you: notices/messages, comment subscriptions, newsletters, mailing lists
- Achivements – I use Paul Gibbs’ Achievements for BuddyPress
- Activity – Links to the various activity screens
First I decided I wanted an accordian style profile, where you had sections. I grabbed Tabbed Widgets and tossed that in my widget area. Then I used Widget Logic and set the tab to only show if a user was logged in. If the user is NOT logged in, I used the PHP Code Widget to display a login form. Since I’m using BuddyPress, I just grabbed this wholesale from the source.
<form id="sidebar-login-form" class="standard-form" action="<?php echo site_url( 'wp-login.php', 'login_post' ) ?>" method="post" name="login-form"><label><!--?php _e( 'Username', 'buddypress' ) ?--> <input id="sidebar-user-login" class="input" type="text" name="log" value="<?php echo esc_attr(stripslashes($user_login)); ?>" /></label><label><!--?php _e( 'Password', 'buddypress' ) ?--> <input id="sidebar-user-pass" class="input" type="password" name="pwd" value="" /></label> <p class="forgetmenot"><label> <input id="sidebar-rememberme" type="checkbox" name="rememberme" value="forever" /> <!--?php _e( 'Remember Me', 'buddypress' ) ?--></label></p> <center><!--?php do_action( 'bp_sidebar_login_form' ) ?--> <input id="sidebar-wp-submit" tabindex="100" type="submit" name="wp-submit" value="<?php _e('Log In'); ?>" /> <input type="hidden" name="testcookie" value="1" /></center></form>
I could have probably done this with a widget, but I like being able to customize my PHP as I want to. Next it was time to build my tabs. The Tabbed Widget plugin is pretty easy to use. You make your widgets in the Invisible Widget area and they show up available for the Tabbed Widget. Using the list I made above, I pulled in the obvious widgets. Three are PHP and one is the Achievements widget which came with the plugin. I dislike using plugins just for widgets, so my PHP is how I customized things. The PHP for notifications has extra cruft you probably won’t need, but I wanted you to see how you could easily port in any link.
My profile
<div> <div style="float: left; padding-left: 5px;"><strong>Hello, <!--?php echo bp_loggedin_user_fullname() ?--></strong> • <a href="<?php echo bp_loggedin_user_domain() ?>profile/">Visit My Profile</a> • <a href="<?php echo bp_loggedin_user_domain() ?>profile/edit/">Edit My Profile</a> • <a href="<?php echo bp_loggedin_user_domain() ?>settings/">Edit My Settings</a> </div> </div>
My Notifications
• <a href="http://jorjafox.net/comment-subscriptions/">Edit Comment Subscriptions</a> • <a href="http://jorjafox.net/wp-admin/users.php?page=s2_users">Edit Daily Update Emails</a> • <a href="http://jorjafox.net/csiwatch/">Edit CSI Watch Subscription</a> • <?php if ( messages_get_unread_count() > 0 ) { ?><a href="<?php echo bp_loggedin_user_domain() ? rel="nofollow"><?php echo BP_MESSAGES_SLUG ?>">Inbox (<?php echo messages_get_unread_count(); ?>)</a><?php } else { ?><a href="<?php echo bp_loggedin_user_domain() ? rel="nofollow">/messages/">No new messages</a><?php } ?>
Activity
<div style="padding-left: 5px;"> <ul id="user-menu"> <li><a href="<?php echo bp_loggedin_user_domain() ?>activity/">Site Activity</a></li> <li><a href="<?php echo bp_loggedin_user_domain() ?>activity/just-me/">My Activity</a></li> <li><a href="<?php echo bp_loggedin_user_domain() ?>activity/favorites/">My Favorites</a></li> <li><a href="<?php echo bp_loggedin_user_domain() ?>activity/groups/">My Groups</a></li> <li><a href="<?php echo bp_loggedin_user_domain() ?>activity/mentions/">@<!--?php echo bp_loggedin_user_fullname() ?--></a></li> </ul> </div>
Once I was done making those, I just pulled them into my Tabbed Widget in the order I wanted, with the style and defaults I wanted. The rest was all CSS, which you can do yourself.
Basically, this just goes to show you that you can do pretty much anything you want with WordPress plugins. I really only needed two to do this, though the third (PHP Code Widget) really helped me take it to the next level. If you’re PHP shy, you can use Login with Ajax instead of my ‘Login’ code, BP Notification Widget instead of my Notification code, and I’m sure people can pick out some alternatives to other code bits.
Hope this gets you started!
Comments
21 responses to “Customizing a Sidebar Profile – BuddyPress”
Very awesome indeed! I like your approach and pretty creative approach you’ve used to pull this off!
I posted it on bp-tricks too 😉
I found your neat little idea on bp-tricks, thanks for putting together and posting. I didn’t actually know about tabbed widgets or php widgets, so I got a triple bonus from this one. I incorporated this on my site, I hope you don’t mind, it’s pretty cool. Thanks!
It’s there so you can use it 😀 It’s really because @josemv asked me to release my how-to after I bragged on Twitter.
Of note? This breaks on WordPress 3.1 right now! It’s the Tabbed Widget plugin. I dropped a note to the dev, and I suspect it’s because of the jQuery change in WP 3.1 😀 Gotta laugh!
It works on the 1.3 version of the plugin, but I’m having issues with 1.3.1 for some reason.
Okay, works on 1.3.1 too! Without any work on your end (it was a flaw in my theme).
I’ve run into this with TW 1.3.1 on a new theme, as well. I’m curious: what did you fix in your theme to make it work? Maybe I have the same issue…
It’s all in here : http://wordpress.org/support/topic/plugin-tabbed-widgets-not-working-on-31-rc3
This is not the best way to handle it, mind you, but it gets me through the day.
Awesome, thanks! I shall try this and see if it takes care of my issue
HOLY COW! Just found this post and I am simply over the moon – thank you soooo much for posting this. I have been wondering how to do this and you have saved my day. I am doing a little dance in your honour right now 😀
HOLY COW! Just found your post and I am overjoyed… I have been wondering how to do this and you have made it really easy to follow. Thanks soooooo much! I am doing a little dance in your honour 😀
This is cool, but I couldn’t get the notifications to work, they display in the buddy bar, but not in the sidebar… Any Ideas why?
I’ve done some tweaking since I wrote this.
http://pastebin.com/krfLn7B2
That’s what I’m using now and it seems to work.
That code worked, there were some syntax errors, but i fixed it and it works great thanks!
Can you post the changes to the syntax? Thanks!
When I use your new code I get this error:
Parse error: syntax error, unexpected ‘=’ in /home/tradesh4/public_html/wp-content/plugins/php-code-widget/execphp.php(44) : eval()’d code on line 2
Can You help? Thank you!
That code is what I was using (I’m not using it at all right now due to other issues, unrelated), but it worked fine.
I would start with just checking that the basic if/else part works:
if ( messages_get_unread_count() > 0 ) {
echo "Unread!";
} else {
echo "No new messages";
}
If that works, start adding in the rest.
Could you paste the full code that goes in the widget logic section? Thanks!
It’s a very basic call to is_user_logged_()
http://codex.wordpress.org/Function_Reference/is_user_logged_in
!is_user_logged_in() for If the user IS NOT logged in, and is_user_logged_in() for if they are 🙂
This looks awesome! I was wondering why my accordion widget doesn’t look as nice as yours does though, how can I fix this?
Probably CSS. It took a lot of wiggling around to get it right.