Skip to content

Commit

Permalink
Fix endless page loading with WPML.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Sep 6, 2021
1 parent 78a80fd commit 8718ae1
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/php/class-main.php
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 8718ae1

Please sign in to comment.