Ticket #38528: 38528.patch
File 38528.patch, 3.0 KB (added by , 7 years ago) |
---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
596 596 $data['link'] = get_author_posts_url( $user->ID, $user->user_nicename ); 597 597 } 598 598 599 if ( ! empty( $schema['properties']['locale'] ) ) { 600 $data['locale'] = get_user_locale( $user ); 601 } 602 599 603 if ( ! empty( $schema['properties']['nickname'] ) ) { 600 604 $data['nickname'] = $user->nickname; 601 605 } … … 847 851 'context' => array( 'embed', 'view', 'edit' ), 848 852 'readonly' => true, 849 853 ), 854 'locale' => array( 855 'description' => __( 'Locale for the resource.' ), 856 'type' => 'string', 857 'context' => array( 'edit' ), 858 'arg_options' => array( 859 'sanitize_callback' => array( $this, 'sanitize_locale' ), 860 ), 861 ), 850 862 'nickname' => array( 851 863 'description' => __( 'The nickname for the resource.' ), 852 864 'type' => 'string', … … 987 999 ); 988 1000 return $query_params; 989 1001 } 1002 1003 /** 1004 * Sanitizes the locale value. 1005 * 1006 * @since 4.7.0 1007 * 1008 * @param string $locale Locale value passed in request. 1009 * @return string Sanitized value for the locale. 1010 */ 1011 public function sanitize_locale( $locale ) { 1012 $locale = sanitize_text_field( $locale ); 1013 if ( ! in_array( $locale, get_available_languages(), true ) ) { 1014 $locale = ''; 1015 } 1016 1017 return ( '' === $locale ) ? 'en_US' : $locale; 1018 } 990 1019 } -
tests/phpunit/tests/rest-api/rest-users-controller.php
1116 1116 $data = $response->get_data(); 1117 1117 $properties = $data['schema']['properties']; 1118 1118 1119 $this->assertEquals( 1 8, count( $properties ) );1119 $this->assertEquals( 19, count( $properties ) ); 1120 1120 $this->assertArrayHasKey( 'avatar_urls', $properties ); 1121 1121 $this->assertArrayHasKey( 'capabilities', $properties ); 1122 1122 $this->assertArrayHasKey( 'description', $properties ); … … 1126 1126 $this->assertArrayHasKey( 'id', $properties ); 1127 1127 $this->assertArrayHasKey( 'last_name', $properties ); 1128 1128 $this->assertArrayHasKey( 'link', $properties ); 1129 $this->assertArrayHasKey( 'locale', $properties ); 1129 1130 $this->assertArrayHasKey( 'meta', $properties ); 1130 1131 $this->assertArrayHasKey( 'name', $properties ); 1131 1132 $this->assertArrayHasKey( 'nickname', $properties ); … … 1261 1262 $this->assertEquals( $user->user_url, $data['url'] ); 1262 1263 $this->assertEquals( $user->description, $data['description'] ); 1263 1264 $this->assertEquals( get_author_posts_url( $user->ID ), $data['link'] ); 1265 $this->assertEquals( get_user_locale( $user ), $data['locale'] ); 1264 1266 $this->assertArrayHasKey( 'avatar_urls', $data ); 1265 1267 $this->assertEquals( $user->user_nicename, $data['slug'] ); 1266 1268