From 8718ae12df607d2db613381be7ac6a9c6202f491 Mon Sep 17 00:00:00 2001 From: KAGG Design Date: Mon, 6 Sep 2021 10:38:58 +0300 Subject: [PATCH] Fix endless page loading with WPML. --- src/php/class-main.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/php/class-main.php b/src/php/class-main.php index a36d789..4808ab1 100644 --- a/src/php/class-main.php +++ b/src/php/class-main.php @@ -167,6 +167,8 @@ public function init_hooks() { } if ( class_exists( SitePress::class ) ) { + $this->wpml_locale = $this->get_wpml_locale(); + // We cannot use locale filter here // as WPML reverts locale at PHP_INT_MAX in \WPML\ST\MO\Hooks\LanguageSwitch::filterLocale. add_filter( 'ctl_locale', [ $this, 'wpml_locale_filter' ], - PHP_INT_MAX ); @@ -609,16 +611,19 @@ public function wpml_locale_filter( $locale ) { return $this->wpml_locale; } + return $locale; + } + + /** + * Get wpml locale. + * + * @return string|null + */ + private function get_wpml_locale() { $language_code = wpml_get_current_language(); $languages = apply_filters( 'wpml_active_languages', null ); - if ( isset( $languages[ $language_code ] ) ) { - $this->wpml_locale = $languages[ $language_code ]['default_locale']; - - return $this->wpml_locale; - } - - return $locale; + return isset( $languages[ $language_code ] ) ? $languages[ $language_code ]['default_locale'] : null; } /**