1

I'm using facebook connect plugin.

Usernames generated by that plugin look like firstname_lastname. I mean it looks ugly.

I would like to give the privilege to my users to change the username BUT ONCE.

I hope its like changing the password.

Here is my change password function.

Can anyone help me to modify it?

Thanks

1 Answer 1

1

Just add a meta record that tracks the state of the username-changing actions:

$user = wp_get_current_user();

$did_one_change = get_user_meta($user->ID, 'changed_username', true);

if($did_one_change !== false)
  wp_die('You already changed your user name once!');

wp_update_user(array(
  'ID'         => $user->ID, 
  'first_name' => $_POST['first_name'],
  'last_name'  => $_POST['last_name'],
));

// here add a meta entry that suggests the user has changed their name once
update_user_meta($user->ID, 'changed_username', 1);
2
  • Hi thanks for your answer , but what will happen if username already exists? Commented Apr 5, 2012 at 19:38
  • you can check that before doing the update: username_exists() Commented Apr 5, 2012 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.