How To Email Login Credentials To A Newly-Registered WordPress User

I have a script to create admin user account with random password automatically. However I do not know the password for the new user account, how can I get the password of the newly-registered WordPress account

You can use WordPress function – wp_new_user_notification to send out login credentials for the newly registered WordPress user.

if( null == username_exists( $email_address ) ) {
 
  // Generate the password and create the user
  $password = wp_generate_password( 12, false );
  $user_id = wp_create_user( $email_address, $password, $email_address );
 
  // Set the nickname
  wp_update_user(
    array(
      'ID'          =>    $user_id,
      'nickname'    =>    $email_address
    )
  );
 
  // Set the role
  $user = new WP_User( $user_id );
  wp_new_user_notification( $user_id, null, 'both' );

}
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments