Make WordPress Core


Ignore:
Timestamp:
12/14/2018 01:31:27 AM (8 years ago)
Author:
jeremyfelt
Message:

REST API: Render response in user locale with ?_locale=user.

Introduces new determine_locale() function for deciding the proper locale to use for a response. Default value is get_user_locale() in the admin, and get_locale() on the frontend. Because REST API requests are considered frontend requests, ?_locale=user can be used to render the response in the user's locale.

Also updates wp-login.php?wp_lang implementation to benefit from this abstraction.

Merges [43776] from the 5.0 branch to trunk.

Props flixos90, mnelson4, swissspidy, TimothyBlynJacobs.
Fixes #44758.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/class-wp-locale-switcher.php

    r42395 r44134  
    4646         */
    4747        public function __construct() {
    48                 $this->original_locale     = is_admin() ? get_user_locale() : get_locale();
     48                $this->original_locale     = determine_locale();
    4949                $this->available_languages = array_merge( array( 'en_US' ), get_available_languages() );
    5050        }
     
    7070         */
    7171        public function switch_to_locale( $locale ) {
    72                 $current_locale = is_admin() ? get_user_locale() : get_locale();
     72                $current_locale = determine_locale();
    7373                if ( $current_locale === $locale ) {
    7474                        return false;
Note: See TracChangeset for help on using the changeset viewer.