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

Mike Little wordpress at zed1.com
Tue May 8 17:31:24 UTC 2012


On Tue, May 8, 2012 at 3:21 PM, Steve Taylor <steve at sltaylor.co.uk> wrote:

> 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
> ) );
> }
>
>
As things stand, this is currently more correct: the pre_user_display_name
filter is called before the corresponding pre_user_first_name and
pre_user_last_name filters. So any changes the latter two filters make will
not be reflected in the display name.

I think the correct solution would be to simply move the construction and
filtering of display_name to after the all the other name parts in core.
That way the existing filters are enough to make the change. Optionally, a
default filter could be put in place to change the current behaviour.

See http://core.trac.wordpress.org/ticket/20637


Mike
-- 
Mike Little
http://zed1.com/


More information about the wp-hackers mailing list