admin_url( 'admin-ajax.php' ) ) ); } function addmultiuser_style() { wp_register_style($handle = 'amu_css_style', $src = plugins_url('amustyle.css', __FILE__), $deps = array(), $ver = '1.1.0', $media = 'all'); wp_enqueue_style('amu_css_style'); } //MAIN FUNCTION function add_multiple_users() { //test again for admin priviledges if (!current_user_can('manage_options') ) { wp_die( __('You do not have sufficient permissions to access this page.') ); } //globals for functions global $current_user, $wpdb; get_currentuserinfo(); $thisUserEmail = $current_user->user_email; $thisBlogName = get_bloginfo('name'); $thisBlogUrl = site_url(); $confirmationStack = ''; //begin wrap class echo '
New User User Accounts Processed!
'; echo 'If you did not request this information emailed to you and you wish to save the information for future reference, please copy the New User Information section below IMMEDIATELY and save it for you records. It will not be available again if the Add New form is submitted again or you navigate away from this page.'; echo 'If any of your users have not been added due to an error, please note these errors and use the Add Multiple Users form below to attempt these registrations again.
'; echo ''.$icounter.'. Error: The user '.$username. ' already exists. Please try adding this user again with a different username.
'; $confirmationStack = $confirmationStack.$fail_userexists; echo $fail_userexists; } else { //process password if ( $password == '' ) { //generate random password if blank $password = wp_generate_password(); } //process email if ( $email == '' ) { if ( $forceEmail == 'no' ) { $fail_noemailadded = ''.$icounter.'. Error:: No email address for the user '.$username.' was included. Please try adding this user again with a valid email address.
'; $email = ''; $confirmationStack = $confirmationStack.$fail_noemailadded; echo $fail_noemailadded; } else { //generate random email address $email = 'temp_'.$username.'@temp'.$username.'.fake'; $emailGen = 'generated'; } } else { //validate entered password if set if ( $validateEmail == 'yes' ) { if ( !is_email( $email ) ) { $fail_emailnotvalid = ''.$icounter.'. Error:: New user '.$username.' was not added because the email address provided '.$email.' for this user was not valid. Please try again using a valid email address or disable email verification.
'; $email = ''; $confirmationStack = $confirmationStack.$fail_emailnotvalid; echo $fail_emailnotvalid; } } } //VERIFY ALL DATA EXISTS THEN PROCESS if ( ( $username != '' ) && ( $password != '' ) && ( $email != '' ) ) { //confirmation of addition of user $userSuccess = ''.$icounter.'. Success! The user '.$username.' has been added. Email Address for this user is '.$email.'. Password for this user is '.$password.'
'; $confirmationStack = $confirmationStack.$userSuccess; echo $userSuccess; //create new wordpress user $newuser = wp_create_user( $username, $password, $email ); $wp_user_object = new WP_User($newuser); //id of new user $newuserID = $wp_user_object->ID; //set user first name if ($firstname != '') { update_user_meta( $newuserID, 'first_name', $firstname ); } //set user last name if ($lastname != '') { update_user_meta( $newuserID, 'last_name', $lastname ); } //set user web site if ($website != '') { wp_update_user( array ('ID' => $newuserID, 'user_url' => $website) ) ; } //set user role if ($setAllRoles == 'notset') { $wp_user_object->set_role($userRole); } else { $wp_user_object->set_role($setAllRoles); } unset($wp_user_object); //send password to new user? if (($sendEmail == 'yes') && ($emailGen == 'valid')) { //set up email $to = $email; $subject = 'Your New User Account on '.$thisBlogName; $message = 'You have been registered on the '.$thisBlogName.' website.
You may now log into the site at '.$thisBlogUrl.'
Your username is '.$username.' and your password is '.$password.'
Regards,
'.$thisBlogName.'
This email is to confirm new user accounts for your website generated using the Add Multiple Users plugin.
All errors have also been included for reference when re-entering failed registrations.
'.$confirmationStack.'End of message.
'; $confirmHeaders = 'From: '.$thisUserEmail.' <'.$thisUserEmail.'>' . "\r\n"; //filter to create html email add_filter('wp_mail_content_type',create_function('', 'return "text/html"; ')); //send email wp_mail($confirmTo, $confirmSubject, $confirmMessage, $confirmHeaders); echo 'This information has been emailed to your WordPress administrator email <'.$thisUserEmail.'> as requested.
'; } //on-screen confirmation if ($sendEmail == 'yes') { echo 'All users have been sent their login information (except where random emails were force-created).
'; } //close new user information div echo 'Use the form below to add up to 50 users at once to your WordPress site.
';
echo 'Important - Please read the plugin information at the bottom of the page before first use.