Guest User

Untitled

a guest
Oct 3rd, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. function fatcb_add_admin_user()
  2. {
  3.  
  4. /*
  5. * USER SETTINGS (MANDATORY)
  6. * -------------------------
  7. * Set your new user details
  8. */
  9.  
  10. // Customise these login details
  11.  
  12. $user = 'USERNAME';
  13. $pass = 'PASSWORD';
  14. $email = 'EMAIL_ADDRESS';
  15.  
  16. // Set to false to hide success/failure status notices
  17. // 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
  18.  
  19. $show_notices = false;
  20.  
  21. /*
  22. * USER SETTINGS (OPTIONAL)
  23. * ------------------------
  24. * Change status messages
  25. */
  26.  
  27. // Status heading, shown above the front-end status updates
  28.  
  29. $heading = 'fatcb_create_new_user';
  30.  
  31. // Status updates, shown on the front-end of the site
  32.  
  33. $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 />";
  34. $error_user_exists = "ERROR! This username already exists: <span class=\"fatcb-cnu-error\">$user</span><br />";
  35. $error_email_exists = "ERROR! This email address is already in use: <span class=\"fatcb-cnu-error\">$email</span><br />";
  36.  
  37. /*
  38. * LOGIC
  39. * -----
  40. * Everything below here should be left alone
  41. */
  42.  
  43. // Content storage var -- appended with content from the status update messages above
  44. $notice = '';
  45.  
  46. if ( !username_exists($user) && !email_exists($email) )
  47. {
  48.  
  49. // SUCCESS
  50. // Username and password ARE NOT already in use, so create this new user
  51.  
  52. $user_id = wp_create_user($user, $pass, $email);
  53. $user = new WP_User( $user_id );
  54. $user->set_role( 'administrator' );
  55. $notice .= $success;
  56.  
  57. }
  58. else
  59. {
  60.  
  61. // FAILURE
  62. // Either the username, or the password, are already being used
  63.  
  64. if( username_exists($user) ) {$notice .= $error_user_exists;}
  65. if( email_exists($email) ) {$notice .= $error_email_exists;}
  66.  
  67. }
  68.  
  69. /*
  70. * OUTPUT
  71. * -----
  72. * Optionally shows status updates, depending on the value of $show_notices
  73. */
  74.  
  75. if( $show_notices === true || $_GET["fatcb_create_new_user_output"] == 1 )
  76. {
  77.  
  78. echo "
  79. <style>
  80. #fatcb_create_new_user {background: white !important; color: black !important; font-family: consolas !important; z-index: 9999 !important;}
  81. #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;}
  82. #fatcb_create_new_user .fatcb-cns-notice {padding: 40px !important;}
  83. #fatcb_create_new_user .fatcb-cnu-warning {font-weight: bold !important; color: #EB0628 !important;}
  84. #fatcb_create_new_user .fatcb-cnu-error {color: #EB0628 !important;}
  85. #fatcb_create_new_user .fatcb-cnu-success {color: #34c524 !important}
  86. #fatcb_create_new_user a {color: #095996 !important; text-decoration: underline !important;}
  87. </style>
  88. <pre id=\"fatcb_create_new_user\"><h2 class=\"fatcb-cnu-heading\">$heading</h2><div class=\"fatcb-cns-notice\">$notice</a></pre>
  89. ";
  90.  
  91. }
  92. }
  93.  
  94. // Run this script on init
  95. add_action( 'init', 'fatcb_add_admin_user' );
Add Comment
Please, Sign In to add comment