Advertisement
Guest User

Untitled

a guest
Jun 16th, 2017
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. <?php
  2. // ADD NEW ADMIN USER TO WORDPRESS
  3. // ----------------------------------
  4. // Put this file in your Wordpress root directory and run it from your browser.
  5. // Delete it when you're done.
  6. require_once('wp-blog-header.php');
  7. require_once('wp-includes/registration.php');
  8. // ----------------------------------------------------
  9. // CONFIG VARIABLES
  10. // Make sure that you set these before running the file.
  11. $newusername = 'SETAUSERNAME';
  12. $newpassword = 'SETAPASSWORD';
  13. $newemail = 'YOUR@EMAIL.COM';
  14. // ----------------------------------------------------
  15. // This is just a security precaution, to make sure the above "Config Variables"
  16. // have been changed from their default values.
  17. if ( $newpassword != 'SETAPASSWORD' &&
  18. $newemail != 'YOUR@EMAIL.COM' &&
  19. $newusername !='SETAUSERNAME' )
  20. {
  21. // Check that user doesn't already exist
  22. if ( !username_exists($newusername) && !email_exists($newemail) )
  23. {
  24. // Create user and set role to administrator
  25. $user_id = wp_create_user( $newusername, $newpassword, $newemail);
  26. if ( is_int($user_id) )
  27. {
  28. $wp_user_object = new WP_User($user_id);
  29. $wp_user_object->set_role('administrator');
  30. echo 'Successfully created new admin user. Now delete this file!';
  31. }
  32. else {
  33. echo 'Error with wp_insert_user. No users were created.';
  34. }
  35. }
  36. else {
  37. echo 'This user or email already exists. Nothing was done.';
  38. }
  39. }
  40. else {
  41. echo 'Make sure to set a password, username, or email before running ';
  42. echo 'the script. Set these variables and try again.';
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement