Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

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);
share|improve this answer
    
Hi thanks for your answer , but what will happen if username already exists? –  Giri Apr 5 '12 at 19:38
    
you can check that before doing the update: username_exists() –  onetrickpony Apr 5 '12 at 22:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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