Redirect to bp profile upon login

I use a plugin for this in most of my multisites, but I have a situation now that requires a different solution. The designated home page of my wp multisite is NOT a wordpress page, but rather a whmcs page (this is the way I have it configured within the network settings of wp). So upon logging in, users presently are sent to whmcs -- which I don't want, I only want non-logged-in users going there. I can use the login redirect plugin (wpmudev) to send logged-in users to bp activity pages etc, but not the profile page, as it requires a dynamic link, which the plugin can not accept. Any suggestions? It has occurred to me to write something in the htaccess file that says "if logged into wp, go to dynamic bp profile page; if not logged into wp, go to whmcs", but I don't know the language well enough to pull it off.

  • Ash
    • WordPress Hacker

    Hello @xbladerunner

    I hope you are well today and thanks for asking the question.

    Please use the following code:

    add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
    function redirect_to_profile( $redirect_to, $request, $user  ) {
    	global $current_user;
    	get_currentuserinfo();
    	return site_url() . '/members/' . $current_user->user_login . '/profile/';
    }

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

  • xbladerunner
    • Syntax Hero

    Thanks Ash,

    I'm getting this warning: Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'my_login_redirect' not found or invalid function name in /XXXXXXXXXXXXXXXXX/wp-includes/plugin.php on line 214
    and the redirect is still going to whmcs... any suggestions? I put the code in mu-plugins folder.

  • Ash
    • WordPress Hacker

    Please try this:

    add_filter( 'login_redirect', 'redirect_to_profile', 999, 3 );
    function redirect_to_profile( $redirect_to, $request, $user  ) {
    	global $current_user;
    	get_currentuserinfo();
    	return site_url() . '/members/' . $current_user->user_login . '/profile/';
    }

    Please let us know if that works.

    Cheers
    Ash

  • Ash
    • WordPress Hacker

    Please try this:

    add_filter( 'login_redirect', 'redirect_to_profile', 999, 3 );
    function redirect_to_profile( $redirect_to, $request, $user  ) {
    	$current_user = wp_get_current_user();
    	get_currentuserinfo();
    	return site_url() . '/members/' . $current_user->user_login . '/profile/';
    }

    Let me know if it works.

    Cheers
    Ash

  • Ash
    • WordPress Hacker

    Hello @xbladerunner

    This is really odd :slight_frown:

    Would you please send me your ftp details and an user account?

    To send me details, please use our contact form: https://premium.wpmudev.org/contact/

    Select: I have a different question
    Subject: Attn-Ash
    Details: Send all required details (admin info and/or ftp details) with a link of this thread, so that I can track.
    Also post a note here once you send the info.

    I will be happy to take a look :slight_smile:

    Cheers
    Ash

  • Ash
    • WordPress Hacker

    Hello @xbladerunner

    Please check now. Used code:

    add_filter( 'login_redirect', 'redirect_to_profile', 999, 3 );
    function redirect_to_profile( $redirect_to, $request, $user  ) {
    	global $user;
    	return site_url() . '/community/members/' . $user->user_login . '/profile/';
    }

    Hope it helps :slight_smile: Please feel free to ask more question if you have.

    Cheers
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.