Suppressing New User Blog Addition
-
Hi there,
We’re in the process of switching over to Authorizer, and we have Authorizer working except for a small issue. When a new user signs in through CAS and gets added as a network user, they also get added as a user to the blog in question. Ideally, we’d like the user to be added at the network level, but NOT be added as an individual blog user.
While I haven’t been able to stop that blog creation, my next attempt was delete the user after creation by hooking into the ‘add_user_to_blog’ action like so:
add_action('add_user_to_blog', 'remove_user_no_role', PHP_INT_MAX, 3); function remove_user_no_role($user_id, $role, $blog_id) { if ('' === $role || null == $role) { remove_user_from_blog($user_id); } }
However, this doesn’t appear to remove the user from the blog as I thought it might. I noticed there’s a ‘authorizer_user_register’ hook in the Authorization class file, but hooking into that doesn’t seem to work either.
Something like this achieves the desired effect:
add_action('admin_init', 'remove_no_roles'); function remove_no_roles() { $args = array( 'role__not_in' => array('administrator', 'editor', 'author', 'contributor', 'subscriber') ); $users_no_role = get_users($args); if (count($users_no_role) > 0) { foreach ($users_no_role as $user) { remove_user_from_blog($user->ID); } } }
But that’s not really ideal since it runs much more than necessary.
Can you think of a way to achieve this, or something else I can try with the hooks mentioned above? Thanks so much for any help you can offer!
- The topic ‘Suppressing New User Blog Addition’ is closed to new replies.