I've commented on a few posts, but thought I would start my own thread...
I want a user to be able to register on a sub blog (and not be handed off to the root account) of a multisite install, and the user activates their account and is automatically granted specific rights on THAT SITE ONLY.
I have 3 questions, detailed below, but first, the background...
I have a multisite install with several sub-blogs. I am aware of the "default" behaviour of registration whereby a new user submits the registration, checks their email, activates their account (ie, confirms their email) and is then placed in a "dead-zone" until an admin comes by and adds the user to a blog.
I know there is a plugin that will allow you to set default roles for different sites (across all sites), but this is not a suitable fix as this gives the user access to multiple sites that really are quite irrelevant and maybe even detrimental in a competitive sense. The plugin also doesn't distinguish where the user came from (ie, which site) and apply only the correct role for the blog the user registered--if there is a plugin for this, I would like to know about it.
I have broken this down into a 2 step process:
1. have the user remain on the blog that they are registering with (and not being palmed off to the root blog, and
2. adding a default role for the user, for that particular blog they are registering/activating with.
I have achieved point 1 by editing out the relevant sections of wp-signup.php and wp-activate.php. So, my first question is:
Q1. Is there any detrimental effect to doing this? The user is still added to the database with exactly the same capabilities as a user added before making these changes. They still have no capabilities with any blog other than being able to view their profile. They are in the database - just not associated with any blog.
I am stuck at point 2. I know where I should be editing, but I don't know what to put there exactly. I have identified the portion of code I want to add to within wp-activate.php:
$url = get_blogaddress_by_id( (int) $blog_id); $user = new WP_User( (int) $user_id); // <!-- I want to add a line of code here... --> ?> <h2><?php _e('Your account is now active!'); ?></h2>
I know I want to use the add_role function, but I don't know how to call it safely and to make sure that the correct capabilities are added to that role, if they need to be... And to make sure it's only added for the specified blog.
I'm thinking something along the lines of
$user->add_role( $role_name ); where $role_name should/would equal "subscriber"???
Q2. How do I correctly call the add_role function, adding the user to the subscribers role for the blog they are currently activating? I want to call it using correct wordpress protocols, such that should "subscriber" (or "Subscriber") be hardcoded into the code? I'm thinking not. Should I use the get_role function to determine the text to use? I usually do just play around and try things and see what happens, so I'm sorry if it's a stupid question, I just don't want to "experiment" in this area.
Q3. wp-activate.php and wp-signup.php are not located in the template file area. How do I correctly override these files? Or should I NOT be overriding them at all? Ok, technically not one question. :^) Can I just place a copy in the child theme I have created for these sites? Or are these files that are not meant to be overridden?
BTW, I have been searching for an answer for this for over a week now and this seems to be a common problem to which there is no documented solution (that I could find). I am determined to come to a solution and hopefully it can be documented here. Most threads on this topic have died off and been closed, although there are a couple that I have found to be open at the moment but still have no solution.