Redirect to author profile after fb connect

Hi,

I want to redirect users after login to their front end profile page, how do I do this?
I am using the following code in functions.php but I think the setting in Ultimate Facebook is causing a conflict -
function myplugin_registration_save($user_id) { if(isset($_SESSION['selectedWHS'])) {
$value = $_SESSION['selectedWHS'];
myEndSession();
} else {
$value = 'none';
}
update_user_meta($user_id, 'whs_list', $value);
get_currentuserinfo();
return get_author_link($current_user->ID);
}

Also, how can i fill user's profile information in wordpress from facebook by default? I noticed that the information is stored in usermeta but not filled in the profile.

  • Jack Kitterhing
    • Code Norris

    Hi there @ajayrds

    I hope you are well today and thank you for your question.

    With regards to the redirect, do you have BuddyPress installed and that's the profile they will be redirected to?

    The fields for the user profile they can be mapped in Ultimate facebook > settings :slight_smile:

    Thank you!

    Kind Regards
    Jack.

  • ajayrds
    • Flash Drive

    Hello,

    No I do not have buddypress installed. I am using custom code in the author.php file.
    Profile info - I have already mapped the required fields in the UF settings page, but the information does not show up by default on the user's profile page.

  • ajayrds
    • Flash Drive

    Hi,

    Can you at least tell me how to disable the redirect on login completely in the UF plugin?
    My author urls are <home>/traveler/username and I tried to use macros (as specified in the info popup) to make this work - selected Site URL and /traveler/USER_LOGIN, but that is just redirecting to <home>/travelers. Are there any other macros I can use?

    Since this did not work, I tried to add code in the functions.php file using add_filter("login_redirect", "my_login_redirect", 10, 3) but the plugin is superceding this function too.

  • Jack Kitterhing
    • Code Norris

    Hi there @ajayrds

    I hope you are well today, sorry for the delay on this.

    I have just been speaking with the lead developer on to disable the redirection you can leave the URL fragment empty and that should disable it.

    Would it be possible to get a look at your site, so I can see why the fields might not be mapping?

    Thank you!

    Kind Regards
    Jack.

  • ajayrds
    • Flash Drive

    Hi,

    Please check on the staging site - http://www.ajaymreddy.com/stg/.
    I have removed the URL fragment in the option against Redirect on login.
    Also, I have this code now to redirect users after login in my functions.php, but the redirect is still not working -

    //From http://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect
    function my_login_redirect( $redirect_to, $request, $user ){
    //is there a user to check?
    if( isset( $user->roles ) && is_array( $user->roles ) ) {
    //check for admins
    if( in_array( "administrator", $user->roles ) ) {
    // redirect them to the default place
    return $redirect_to;
    } else {
    return "http://google.com";
    // return home_url();
    }
    }
    else {
    return $redirect_to;
    }
    }
    add_filter("login_redirect", "my_login_redirect", 10, 3);

    You can test the mapping from facebook as well.

  • Jack Kitterhing
    • Code Norris

    Hi there @ajayrds

    Thanks for the additional information, everything looks good on the site, no errors, apart from some missing images but that shouldn't cause the issue.

    The code above, that is just taken from the codex correct? You need to modify that code to do what you want, it most likely won't work after login with facebook, it's not the correct parameters, nor is it correct I'm afraid for login after a normal WordPress account, which I just have checked with.

    I have just registered a test account, could you upgrade the user: jackstest to an admin please? So I can check all settings :slight_smile:

    Thank you!

    Kind Regards
    Jack.

  • ajayrds
    • Flash Drive

    Hello,

    I have been able to get redirect working for normal logins using this php code -
    /**
    * Redirect non-admins to the homepage after logging into the site.
    * http://tommcfarlin.com/redirect-non-admin/
    * @since 1.0
    */
    function soi_login_redirect( $redirect_to, $request, $user ) {
    return ( is_array( $user->roles ) && in_array( 'administrator', $user->roles ) ) ? admin_url() : site_url('traveler/'.$user->user_login);
    } // end soi_login_redirect
    add_filter( 'login_redirect', 'soi_login_redirect', 1, 3 );

    However, as you mentioned this code does not work for facebook login. Could you help me with that?
    Do have a look at why facebook data is not getting updated in user profile also, maybe I have missed a setting.

  • Jack Kitterhing
    • Code Norris

    Hi there @ajayrds

    Thanks for upgrading me and I'm glad to hear that you have got the login redirect working, hopefully we can assist you in getting the facebook redirect working,

    Now this can only be done from the facebook settings with the fragment URL, which wasn't working before, I have checked the settings on your site and the APP is not configured correctly. The credentials are incorrect.

    Could you try creating a new app please? https://premium.wpmudev.org/forums/topic/how-to-make-a-facebook-app

    Thank you!

    Kind Regards
    Jack.

  • ajayrds
    • Flash Drive

    Do you mean the app ID and secret for the app?
    The plugin seems to load correctly when I checked - it does show a green mark and says successfully connected to the app in Ultimate FB settings. Do you see something different?
    I have attached a screenshot of the app settings on facebook, let me know if I need to change something.

  • Jack Kitterhing
    • Code Norris

    Hi there @ajayrds

    Thanks for the additional information, I have logged in and check this issue again and it is now showing green for me (this was in the Facebook settings in WordPress).

    After testing with a colleague, we believe the redirect issue is now sorted, you wanted them redirect to your home page correct? If so it is now doing that, what it needed was the SITE URL choosen from box, and then put / in the box below that as it doesn't need the full url in that box if that makes sense?

    The mapping was tested and was working apart from the date of birth field was the mapping needed to be changed on, everything should now be working :slight_smile:

    Thank you!

    Kind regards
    Jack.

  • ajayrds
    • Flash Drive

    Thanks Jack.
    I want to redirect users to their author page and not the home page of the site.
    As you can see on the website, loggin in with WP credentials will take you to the correct page whereas loggin in with FB will take you to the home page.

  • Jack Kitterhing
    • Code Norris

    Hi there @ajayrds

    Thanks for the clarification on that, /traveler/USER _LOGIN should be working but it isn't, the developer is looking into this for you :slight_smile:

    Thank you for your patience, please be aware that this may take longer than most tickets, but we aim to have this resolved as soon as possible for you :slight_smile:

    Kind Regards
    Jack.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.