[wp-hackers] Change default display name for new users

Steve Taylor steve at sltaylor.co.uk
Tue May 8 14:21:41 UTC 2012


FWIW, I use:

add_action( 'user_register', 'slt_default_user_display_name' );
function slt_default_user_display_name( $user_id ) {
	$first = get_user_meta( $user_id, 'first_name', true );
	$last = get_user_meta( $user_id, 'last_name', true );
	$display = $first . " " . $last;
	wp_update_user( array( "ID" => $user_id, "display_name" => $display ) );
}


On 7 May 2012 22:41, Otto <otto at ottodestruct.com> wrote:
> Put this in a plugin or something similar.
>
> add_filter('pre_user_display_name','default_display_name');
> function default_display_name($name) {
> if ( isset( $_POST['display_name'] ) )
>  return sanitize_text_field( $_POST['display_name'] );
>
> if ( isset( $_POST['first_name'] ) ) {
>  $name = sanitize_text_field( $_POST['first_name'] );
> if ( isset( $_POST['last_name'] ) )
>  $name .= ' '. sanitize_text_field( $_POST['last_name'] );
> }
>  return $name;
> }
>
> That will change the default display name at the time of user creation to
> be firstname lastname.
>
> -Otto
>
>
> On Mon, May 7, 2012 at 3:11 PM, Robert Lusby <nanogwp at gmail.com> wrote:
>
>> Is there a hook or filter that can be used to override the default display
>> name? Can't seem to see on in the code, but sure I'm missing something.
>>
>> In my install it makes more sense for display_name to be first name + last
>> name for all new users, rather than login name.
>>
>> Thanks,
>> Robert.
>> ______________________________**_________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.**com <wp-hackers at lists.automattic.com>
>> http://lists.automattic.com/**mailman/listinfo/wp-hackers<http://lists.automattic.com/mailman/listinfo/wp-hackers>
>>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list