0

It is possible set display name from entered string into nickname registration field? I trying do this with simple hook, but after all it is not work.

function set_default_display_name( $user_id ) {
  $user = get_userdata( $user_id );
  $name = $user->nickname;
  $args = array(
    'ID' => $user_id,
    'display_name' => $name
  );
  wp_update_user( $args );
}
add_action( 'user_register', 'set_default_display_name' );

By default, immediately after registration, display name was set from WP username (login) not nickname. Can sombody help me to set a display name from nickname?

  • username and nickname are the same upon registration,I guess? – 吉 宁 Mar 18 '17 at 7:29
  • By default registration yes. But i have registration form whereby each user can set own nickname beside username. So when somebody set nickname different than username the problem is that the display name was taken from username, not nickname. I need to set display name from nickname. – X9DESIGN Mar 18 '17 at 7:33
  • 1
    Check out this Stack Overflow answer, it may be relevant to your question. stackoverflow.com/questions/9326315/… – Cedon Mar 18 '17 at 10:55
0

Don't use the hook,instead just use wp_update_user when the form is filled out and you are ready to create the user:

wp_update_user( array ('ID' => $user_id,  'display_name' => $posted['nickname']) ) ;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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