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-login.php

    r44021 r44134  
    465465}
    466466
    467 $lang            = ! empty( $_GET['wp_lang'] ) ? sanitize_text_field( $_GET['wp_lang'] ) : '';
    468 $switched_locale = switch_to_locale( $lang );
    469 
    470467/**
    471468 * Fires when the login form is initialized.
    … …  
    528525                setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );
    529526
    530                 if ( $switched_locale ) {
    531                         restore_previous_locale();
    532                 }
    533 
    534527                wp_safe_redirect( wp_get_referer() );
    535528                exit();
    … …  
    547540                        $redirect_to           = 'wp-login.php?loggedout=true';
    548541                        $requested_redirect_to = '';
    549                 }
    550 
    551                 if ( $switched_locale ) {
    552                         restore_previous_locale();
    553542                }
    554543
    … …  
    649638                <?php
    650639                login_footer( 'user_login' );
    651 
    652                 if ( $switched_locale ) {
    653                         restore_previous_locale();
    654                 }
    655640
    656641                break;
    … …  
    781766                login_footer( 'user_pass' );
    782767
    783                 if ( $switched_locale ) {
    784                         restore_previous_locale();
    785                 }
    786 
    787768                break;
    788769
    … …  
    867848                <?php
    868849                login_footer( 'user_login' );
    869 
    870                 if ( $switched_locale ) {
    871                         restore_previous_locale();
    872                 }
    873850
    874851                break;
    … …  
    11801157                login_footer();
    11811158
    1182                 if ( $switched_locale ) {
    1183                         restore_previous_locale();
    1184                 }
    1185 
    11861159                break;
    11871160} // End action switch.
Note: See TracChangeset for help on using the changeset viewer.