WordPress display name string manipulation

Question

I have set the display name to show both first name and last name using the function below. How do I manipulate the LAST NAME to only pull the first letter of that string? Example, if you sign up as John Doe (First name= John, Last name= Doe), I want your display name to be John D.

Thanks

function force_pretty_displaynames($user_login, $user) {

  $outcome = trim(get_user_meta($user->ID, 'first_name', true) . " " . get_user_meta($user->ID, 'last_name', true));
  if (!empty($outcome) && ($user->data->display_name!=$outcome)) {
    wp_update_user( array ('ID' => $user->ID, 'display_name' => $outcome));    
  }
}
add_action('wp_login','force_pretty_displaynames',10,2); 
0
, , eddie 10 years 2013-08-23T14:23:43-05:00 0 Answers 61 views 0

Leave an answer

Browse
Browse