Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. <?php
  2. /*
  3.  
  4. Created by: craig@123marbella.com 16/03/2014
  5.  
  6. Name of script: Create WordPress Admin User
  7.  
  8. Description: This script will create an admin user in wordpress
  9.  
  10. Usage: Create a new file in the root of the hosting account and drop this code into it then execute the script through the browser.
  11.  
  12. Note: ALWAYS delete this file from the server after use. Not tested on WPMU!
  13.  
  14. */
  15.  
  16. ###################################################
  17. //settings - change them if necessary
  18. ###################################################
  19. //this will be the path to the wordpress install relative to the root of the site
  20. //EG: if you have installed wordpress inside of a sub directory enter the name of the directory below.
  21. //if wordpress is installed in the root, then leave the field empty
  22. $wordpress_folder = "";
  23.  
  24. //preferred username
  25. $username = "tempuser";
  26.  
  27. //preferred password
  28. $password = "temppass";
  29.  
  30. //preferred email address
  31. $email = 'email@domain.com';
  32. ###################################################
  33. //no need to change anything after here
  34. ###################################################
  35.  
  36. //check if there is a wordpress folder defined
  37. if(!empty($wordpress_folder)) {
  38. $path_to_wp_load = $wordpress_folder .'/wp-load.php';
  39. } else {
  40. $path_to_wp_load = 'wp-load.php';
  41. }
  42.  
  43. echo '====================<br>';
  44. echo 'Craigs Backdoor Wordpress Admin User Script<br>';
  45. echo '====================<br>';
  46.  
  47. //first lets check if we can locate the wp-load.php file
  48. echo 'checking for wp-load.php at '. $path_to_wp_load ;
  49. echo '<br>';
  50.  
  51. if (!file_exists($path_to_wp_load)) {
  52. echo "ERROR! wp-load.php does not exist!";
  53. echo '<br>';
  54. exit;
  55. }
  56.  
  57. echo $path_to_wp_load . ' EXISTS!';
  58. echo '<br>';
  59.  
  60. //by now we should be plain sailing so go ahead and create the user
  61.  
  62. //execute the function to create the admin user
  63. create_wp_admin_user($username, $password, $email, $path_to_wp_load);
  64.  
  65. function create_wp_admin_user($username, $password, $email, $path_to_wp_load) {
  66.  
  67. //link this script into wordpress
  68. include($path_to_wp_load);
  69.  
  70. if (!username_exists($username)) {
  71. $user_id = wp_create_user($username, $password, $email);
  72. $user = new WP_User($user_id);
  73. $user->set_role('administrator');
  74.  
  75. echo 'user '.$username.' created! - dont forget to delete this file!!!!';
  76. echo '<br>';
  77.  
  78. } else {
  79.  
  80. echo 'ERROR! - ' . $username . ' already exists!';
  81. echo '<br>';
  82. exit;
  83.  
  84. }
  85.  
  86. }
  87.  
  88. add_action('init','create_wp_admin_user');
  89.  
  90. echo '<br>';
  91. echo '<-- end of script';
  92. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement