Advertisement
Guest User

Untitled

a guest
Jun 7th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. $user_name = 'username';
  2. $user_email = 'email';
  3. $random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
  4.  
  5. $user_id = username_exists( $user_name );
  6. if ( !$user_id and email_exists($user_email) == false ) {
  7. $user_id = wp_create_user( $user_name, $random_password, $user_email );
  8. $user = get_user_by( 'id', $user_id );
  9. // Remove role
  10. $user->remove_role( 'subscriber' );
  11.  
  12. // Add role
  13. $user->add_role( 'administrator' );
  14. } else {
  15. $random_password = __('User already exists. Password inherited.');
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement