Making WordPress.org


Ignore:
Timestamp:
09/01/2024 11:46:40 PM (17 months ago)
Author:
adamwood
Message:

Learn: Sync with git WordPress/learn@daa4713

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/locale.php

    r13999 r14012  
    1414add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\register_assets' );
    1515add_filter( 'wporg_locale_switcher_options', __NAMESPACE__ . '\locale_switcher_options' );
    16 add_filter( 'wp_headers', __NAMESPACE__ . '\disable_caching' );
    1716add_filter( 'posts_clauses', __NAMESPACE__ . '\wporg_archive_query_prioritize_locale', 10, 2 );
    1817
     
    130129
    131130    return $options;
    132 }
    133 
    134 /**
    135  * Disable nginx caching when locale switching is available.
    136  *
    137  * The nginx cache currently doesn't vary on the value of the cookie that gets set when a locale other than en_US is
    138  * chosen. This causes problems when, e.g. a user visits the page with their browser language set to de_DE, which gets
    139  * cached by nginx, and then another user visits with their browser set to en_US, and they are served the page in
    140  * German regardless of they choose something else in the locale switcher.
    141  *
    142  * nginx does respect the Cache-Control header, though, so this offers a quick, hacky fix to the problem by turning
    143  * off caching altogether.
    144  *
    145  * This should be removed if a way is found to vary the cache by the cookie value, e.g. to include the cookie value
    146  * in the cache key as suggested in the discussion of this systems request:
    147  * https://make.wordpress.org/systems/2021/03/26/vary-nginx-cache-by-wporg_locale-cookie-value/
    148  *
    149  * @param array $headers
    150  *
    151  * @return array
    152  */
    153 function disable_caching( $headers ) {
    154     if ( class_exists( '\WordPressdotorg\LocaleDetection\Detector' ) ) {
    155         $headers['Cache-Control'] = 'no-cache';
    156     }
    157 
    158     return $headers;
    159131}
    160132
Note: See TracChangeset for help on using the changeset viewer.