I want to change username and email after a user has been created and sent an email. This is because I want!! (yes, you read correctly) to have duplicates in my database. In normal situations this is not a good option but this I just to have to at the moment.
//Workaround-Set registered unix-timestamp before each new user-login and user-email when saving new users
//so we can use duplicate usernames and emails
function save_user_fields($user_id) {
global $wpdb;
$wpdb->query(
$wpdb->prepare(
"
UPDATE $wpdb->users
SET user_email=CONCAT('registered-%s',user_email),user_login=CONCAT('registered-%s',user_login),
WHERE ID = %s AND user_login LIKE 'VT2014%' AND user_email NOT LIKE 'registered%'
LIMIT 1
",
time(), time(),$wpdb->insert_id
)
);
}
add_action('user_register', 'save_user_fields'); //When adding new users
I want them to be changed AFTER they have been saved and after an email-confrimation mail has been sent to actual type-in-mail by user.
With above code Wordpress says that there are already an email adress in the database and stops there... ...and that is actuall what you want in most cases
I've also tried this:
function changeusername($user_id) {
global $wpdb;
$wpdb->query(
$wpdb->prepare(
"
UPDATE $wpdb->users
SET user_email=CONCAT('registered-%s',user_email),user_login=CONCAT('registered-%s',user_login),
WHERE ID = %s AND user_login LIKE 'VT2014%' AND user_email NOT LIKE 'registered%'
LIMIT 1
",
time(), time(),$wpdb->insert_id
)
);
}
add_action('register_post', 'changeusername'); //Just before saving new user to database
I want new users be changed AFTER they have been saved and after an email-confrimation mail has been sent to actual typed-in-mail by user. How could I solve that?