• We wrote a simple login sync that will automatically login users to WordPress when they login on our main website. This worked fine on a regular WordPress, but as soon as we enabled Multisite it gave us

    Error establishing a database connection.

    Does Multisite changes certain things to cause this? Any help would be great appreciated!

    Here is the code for login sync that works with wordpress single, but breaks as soon as multisite is enabled.

    require_once('../3/wp-load.php'); //Include WP core
    wp_create_user( $request->getPost('username'), $request->getPost('password'), $request->getPost('email') );
    $rusername = $request->getPost('username'); // Get username of loged user
    $ruser = get_user_by('login', $rusername );
    
    if ( !is_wp_error( $ruser ) )
    {
        wp_clear_auth_cookie();
        wp_set_current_user ( $ruser->ID ); //Set current loged user in WP
        wp_set_auth_cookie  ( $ruser->ID ); //Set current Loged user cookie/session in WP
    }
Viewing 1 replies (of 1 total)
  • Moderator Bet Hannon

    (@bethannon1)

    I am definitely not a coder, but since no one has answered, I’ll give it a shot:

    Yes, multisite deals a little differently with users. All users are held in the network and given privileges on individual sites in the network. It may deal differently with cookies because of this, but I’m not sure. I would guess this is the reason for your code not working.

Viewing 1 replies (of 1 total)
  • The topic ‘WordPress Multisite breaks login/logout session’ is closed to new replies.