using an email address as login is not smart, just imagine you will lose the email account and you can’t recover the password because the mail is sent to the old email address.
How does having a username help with this? The password recovery email will still be sent to the email address you have lost.
email as login is with conflict with philosophy of wordpress
How so? WordPress itself allows to login with both username and email.
WPAdverts uses email as login as this is one thing less for users to think about. This is actually a common trend among all websites you no longer need to come up with your own login, just the email address will do.
Either way, to allow users to have a username set you can add the code below in your theme functions.php file, it will add the username field and use it when registering a user
add_action( "init", "my_username_init", 100 );
function my_username_init() {
remove_filter('adverts_create_user_from_post_id', '_adverts_create_user_from_post_id', 20, 2 );
add_filter('adverts_create_user_from_post_id', '_my_username_create_user_from_post_id', 20, 2 );
add_filter('adverts_form_load', 'adverts_add_username_field' );
}
function _my_username_create_user_from_post_id( $user_id, $post_id ) {
if( $user_id !== null ) {
// some other filter already registered user, skip registration then
return $user_id;
}
$email_address = get_post_meta( $post_id, "adverts_email", true );
$username = get_post_meta( $post_id, "my_username", true );
$full_name = get_post_meta( $post_id, "adverts_person", true );
// Generate the password and create the user
$password = wp_generate_password( 12, false );
$user_id = wp_create_user( $username, $password, $email_address );
// Set the nickname
wp_update_user(
array(
'ID' => $user_id,
'nickname' => $full_name,
'display_name'=> $full_name
)
);
// Set the role
$user = new WP_User( $user_id );
$user->set_role( 'subscriber' );
// Email the user
do_action( "adverts_new_user_notification", $user_id, null, "both", $password );
return $user_id;
}
function adverts_add_username_field( $form ) {
if( $form["name"] != "advert" ) {
return $form;
}
$form["field"][] = array(
"name" => "my_username",
"type" => "adverts_field_text",
"order" => 2.1,
"label" => "Username",
"is_required" => false,
"validator" => array()
);
return $form;
}