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'.
$user->remove_role('subscriber')
otherwise they'll be both an admin and a subscriber ... which isn't the functionality you want.$user->remove_role('editor');
... you need to remove their current role so that their only role is administrator. And yes, I'm sure this is the right function - see the inline documentation of the function in the WP_User class.