Ticket #31251: 31251.patch
File 31251.patch, 6.2 KB (added by , 10 years ago) |
---|
-
src/wp-includes/user.php
1355 1355 * The available arguments are as follows: 1356 1356 * 1357 1357 * @since 2.3.0 1358 * @since 4.2.0 The default value for $show was changed to empty 1358 1359 * 1359 1360 * @global wpdb $wpdb WordPress database object for queries. 1360 1361 * … … 1382 1383 * @type bool|int $multi Whether to skip the ID attribute on the 'select' element. 1383 1384 * Accepts 1|true or 0|false. Default 0|false. 1384 1385 * @type string $show User table column to display. If the selected item is empty 1385 * then the ' user_login' will be displayed in parentheses.1386 * Accepts user fields. Default 'display_name' .1386 * then the 'display_name' will be displayed with the 'user_login' in parenthesis. 1387 * Accepts user fields. Default 'display_name' with 'user_login' in parenthesis. 1387 1388 * @type int|bool $echo Whether to echo or return the drop-down. Accepts 1|true (echo) 1388 1389 * or 0|false (return). Default 1|true. 1389 1390 * @type int $selected Which user ID should be selected. Default 0. … … 1403 1404 'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '', 1404 1405 'orderby' => 'display_name', 'order' => 'ASC', 1405 1406 'include' => '', 'exclude' => '', 'multi' => 0, 1406 'show' => ' display_name', 'echo' => 1,1407 'show' => '', 'echo' => 1, 1407 1408 'selected' => 0, 'name' => 'user', 'class' => '', 'id' => '', 1408 1409 'blog_id' => $GLOBALS['blog_id'], 'who' => '', 'include_selected' => false, 1409 1410 'option_none_value' => -1 … … 1418 1419 $option_none_value = $r['option_none_value']; 1419 1420 1420 1421 $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) ); 1421 $query_args['fields'] = array( 'ID', 'user_login', $show);1422 $query_args['fields'] = array( 'ID', 'user_login', 'display_name' ); 1422 1423 $users = get_users( $query_args ); 1423 1424 1424 1425 $output = ''; … … 1447 1448 if ( $_selected ) { 1448 1449 $found_selected = true; 1449 1450 } 1450 $display = ! empty( $user->$show ) ? $user->$show : '('. $user->user_login . ')';1451 $display = ! empty( $user->$show ) ? $user->$show : $user->display_name . ' ('. $user->user_login . ')'; 1451 1452 $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; 1452 1453 } 1453 1454 1454 1455 if ( $r['include_selected'] && ! $found_selected && ( $r['selected'] > 0 ) ) { 1455 1456 $user = get_userdata( $r['selected'] ); 1456 1457 $_selected = selected( $user->ID, $r['selected'], false ); 1457 $display = ! empty( $user->$show ) ? $user->$show : '('. $user->user_login . ')';1458 $display = ! empty( $user->$show ) ? $user->$show : $user->display_name . ' ('. $user->user_login . ')'; 1458 1459 $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n"; 1459 1460 } 1460 1461 -
tests/phpunit/tests/user/wpDropdownUsers.php
1 <?php 2 3 /** 4 * Test functions in wp-includes/user.php 5 * 6 * @group user 7 */ 8 class Tests_User_WpDropdownUsers extends WP_UnitTestCase { 9 10 /** 11 * @ticket 31251 12 */ 13 public function test_show_should_display_display_name_and_user_in_parenthesis_when_show_is_not_specified() { 14 15 // create a user with a different display_name 16 $u = $this->factory->user->create( array( 17 'user_login' => 'foo', 18 'display_name' => 'Foo Person' 19 ) ); 20 21 // Get the result of a non-default, but acceptable input for 'show' parameter to wp_dropdown_users(). 22 $found = wp_dropdown_users( array( 23 'echo' => false 24 ) ); 25 26 $expected = "<option value='$u'>Foo Person (foo)</option>"; 27 28 $this->assertContains( $expected, $found ); 29 } 30 31 /** 32 * @ticket 31251 33 */ 34 public function test_show_should_display_display_name_and_user_in_parenthesis_when_show_is_specified_as_empty() { 35 36 // create a user with a different display_name 37 $u = $this->factory->user->create( array( 38 'user_login' => 'foo', 39 'display_name' => 'Foo Person' 40 ) ); 41 42 // Get the result of a non-default, but acceptable input for 'show' parameter to wp_dropdown_users(). 43 $found = wp_dropdown_users( array( 44 'echo' => false, 45 'show' => '' 46 ) ); 47 48 $expected = "<option value='$u'>Foo Person (foo)</option>"; 49 50 $this->assertContains( $expected, $found ); 51 } 52 53 /** 54 * @ticket 31251 55 */ 56 public function test_show_should_display_user_property_when_the_value_of_show_is_a_valid_user_property() { 57 58 // create a user with a different display_name 59 $u = $this->factory->user->create( array( 60 'user_login' => 'foo', 61 'display_name' => 'Foo Person' 62 ) ); 63 64 // Get the result of a non-default, but acceptable input for 'show' parameter to wp_dropdown_users(). 65 $found = wp_dropdown_users( array( 66 'echo' => false, 67 'show' => 'user_login' 68 ) ); 69 70 $expected = "<option value='$u'>foo</option>"; 71 72 $this->assertContains( $expected, $found ); 73 } 74 75 /** 76 * @ticket 31251 77 */ 78 public function test_show_should_display_display_name_and_user_in_parenthesis_when_show_an_invalid_user_property() { 79 80 // create a user with a different display_name 81 $u = $this->factory->user->create( array( 82 'user_login' => 'foo', 83 'display_name' => 'Foo Person' 84 ) ); 85 86 // Get the result of a non-default, but acceptable input for 'show' parameter to wp_dropdown_users(). 87 $found = wp_dropdown_users( array( 88 'echo' => false, 89 'show' => 'foobar' 90 ) ); 91 92 $expected = "<option value='$u'>Foo Person (foo)</option>"; 93 94 $this->assertContains( $expected, $found ); 95 } 96 97 } 98 No newline at end of file