I’m trying to add a users to a specific blog with a role chosen by the user at registration.
I’m able to add the desired role to meta with this:
add_filter( 'add_signup_meta', 'add_register_meta' );
public function add_register_meta($meta = array()) {
$role = sanitize_text_field( $_POST['role'] );
$meta['role'] = $role;
return $meta;
}
I can see the serialized meta in the signup table of the database. So then I was trying to add the user with that role to a specific blog:
add_action ( 'wpmu_activate_user', 'assign_user_to_blog' );
public function assign_user_to_blog($user_id, $password, $meta ) {
if ( isset($meta['role']) ) {
add_user_to_blog( 3, $user_id, $meta['role']);
} else {
add_user_to_blog( 3, $user_id, "dmd");
}
}
But when the user is activated, nothing happens. The user isn’t added to the blog.
Something weird that I noticed is that the user receives the activation email, AND the email with the password at the same time. It’s like users are activated automatically, not by the activation key in the email. Could that be the issue? Why is this?
UPDATE: I moved the plugin to mu-plugins, and now it works, for the most part.
Users are being added to blog 3, but not with the role in the meta, but with the ‘dmd’ role.
Is there a way to view the value of $meta? var_dump doesn’t work.