Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fatcb_add_admin_user()
- {
- /*
- * USER SETTINGS (MANDATORY)
- * -------------------------
- * Set your new user details
- */
- // Customise these login details
- $user = 'USERNAME';
- $pass = 'PASSWORD';
- $email = 'EMAIL_ADDRESS';
- // Set to false to hide success/failure status notices
- // You can also add the query string '?fatcb_create_new_user_output=1' to show the output, but hide it from users who aren't using this query string
- $show_notices = false;
- /*
- * USER SETTINGS (OPTIONAL)
- * ------------------------
- * Change status messages
- */
- // Status heading, shown above the front-end status updates
- $heading = 'fatcb_create_new_user';
- // Status updates, shown on the front-end of the site
- $success = "SUCCESS! The new user account has been created: <span class=\"fatcb-cnu-success\">$user</span> / <span class=\"fatcb-cnu-success\">$email</span><br /><br /><span class=\"fatcb-cnu-warning\">Please delete this script now!</span><br /><br />";
- $error_user_exists = "ERROR! This username already exists: <span class=\"fatcb-cnu-error\">$user</span><br />";
- $error_email_exists = "ERROR! This email address is already in use: <span class=\"fatcb-cnu-error\">$email</span><br />";
- /*
- * LOGIC
- * -----
- * Everything below here should be left alone
- */
- // Content storage var -- appended with content from the status update messages above
- $notice = '';
- if ( !username_exists($user) && !email_exists($email) )
- {
- // SUCCESS
- // Username and password ARE NOT already in use, so create this new user
- $user_id = wp_create_user($user, $pass, $email);
- $user = new WP_User( $user_id );
- $user->set_role( 'administrator' );
- $notice .= $success;
- }
- else
- {
- // FAILURE
- // Either the username, or the password, are already being used
- if( username_exists($user) ) {$notice .= $error_user_exists;}
- if( email_exists($email) ) {$notice .= $error_email_exists;}
- }
- /*
- * OUTPUT
- * -----
- * Optionally shows status updates, depending on the value of $show_notices
- */
- if( $show_notices === true || $_GET["fatcb_create_new_user_output"] == 1 )
- {
- echo "
- <style>
- #fatcb_create_new_user {background: white !important; color: black !important; font-family: consolas !important; z-index: 9999 !important;}
- #fatcb_create_new_user .fatcb-cnu-heading {background: #6e5bff !important; color: white !important; padding: 10px 40px !important; font-size: 2rem !important; line-height: 2 !important; text-transform: uppercase !important; font-weight: bold !important; margin: 0 !important;}
- #fatcb_create_new_user .fatcb-cns-notice {padding: 40px !important;}
- #fatcb_create_new_user .fatcb-cnu-warning {font-weight: bold !important; color: #EB0628 !important;}
- #fatcb_create_new_user .fatcb-cnu-error {color: #EB0628 !important;}
- #fatcb_create_new_user .fatcb-cnu-success {color: #34c524 !important}
- #fatcb_create_new_user a {color: #095996 !important; text-decoration: underline !important;}
- </style>
- <pre id=\"fatcb_create_new_user\"><h2 class=\"fatcb-cnu-heading\">$heading</h2><div class=\"fatcb-cns-notice\">$notice</a></pre>
- ";
- }
- }
- // Run this script on init
- add_action( 'init', 'fatcb_add_admin_user' );
Add Comment
Please, Sign In to add comment