• Hi

    I have 2 users registered under wrong site on a multisite install. Is there a way I can change the site per user? I do not see this setting in Edit user…. Can I enforce this in DB? or other

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi @hebhansen
    Programmatic Way via add_user_to_blog()
    If you’re writing a quick PHP script or plugin:

    $user_id = 123; // the user ID
    $blog_id = 5; // the correct site/blog ID
    $wrong_blog_id = 3; // change this value
    $role = 'subscriber';

    add_user_to_blog( $blog_id, $user_id, $role );
    remove_user_from_blog( $wrong_blog_id, $user_id );

    Thanks
    Ahir Hemant

    Thread Starter hebhansen

    (@hebhansen)

    Thx @hemant-ahir

    If I have more tha one, do I seperate by comma? Sorry but I am no superstar in PHP.

    $user_id = 15, 22, 123; // the user ID

    Thx

    Hi @hebhansen

    No worries at all — you’re doing great! PHP is picky, so happy to help clear things up 😄

    In PHP, you can’t assign multiple values to a variable like this:

    $user_id = 15, 22, 123; // ❌ Invalid syntax

    Instead, you should use an array if you have multiple user IDs:

    $user_ids = [15, 22, 123];

    Then you can loop through each user ID like this:

    $user_ids = [15, 22, 123];
    $blog_id = 5;
    $wrong_blog_id = 3;
    $role = 'subscriber';

    foreach ( $user_ids as $user_id ) {
    add_user_to_blog( $blog_id, $user_id, $role );
    remove_user_from_blog( $wrong_blog_id, $user_id );
    }

    That will add all those users to the correct blog and remove them from the wrong one.

    Let me know if you want to apply different roles or blog IDs per user — I can help with that too!

    Thanks
    Ahir Hemant

    Thread Starter hebhansen

    (@hebhansen)

    @hemant-ahir

    Ok – Let me get this right:

    I prefer to manage users from backend and not by code. So can I fix the above in another way. Point is, in retrospect, what happened is that I set up the site as superadmin as a subdomain. This user was registered. Then I had a go ahead and converted this site to a top level domain. That means I am positive that this user has a cross registration, that somehow conflicts with a lot of other things. Fx she cannot open the FSE Editor etc. So my gut feeling is that something is off and I may need to sort this in DB. I just don’t know where to look and fix this.

    Let me hear your thoughts on this before I start hacking in PHP that may not work due to a deeper issue!?

    Thx

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Multisite – User registered under wrong site’ is closed to new replies.