Make WordPress Core


Ignore:
Timestamp:
10/21/2018 03:02:49 PM (6 years ago)
Author:
danielbachhuber
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.

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-login.php

    r43458 r43776  
    438438    setcookie( TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure );
    439439
    440 $lang            = ! empty( $_GET['wp_lang'] ) ? sanitize_text_field( $_GET['wp_lang'] ) : '';
    441 $switched_locale = switch_to_locale( $lang );
    442 
    443440/**
    444441 * Fires when the login form is initialized.
     
    501498    setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );
    502499
    503     if ( $switched_locale ) {
    504         restore_previous_locale();
    505     }
    506 
    507500    wp_safe_redirect( wp_get_referer() );
    508501    exit();
     
    520513        $redirect_to = 'wp-login.php?loggedout=true';
    521514        $requested_redirect_to = '';
    522     }
    523 
    524     if ( $switched_locale ) {
    525         restore_previous_locale();
    526515    }
    527516
     
    618607<?php
    619608login_footer('user_login');
    620 
    621 if ( $switched_locale ) {
    622     restore_previous_locale();
    623 }
    624609
    625610break;
     
    748733login_footer('user_pass');
    749734
    750 if ( $switched_locale ) {
    751     restore_previous_locale();
    752 }
    753 
    754735break;
    755736
     
    834815<?php
    835816login_footer('user_login');
    836 
    837 if ( $switched_locale ) {
    838     restore_previous_locale();
    839 }
    840817
    841818break;
     
    11201097login_footer();
    11211098
    1122 if ( $switched_locale ) {
    1123     restore_previous_locale();
    1124 }
    1125 
    11261099break;
    11271100} // end action switch
Note: See TracChangeset for help on using the changeset viewer.