BuddyDev

32 Responses to BuddyPress trick: Redirect Users to their profile on login

  • Pingback:BP Redirect to profile Plugin :redirect Users to their profile on Login on buddypress sites | Buddy Dev

  • is this working with WPMU or WPSU too?

  • Thanks for the trick, it works @ buddypress!

    I'm just wondering,
    if I want site admin also be redirected to his profile, what should I change in

    if(!is_site_admin($user->user_login))

    Thanks!

    • Hi Natalie,
      Thanks for the comment.

      Please change this

      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*/

      to


      return bp_core_get_user_domain($user->ID );

      That should do it.

  • Hi Brajesh,

    I'd like to have two different home pages: one for logged users and other for non-logged users. What I have to change in your code to redirect the user to a specific the home page for logged-users? I don't want to use the profile page as home page.

    Thank you!

    • Hi Tazek,
      what will be the urls for the logged in user/non logged in user, I mean you will be using something like site.com/abc for logged in or non logged in, please let me know in a little detail and I will put the code.

      Thanks
      Brajesh

  • Hi Brajesh,

    Suppose that my website URL is: http://www.tazek.com.

    If a non-logged user visit this URL, then I want to display only the public content and also links to login form and register form.

    If a logged user visit this URL, then I want to redirect him to http://www.tazek.com/private/, then I want to display the private content.

    I don't know how to:
    – Check if the user is logged and redirect him to the private website (www.tazek.com/private) if he's logged;
    – Check if the user is logged and redirect him to the public website (www.tazek.com) if he isn't logged;
    – Always redirect the user to http://www.tazek.com/private/ the log-on process.

    Thank you!

  • Hi Brajesh, I wrote something wrong. The last line is:
    – Always redirect the user to http://www.tazek.com/private/ after the log-on process.

  • Ron #

    Well this is what worked for me i Downloaded it ran into a few errors.
    This is what fixed it all so it works great hope it helps people in the future.
    Keep the good work up.

    <?php
    /*
    Plugin Name: BP Redirect to Profile for Buddypress
    Description:Redirect user to their profile when they login
    Version: 1.1
    Requires at least: BuddyPress 1.1
    Tested up to: BuddyPress 1.2+wpmu 2.9.1
    License: GNU General Public License 2.0 (GPL) http://www.gnu.org/licenses/gpl.html
    Author: Brajesh Singh
    Author URI: https://buddydev.com
    Plugin URI:https://buddydev.com/buddypress/bp-redirect-to-profile-plugin-redirect-users-to-their-profile-on-login-on-buddypress-sites/
    Last updated:16th feb 2010
    */
    /***
    Copyright (C) 2009 Brajesh Singh(buddydev.com)

    This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along with this program; if not, see .

    /*Add a filter to filter the redirect url for login*/

    add_filter("login_redirect","bpdev_redirect_to_profile",100,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*/

    }
    if ( !function_exists( 'is_site_admin' ) ) :
    function is_site_admin() {
    return is_super_admin();
    }
    endif;
    ?>

  • I'm just trying to figure out the code I would need to determine if a user is an admin or group admin, and if so display ABC set of links, but if not display XYZ set of links. I've been playing around with the code here a bit but no luck.

    • Hi Alan,
      sorry the above code is not about detecting if the user is siteadmin/group admin. You can check it by using is_super_admin and also you will need to check like the code here(for finding if user is admin of any group)
      http://pastebin.com/LZud06Rv

  • Sam #

    Hi,

    We changed our redirect to the user's profile, but would now like to eliminate the change. I cannot remember for the life of me where we placed the code – but I do recall actually using a link to /profile.

    Any help would be appreciated. We want to use your plugin, but whatever we did earlier is overriding your plugin completely. I am scouring wp-login, have looked in the theme's pages, the plugin pages.. nothing yet. Thank you!

  • Hi – what I want to do is to be able to send all logins to their profile upon login, but when clicking the HOME tab, I would like for them to be able to go to the frontpage. We are using the plugin. How do I make this happen?

    • Hi Tore,
      if you are using this plugin, then that is the default behavior. It will redirect to profile when logging in but does not restricts user to visit any page later.

  • Hello. Thank you for this.

    I have the following:

    add_filter("login_redirect","gd_redirect_welcome",10,3);
    function gd_redirect_welcome($redirect_to_calculated,$redirect_url_specified,$user)
    {

    /*if the user is not site admin,redirect to his/her profile*/
    $toflag = get_user_meta( $user->ID, 'gd_welcomeflag', true );
    if ( $toflag =='1' )
    {
    return $redirect_to_calculated; /*if site admin or not logged in,do not do anything much*/
    }
    else
    {
    $modified = site_url() . "/about/welcome-to-lam";
    return $modified;
    }
    }

    what am I doing wrong? This does not seem to be working.

    I'd like for the user to be redirected if the usermeta is not equal to 1, if it's equal to 1, don't do redirect with this function.

    this is in my functions.php file. any feedback would be appreciated!

    thank you.

    • Hi Giovanni,
      I just put it in my bp-custom.php and It redirected me to /about/welcome-to-liam page correctly.

      What is the issue you are facing?

  • This plugin works really well. Is there a way to redirect users to their profile page like this when they sign in with facebook connect? I'm going to the home page whenever I login in with fb connect.

    Is there a way to go into the facebook app and put in http://mydomain.com/members/username/
    Maybe some code that tells them that that's the username's profile to redirect to?

  • Rob #

    Thanks for the great free help Brajesh.

    I am using the Buddypress Wall plugin, and this redirects to a User's profile page, rather than their activity.

    So I changed the line
    return bp_core_get_user_domain($user->ID );
    to
    return bp_core_get_user_domain($user->ID) . '/activity';

    and this now sends them to their wall / activity after login.

    Just thought I'd share in case this is useful to anyone else.

    • Thank you Rob.
      I am sure It will help others 🙂

    • hi rob

      can u give complete code for rediredt to activity page….

  • Hi Brajesh, Very cool and effective. Thank you!

    Is it possible to redirect users to their profile without changing the URL structure (So maintain …/[user-name]/profile/)? Currently the code is removing "profile/" which appears to be hiding the profile tab from plugins which use the buddy menu to populate features or depend on link structure.

    Thanks again for your time!

  • Hi Brajesh,

    Love your plugin. Is it possible though to add a way to click back to their wall without having to click on their name. If there isn't could this be done. I would really like a menu button that says something like My Wall.

    All the best
    Dave

  • Went to download the plugin from WordPress.org, it displayed a message that the plugin had not been updated in over 3 years. But near the top of this page, you put

    "last Updated on: April 22, 2015 and tested with BuddyPress 2.2.3.1"

    What gives?

    • Hi Diana,
      Thank you for the comment. Please download the plugin now. I have updated the plugin and have tested it with BuddyPress 2.5.2

      Thank you
      Brajesh

  • Hi,
    I want to redirect the user to cart page if he has something in cart I am using the following code but it doesn't seem to work

    if I echo $redirect_to_calculated, it shows the correct URL i.e "https://edkasa.com/checkout" but it doesn't redirect to this URL
    Please helpp!!

    • Hi Haris,
      Please make sure that the redirect url is on the same domain(wp_safe_redirect needs that)
      Also, try changing priority from 50 to may be 1001 and see if that makes it work.

      regards
      Brajesh

  • It worked for me thank you Brijesh. You are a great web developer.