WordPress.org

Make WordPress Core

Ticket #16045: 16045.2.diff

File 16045.2.diff, 2.5 KB (added by ryan, 5 years ago)

Introduce include_selected flag and add selected user to the end if not returned in the query

  • wp-includes/user.php

     
    957957 * <li>show - Default is 'display_name'. User table column to display. If the selected item is empty then the user_login will be displayed in parentheses</li> 
    958958 * <li>echo - Default is '1'. Whether to display or retrieve content.</li> 
    959959 * <li>selected - Which User ID is selected.</li> 
     960 * <li>include_selected - Always include the selected user ID in the dropdown. Default is false.</li> 
    960961 * <li>name - Default is 'user'. Name attribute of select element.</li> 
    961962 * <li>id - Default is the value of the 'name' parameter. ID attribute of select element.</li> 
    962963 * <li>class - Class attribute of select element.</li> 
     
    977978                'include' => '', 'exclude' => '', 'multi' => 0, 
    978979                'show' => 'display_name', 'echo' => 1, 
    979980                'selected' => 0, 'name' => 'user', 'class' => '', 'id' => '', 
    980                 'blog_id' => $GLOBALS['blog_id'], 'who' => '' 
     981                'blog_id' => $GLOBALS['blog_id'], 'who' => '', 'include_selected' => false 
    981982        ); 
    982983 
    983984        $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; 
     
    10071008                        $output .= "\t<option value='-1'$_selected>$show_option_none</option>\n"; 
    10081009                } 
    10091010 
     1011                $found_selected = false; 
    10101012                foreach ( (array) $users as $user ) { 
    10111013                        $user->ID = (int) $user->ID; 
    10121014                        $_selected = selected( $user->ID, $selected, false ); 
     1015                        if ( $_selected ) 
     1016                                $found_selected = true; 
    10131017                        $display = !empty($user->$show) ? $user->$show : '('. $user->user_login . ')'; 
    10141018                        $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n"; 
    10151019                } 
    10161020 
     1021                if ( $include_selected && ! $found_selected && ( $selected > 0 ) ) { 
     1022                        $user = get_userdata( $selected ); 
     1023                        $_selected = selected( $user->ID, $selected, false ); 
     1024                        $display = !empty($user->$show) ? $user->$show : '('. $user->user_login . ')'; 
     1025                        $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n"; 
     1026                } 
     1027 
    10171028                $output .= "</select>"; 
    10181029        } 
    10191030 
  • wp-admin/includes/meta-boxes.php

     
    530530        wp_dropdown_users( array( 
    531531                'who' => 'authors', 
    532532                'name' => 'post_author_override', 
    533                 'selected' => empty($post->ID) ? $user_ID : $post->post_author 
     533                'selected' => empty($post->ID) ? $user_ID : $post->post_author, 
     534                'include_selected' => true 
    534535        ) ); 
    535536} 
    536537