Skip to content

Instantly share code, notes, and snippets.

@jawdatls
Created February 15, 2016 10:39
Show Gist options
  • Save jawdatls/e7e972b141fd9343d920 to your computer and use it in GitHub Desktop.
Save jawdatls/e7e972b141fd9343d920 to your computer and use it in GitHub Desktop.
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 );
$user->set_role( 'contributor' );
// Email the user
wp_mail( $email_address, 'Welcome!', 'Your Password: ' . $password );
} // end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment