Hi everybody,
I'm trying to create a bit of code that would look at the username supplied during blog creation to automatically modify a users role on their new blog.
These are middle school students' and teachers' blogs. We want the students to be assigned a modified authors role on their blogs and for teachers to be administrators.
Using the code below and a static value for $username and get the desired result (i.e. a username ending in a number makes you an author).
I just can't figure out how to pull the username variable correctly. I've tried $wpdb calls which cause it to freeze and get_userdata(1), to no avail.
Any thoughts or blindingly obvious revelations to a newbie hacker would be greatly appreciated.
//Get user capabilities by login name
$role_str = $username;
//identify last character in the user_name string
$role_last = $role_str[strlen($role_str)-1];
$role_digit = array ('1','2','3','4','5','6','7','8','9','0');
//Give blog privileges based on user_name
if (in_array($role_last, $role_digit)) {
$blog_role = 'author';} else {
$blog_role = 'administrator';}
add_user_to_blog($blog_id, $user_id, $blog_role);