REST API: Add locale to user resource.

Props ocean90, joehoyle.
Fixes #38528.


git-svn-id: https://develop.svn.wordpress.org/trunk@39090 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan McCue
2016-11-02 06:23:12 +00:00
parent df13f01ad0
commit f9230a1c4d
2 changed files with 32 additions and 1 deletions
@@ -696,6 +696,10 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
$data['link'] = get_author_posts_url( $user->ID, $user->user_nicename );
}
if ( ! empty( $schema['properties']['locale'] ) ) {
$data['locale'] = get_user_locale( $user );
}
if ( ! empty( $schema['properties']['nickname'] ) ) {
$data['nickname'] = $user->nickname;
}
@@ -833,6 +837,10 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
$prepared_user->user_url = $request['url'];
}
if ( isset( $request['locale'] ) && ! empty( $schema['properties']['locale'] ) ) {
$prepared_user->locale = $request['locale'];
}
// setting roles will be handled outside of this function.
if ( isset( $request['roles'] ) ) {
$prepared_user->role = false;
@@ -978,6 +986,12 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
'context' => array( 'embed', 'view', 'edit' ),
'readonly' => true,
),
'locale' => array(
'description' => __( 'Locale for the resource.' ),
'type' => 'string',
'enum' => get_available_languages(),
'context' => array( 'edit' ),
),
'nickname' => array(
'description' => __( 'The nickname for the resource.' ),
'type' => 'string',