WordPress.org

Ready to get started?Download WordPress

Forums

Automatically Log In to WordPress (passing login variables) (4 posts)

  1. tbradley22
    Member
    Posted 2 years ago #

    I'm using WordPress to run a large number of sites, and I'd like for clients to be able to log in from our company website and automatically be redirected to their dashboard.

    The end result would be similar to Shopify http://www.shopify.com/login where users log into their website dashboard from the shopify website login page.

    I'm seeing that I'm not the only who's wanted to do this since there have been a number of other posts about it, but none had a solution.

    http://wordpress.org/support/topic/auto-login-to-wordpress-when-logged-in-from-another-site?replies=2
    http://wordpress.org/support/topic/log-into-wp-admin-by-passing-variables-from-another-site?replies=3

    Any tips or relevant plugins? Thanks.

  2. tbradley22
    Member
    Posted 2 years ago #

    Just found this!

    http://www.lbsharp.com/wordpress/index.php/2007/12/10/wordpress-auto-login/

    The post is 5 years old but still works perfectly in 3.2.1.

  3. tbradley22
    Member
    Posted 2 years ago #

    hmm stuck after all....

    I want to pull the username from the URL using $_GET, but when replacing the string ‘admin’ with the same string ‘admin’ from my $_GET variable, it doesn’t work. Very strange… I know I must be missing something.

    function auto_login() {
    // this works perfectly
    $user_login = ‘admin’;

    // this does not work even when setting the same variable via query string ?user=admin
    // $user_login = $_GET['user'];

    //get user’s ID
    $user = get_userdatabylogin($user_login);
    $user_id = $user->ID;

    //login
    wp_set_current_user($user_id, $user_login);
    wp_set_auth_cookie($user_id);
    do_action(‘wp_login’, $user_login);
    }
    add_action(‘init’, ‘auto_login’);

  4. mistercyril
    Member
    Posted 1 year ago #

    Hello,
    Did you end up finding the solution for this?
    Best,
    c.

Topic Closed

This topic has been closed to new replies.

About this Topic