The MU forums have moved to WordPress.org

Login Redirect (18 posts)

  1. vezhead
    Member
    Posted 14 years ago #

    When someone logs in I want them to be redirected to their profile. I changed some code in the wp-login.php and it will now redirect them if they login at their site (theirblog.mywebsite.com/wp-login). If they log-in on my site (mywebsite.com/wp-login), it doesn't redirect them to their profile but their wp-admin page instead. I've looked through a lot of code but I can't figure out how to change it. Any help? Thanks!

  2. zappoman
    Member
    Posted 14 years ago #

    There is the following code in wp-login. You could change this so that whenever someone logs in they are sent to their profile... although... I'm not sure that users would like that...

    line 240

    // If the user can't edit posts, send them to their profile.
    if ( !$user->has_cap('edit_posts') && ( empty( $redirect_to ) || $redirect_to == 'wp-admin/' ) )
    $redirect_to = get_option('siteurl') . '/wp-admin/profile.php';

    Good luck

  3. vezhead
    Member
    Posted 14 years ago #

    Yeah, I changed it there and that works as long as they login in from theirblog.mysite.com/wp-login. But if they login from mysite.com/wp-login, it still sends them to their wp-admin.

  4. MrBrian
    Member
    Posted 14 years ago #

    Try changing line 204 to this:
    $redirect_to = 'wp-admin/profile.php';

  5. vezhead
    Member
    Posted 14 years ago #

    I changed that line but if a user logs in from mysite.com/wp-login it still takes them to theirblog.mysite.com/wp-admin instead of their profile page.

  6. MrBrian
    Member
    Posted 14 years ago #

    When you're on the login page, look up at the URL in the location bar. Is there a redirect_to= in it? Also, with zappoman's code, did you put it BEFORE this line:
    wp_safe_redirect($redirect_to);

  7. vezhead
    Member
    Posted 14 years ago #

    There is no redirect_to in the address bar. The code I changed from zappoman was on line 240-242 and the wp_safe_redirect code is on line 248. like this:

    // If the user can't edit posts, send them to their profile.
    if ( !$user->has_cap('edit_posts') && ( empty( $redirect_to ) || $redirect_to == 'wp-admin/profile.php' ) )
    $redirect_to = get_option('siteurl') . '/wp-admin/profile.php';

    if ( wp_login($user_login, $user_pass, $using_cookie) ) {
    if ( !$using_cookie )
    wp_setcookie($user_login, $user_pass, false, '', '', $rememberme);
    do_action('wp_login', $user_login);
    wp_safe_redirect($redirect_to);
    exit();

  8. MrBrian
    Member
    Posted 14 years ago #

    EDIT:

    Nevermind, i didn't read this thread correctly lol. I thought zappoman was providing some code. Anyway, i see why it's still going to the wp-admin (because it needs the siteurl prefixed or it defaults) so try this modification instead:

    $redirect_to = get_option('siteurl') . '/wp-admin/profile.php';

  9. vezhead
    Member
    Posted 14 years ago #

    Where do I put that code Mr.Brian. I have something similar to that listed in the post above yours. Looks identical to me.

  10. MrBrian
    Member
    Posted 14 years ago #

    Change line 204 to that. It's not identical, the code above will only set it based on certain ifs/ors.

  11. vezhead
    Member
    Posted 14 years ago #

    still taking me to /wp-admin/ unfortunately. Any other ideas?

  12. MrBrian
    Member
    Posted 14 years ago #

    I think i gave you the wrong line numbers, i forgot there was hacks to my file. You need to find this "$redirect_to = 'wp-admin/';" and change it to this "$redirect_to = get_option('siteurl') . '/wp-admin/profile.php';". Make sure your file is the original one, then make that change.

  13. vezhead
    Member
    Posted 14 years ago #

    I changed it like you said but its still not working right. Just to clarify, it does work if they login from their subdomain but if they login at mysite.com/wp-login.php it still goes to the wp-admin file. I also tried this code in my htaccess but it didn't work either. Stinkin' login...

    RewriteRule ^wp-admin$ wp-admin/profile.php
    RewriteRule ^wp-admin/$ wp-admin/profile.php

  14. andrea_r
    Moderator
    Posted 14 years ago #

    Just in case anyone else needs this, it's now somewhere around line 349.

    $redirect_to = 'wp-admin/';

    in my case, I want admins to login and edit an existing post first, so I just added edit.php to wp-admin/

    $redirect_to = 'wp-admin/edit.php';

    Still have to test it tho.

  15. carnold
    Member
    Posted 14 years ago #

    I have long been trying to get a "redirect" to users blogs. For example, when a user is on the main blog page, http://mytimewithgod.net, they login using the login on that main page and are sent/redirected to their blog. Is this possible?

  16. andrea_r
    Moderator
    Posted 14 years ago #

    Yep.

    I'm sure we've discussed it before.

  17. carnold
    Member
    Posted 14 years ago #

    Yep and i have searched and posted on this thread but got no answer:
    http://mu.wordpress.org/forums/topic.php?id=6400
    You will see on this thread the code i have tried. Any insight would be helpful

  18. carnold
    Member
    Posted 14 years ago #

    So, i am not sure if .$user_login is what i am suppose to use in order to get someones username and insert it into the address?
    $redirect_to = 'http://'.$user_login.'mysite.com'; should place http://'username.'mysite.com wherever "redirect_to" is found in the code, right? In the login.php file we have <input type="hidden" name="redirect_to"
    shouldn't this redirect_to equal http://'username.'mysite.com? This does not work and that is why i am unsure if i am suppose to be using $user_login for this

About this Topic