after successful import of ~4000 users and their blogs & posts from Liftype I have a rights problem: all users only are subscribers in their own blog. How can I mass change it to blog (not sitewide!) administrator privileges? All known functions I found in Codex gives Admin rights for the main blog, that’s not what I want.
Thanks
Uwe
Edit:
What’s wrong here?
include 'wp-load.php';
global $wpdb;
for ( $blog_id = 393; $blog_id <=4091; $blog_id++ ){
$bloguser= get_users_of_blog ($blog_id);
foreach ($bloguser as $usr) { // maybe there is more than one
$user_id = $usr->ID;
echo 'Blog No. '.$blog_id.' is property of user: '.$user_id; //control check
if ($user_id != '') {
$user = new WP_User($user_id);
$user->for_blog($blog_id);
$user->remove_role('editor');
$user->add_role('administrator');
}
}
}
echo 'Done!';
Code is well running, but there is no change to user’s role.
Edit: code typo edited, no changes to result
@EAMann Are you sure, add_role is the right function? I understand this is for adding a new role to WP system.
Edit: Updated the code again. Using update_user_meta. $check gives back ‘administrator’ (right!), but if I call the user’s blog properties, the user is always ‘editor’.
From your question, I’m assuming these are users on a specific blog within a MultiSite installation, correct? In that case, do the following:
You’ll have to do this for each page of users, and with 4000 users you’ll have about 160 pages of results. But it’s doable.
Update
If you want some specific code, I recommend looking at the
WP_User
class. This class defines two methods that you’d need to use iteratively:for_blog()
andadd_role()
.Basically, you’ll need to loop through your users based either on their IDs or usernames. Consider this untested example code:
By default, the
add_role()
method of theWP_User
class will act on the current blog … you usefor_blog()
to switch to a specific blog before running theadd_role()
method.So if you have the ids of your users and the ids of the blogs they’re supposed to be administrators for, you can loop through them pretty easily and set them up as administrators for their specific sites.