How to change display name from wordpress users on necessary and make them the default?

The next question is how to make the default Display name selected by the machine name and the first letter of the surname of the user, it is of course possible to manually change in the settings of WordPress and there's a system at will puts itself which wants attribute, and it is necessary that it was installed automatic. Also the admin can display only either the surname, or name or email or username, or name and surname together, and you need to have only the name and the first letter of the surname and become, each registered user a gun?
June 14th 19 at 20:24
1 answer
June 14th 19 at 20:26
Code for output to a display name and last name by default, after registering, can be so
class myUsers {
static function init() {
// Change the user's display name after insertion
add_action( 'user_register', array( __CLASS__, 'change_display_name' ) );
static function change_display_name( $user_id ) {
$info = get_userdata( $user_id );
$args = array(
'ID' => $user_id,
'display_name' => $info->first_name . '' . $info->last_name
wp_update_user( $args );
try the plugin Force First and Last Name as Display Name - Josiah commented on June 14th 19 at 20:29

Find more questions by tags WordPress