Making WordPress.org


Ignore:
Timestamp:
02/15/2018 11:01:34 AM (9 years ago)
Author:
obenland
Message:

Locale Detection: Let GET param override Cookie

Allows for switching locales based on context.

See #1673.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/locale-detection/class-detector.php

    r6640 r6644  
    4444                $this->active_locales = $this->get_active_locales();
    4545
    46                 if ( ! empty( $_COOKIE[ 'wporg_locale' ] ) ) {
     46                if ( ! empty( $_GET['locale'] ) ) {
     47                        $get_locale = $this->sanitize_locale( $_GET['locale'] );
     48
     49                        $this->locale = $this->check_variants( $get_locale ) ?: $this->locale;
     50                } elseif ( ! empty( $_COOKIE['wporg_locale'] ) ) {
    4751                        $locale = $this->sanitize_locale( $_COOKIE['wporg_locale'] );
    4852
    4953                        if ( in_array( $locale, $this->active_locales, true ) ) {
    5054                                $this->locale = $locale;
    51                                 return;
    5255                        }
    53                 }
    54 
    55                 if ( isset( $_GET['locale'] ) ) {
    56                         $get_locale = $this->sanitize_locale( $_GET['locale'] );
    57 
    58                         $this->locale = $this->check_variants( $get_locale ) ?: $this->locale;
    5956                } else {
    6057                        $this->locale = $this->guess_locale() ?: $this->locale;
     58                        setcookie( 'wporg_locale', $this->locale, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN, is_ssl() );
    6159                }
    62 
    63                 setcookie( 'wporg_locale', $this->locale, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN, is_ssl() );
    6460        }
    6561
Note: See TracChangeset for help on using the changeset viewer.