Changeset 14012 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/locale.php
- Timestamp:
- 09/01/2024 11:46:40 PM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-learn/inc/locale.php
r13999 r14012 14 14 add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\register_assets' ); 15 15 add_filter( 'wporg_locale_switcher_options', __NAMESPACE__ . '\locale_switcher_options' ); 16 add_filter( 'wp_headers', __NAMESPACE__ . '\disable_caching' );17 16 add_filter( 'posts_clauses', __NAMESPACE__ . '\wporg_archive_query_prioritize_locale', 10, 2 ); 18 17 … … 130 129 131 130 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 is138 * chosen. This causes problems when, e.g. a user visits the page with their browser language set to de_DE, which gets139 * cached by nginx, and then another user visits with their browser set to en_US, and they are served the page in140 * 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 turning143 * 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 value146 * 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 $headers150 *151 * @return array152 */153 function disable_caching( $headers ) {154 if ( class_exists( '\WordPressdotorg\LocaleDetection\Detector' ) ) {155 $headers['Cache-Control'] = 'no-cache';156 }157 158 return $headers;159 131 } 160 132
Note: See TracChangeset
for help on using the changeset viewer.