WordPress.org

Make WordPress Core

Ticket #20637: patch-20637.diff

File patch-20637.diff, 2.5 KB (added by mikelittle, 6 years ago)

Patch to implement described behaviour

  • wp-includes/default-filters.php

     
    191191add_filter( 'pings_open',               '_close_comments_for_old_post', 10, 2 );
    192192add_filter( 'editable_slug',            'urldecode'                           );
    193193add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object'        );
     194add_filter( 'pre_user_display_name',    '_wp_pre_user_display_name', 10, 2    );
    194195
    195196// Actions
    196197add_action( 'wp_head',             'wp_enqueue_scripts',              1     );
  • wp-includes/user.php

     
    12911291        if ( !$update && ! defined( 'WP_IMPORTING' ) && email_exists($user_email) )
    12921292                return new WP_Error('existing_user_email', __('This email address is already registered.') );
    12931293
    1294         if ( empty($display_name) )
    1295                 $display_name = $user_login;
    1296         $display_name = apply_filters('pre_user_display_name', $display_name);
    1297 
    12981294        if ( empty($nickname) )
    12991295                $nickname = $user_login;
    13001296        $nickname = apply_filters('pre_user_nickname', $nickname);
     
    13071303                $last_name = '';
    13081304        $last_name = apply_filters('pre_user_last_name', $last_name);
    13091305
     1306        if ( empty($display_name) )
     1307                $display_name = $user_login;
     1308        $display_name = apply_filters('pre_user_display_name', $display_name, $userdata );
     1309
    13101310        if ( empty($description) )
    13111311                $description = '';
    13121312        $description = apply_filters('pre_user_description', $description);
     
    14891489        );
    14901490        return apply_filters( 'user_contactmethods', $user_contactmethods, $user );
    14911491}
     1492
     1493/**
     1494 * Create the default display name from the first and last names, but only if
     1495 * the field is currently empty.
     1496 *
     1497 * @access private
     1498 * @since 3.4
     1499 *
     1500 * @param object $display_name String the current display_name value
     1501 * @param object $userdata Array - The parameters originally passed to wp_insert_user()
     1502 * @return array $display_name the constructed display name
     1503 */
     1504function _wp_pre_user_display_name( $display_name, $userdata = array() ) {
     1505        if ( empty( $display_name ) ) {
     1506                if ( !empty( $userdata ) && ( !empty( $userdata['first_name'] ) || !empty( $userdata['last_name'] ) ) ) {
     1507                        return sprintf( _x( '%1$s %2$s', 'Construct user display name from first name and second name' ), $userdata['first_name'], $userdata['last_name'] );
     1508                }
     1509        }
     1510        return $display_name;
     1511}
     1512 No newline at end of file