Advertisement
Guest User

Create WP admin user via FTP

a guest
Mar 30th, 2020
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. Step 1: Add first part of the code to your theme functions.php file, go to your site and load the frontpage once
  5. */
  6.  
  7. function add_admin_acct(){
  8.     $login = 'USERNAME'; // Change to your desired username - MAKE SURE USERNAME ISN'T ALREADY USED
  9.     $passw = 'PASSWORD'; // Change to your desired password - MAKE SURE PASSWORD ISN'T ALREADY USED
  10.     $email = 'EMAIL'; // Change to your desired email - MAKE SURE EMAIL ISN'T ALREADY USED
  11.  
  12.     if ( !username_exists( $login )  && !email_exists( $email ) ) {
  13.         $user_id = wp_create_user( $login, $passw, $email );
  14.         $user = new WP_User( $user_id );
  15.         $user->set_role( 'administrator' );
  16.     }
  17. }
  18. add_action('init','add_admin_acct');
  19.  
  20. /*
  21. Step 2: Loading your site will fire the code and create that new user, you can now remove above code
  22. */
  23.  
  24. /*
  25. Step 3: Login to your WP admin with your new user and find his ID
  26. */
  27.  
  28. /*
  29. Step 4: Add below code with your USER_ID in functions.php and refresh the site
  30. */
  31. grant_super_admin(USER_ID);
  32.  
  33. /*
  34. Step 5: That will set your new user as super-admin and you can remove above code as well
  35. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement