Buddypress trick:Redirect Users to their profile on login

Jotted by Brajesh Singh in Buddypress, Buddypress Tricks on November 20, 2009

I found so many people discussing this on the buddypress forum, so I went ahead and thought to experiment a little.

You are going to need this trick if you are Buddypress site owner/developer and want to redirect your users to their profile on login.
My goal is:

  • Redirect a user to their profile, whether they login through yoursite.com/wp-login.php or any other page(In buddypress, we usually see a login box at all site  pages :) )
  • If site admin is logging in from front page of site, redirect back to front page.
  • If site admin is logging from the site back end, i.e  site.com/wp-login.php, send him to dashboard(wpmu dashboard)

So, I experimented a little and the filter “login_redirect” saved me a lot of hassle.

here is the code snippet to make it happen.


/*let us filter where to redirect */

add_filter("login_redirect","bpdev_redirect_to_profile",10,3);

function bpdev_redirect_to_profile($redirect_to_calculated,$redirect_url_specified,$user)
{
if(empty($redirect_to_calculated))
$redirect_to_calculated=admin_url();

/*if the user is not site admin,redirect to his/her profile*/
if(!is_site_admin($user->user_login))
return bp_core_get_user_domain($user->ID );
else
return $redirect_to_calculated; /*if site admin or not logged in,do not do anything much*/

}

Put it inside your plugins/bp-custom.php or create a new php file and put this in mu-plugins folder.
I Hope It helps.
Note: Now there is a plugin for it, you can download it from here
http://buddydev.com/buddypress/bp-redirect-to-profile-plugin-redirect-users-to-their-profile-on-login-on-buddypress-sites/

and yeh! do not forget to let me know, how it went with you, you experiences.

-:)

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Add to favorites
  • BlinkList
  • DZone
  • FriendFeed
  • IndianPad
  • MySpace
  • Netvouz
  • Reddit
  • SphereIt
  • StumbleUpon
  • Technorati

Related posts:

  1. BP Redirect to profile Plugin :redirect Users to their profile on Login on buddypress sites
  2. Plugin BP Auto activate Auto Login-redirect to profile, automatically activate your new user signup, log them in and redirect to their buddypress profile on signup
  3. Playing With buddypress and Wordpress, some codes for the site admins
  4. BP Flickr Plugin- Allow your users to show their latest flickr images on their BuddyPress profile
  5. Logout redirect plugin for wordpress Mu /buddypress

2 Comments Already!

Leave a Reply

Name [*]

Email [*]

Website Optional

Comment [*]

Please Note,The fields marked as * are required fields*


Get Adobe Flash playerPlugin by wpburn.com wordpress themes