Advertisement
Guest User

Untitled

a guest
Apr 4th, 2017
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. /**
  2. * Read more {@link https://codex.wordpress.org/Function_Reference/wp_set_password}
  3. */
  4. wp_set_password( 'newpasswd', 1 );
  5.  
  6. /**
  7. * Create a new user with admin caps
  8. *
  9. * Read more {@link https://codex.wordpress.org/Function_Reference/wp_create_user}
  10. *
  11. * @version WP 4.7.3
  12. */
  13. add_action( 'init', 'wpse262478_add_new_adminuser' );
  14. function wpse262478_add_new_adminuser()
  15. {
  16. $username = 'aname';
  17. $email = 'whatever@domain.com';
  18. $password = 'LZTf$f$FR)Y@xye';
  19. $user_id = username_exists( $username );
  20.  
  21. if ( !$user_id && email_exists( $email ) == false )
  22. {
  23. $user_id = wp_create_user( $username, $password, $email );
  24.  
  25. if( !is_wp_error( $user_id ) )
  26. {
  27. $user = get_user_by( 'id', $user_id );
  28. $user->set_role( 'administrator' );
  29. }
  30. }
  31. } // end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement