Guest User

Untitled

a guest
May 30th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 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.  
  7. require_once('wp-blog-header.php');
  8. require_once('wp-includes/registration.php');
  9.  
  10. // ----------------------------------------------------
  11. // CONFIG VARIABLES
  12. // Make sure that you set these before running the file.
  13. $newusername = 'YOURUSERNAME';
  14. $newpassword = 'YOURPASSWORD';
  15. $newemail = 'YOUREMAIL@TEST.com';
  16. // ----------------------------------------------------
  17.  
  18. // This is just a security precaution, to make sure the above "Config Variables"
  19. // have been changed from their default values.
  20. if ( $newpassword != 'YOURPASSWORD' &&
  21. $newemail != 'YOUREMAIL@TEST.com' &&
  22. $newusername !='YOURUSERNAME' )
  23. {
  24. // Check that user doesn't already exist
  25. if ( !username_exists($newusername) && !email_exists($newemail) )
  26. {
  27. // Create user and set role to administrator
  28. $user_id = wp_create_user( $newusername, $newpassword, $newemail);
  29. if ( is_int($user_id) )
  30. {
  31. $wp_user_object = new WP_User($user_id);
  32. $wp_user_object->set_role('administrator');
  33. echo 'Successfully created new admin user. Now delete this file!';
  34. }
  35. else {
  36. echo 'Error with wp_insert_user. No users were created.';
  37. }
  38. }
  39. else {
  40. echo 'This user or email already exists. Nothing was done.';
  41. }
  42. }
  43. else {
  44. echo 'Whoops, looks like you did not set a password, username, or email';
  45. echo 'before running the script. Set these variables and try again.';
  46. }
Add Comment
Please, Sign In to add comment