Make WordPress Core

Opened 12 years ago

Closed 12 years ago

#20637 closed enhancement (fixed)

Change default display name for new users

Reported by: mikelittle's profile mikelittle Owned by: nacin's profile nacin
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.4
Component: Users Keywords: has-patch ux-feedback dev-feedback
Focuses: Cc:


As discussed on the wp-hackers mailing list here

It has been suggested that the default display_name for a new user should be constructed from the supplied first name and last name.

Attached is a patch to implement this behaviour. There are three parts:

1) Move the assignment of the display_name (in wp_insert_user()) to be after the first_name and last_name are assigned in case any plugins hooked on their respective filters chooses to modify them.

2) Add the $userdata parameter (passed to wp_insert_user()) to the filter call

3) Add a default filter hooked to pre_user_display_name. This default filter will concatenate the first and last names with a space between (internationalized), only if the current display_name is empty and either of first or last is filled.

Attachments (1)

patch-20637.diff (2.5 KB) - added by mikelittle 12 years ago.
Patch to implement described behaviour

Download all attachments as: .zip

Change History (8)

12 years ago

Patch to implement described behaviour

#1 @nacin
12 years ago

The $userdata context is not passed to the pre_user_* hooks in sanitize_user_field(). It would still work, but the intention for this to work on every save, or just create?

#2 @mikelittle
12 years ago

It was certainly originally only discussed in the context of creating users.

I think that semantically, being called from sanitize_user_field(), it doesn't feel like it should be changing that field in the same way.

Given that the new default filter won't make any changes if not passed the $userdata array, I think that end is accomplished. (Even if not by original design ;-)

#3 @DrewAPicture
12 years ago

  • Cc xoodrew@… added

#4 @JohnONolan
12 years ago

  • Cc JohnONolan added
  • Keywords ux-feedback dev-feedback added
  • Version set to 3.4


#5 @nacin
12 years ago

  • Milestone changed from Awaiting Review to 3.5
  • Owner set to nacin
  • Status changed from new to reviewing

#6 @nacin
12 years ago

As the various pre_user_* filters are designed to complement the same filters in sanitize_user_field(), we probably shouldn't try to overload it otherwise. The patch also will never work, because $display_name is set to $user_login before getting passed to the filter, which means empty($display_name) in _wp_pre_user_display_name() will never be true.

#7 @nacin
12 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In [21876]:

On user creation, default the display name to the first and last names provided. props mikelittle for the initial patch. fixes #20637.

Note: See TracTickets for help on using tickets.