One time username change from frontend?

I’m using facebook connect plugin.

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

Read More

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

Related posts

Leave a Reply

1 comment

  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);