Viewing 1 replies (of 1 total)
  • Plugin Author Khaled

    (@khaledsaikat)

    Hello,

    Create a dropdown with meta_key: display_name, and add following codes to functions.php

    add_filter( 'user_meta_field_config', 'displayNameDropdown', 10, 4 );
    function displayNameDropdown( $field, $fieldID, $formName, $userID ){
        if ( $fieldID <> 'XYZ' ) return $field;
    
        $profileuser = new WP_User( $userID );
    
        $public_display = array();
        $public_display['display_nickname']  = $profileuser->nickname;
        $public_display['display_username']  = $profileuser->user_login;
    
        if ( !empty($profileuser->first_name) )
            $public_display['display_firstname'] = $profileuser->first_name;
    
        if ( !empty($profileuser->last_name) )
            $public_display['display_lastname'] = $profileuser->last_name;
    
        if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) {
            $public_display['display_firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name;
            $public_display['display_lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name;
        }
    
        if ( !in_array( $profileuser->display_name, $public_display ) ) // Only add this if it isn't duplicated elsewhere
            $public_display = array( 'display_displayname' => $profileuser->display_name ) + $public_display;
    
        $public_display = array_map( 'trim', $public_display );
        $public_display = array_unique( $public_display );
        $public_display = implode( ',', $public_display );
    
        $field['options'] = $public_display;
    
        return $field;
    }

    Don’t forget to change XYZ with field id.

    Thanks.

Viewing 1 replies (of 1 total)
  • The topic ‘Can "Display Name" be a drop down?’ is closed to new replies.