PluginProbe
Polylang / 3.8.10
Polylang v3.8.10
3.8.10 3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 All 234 releases
← All changes | src/frontend/choose-lang.php +14 -5 3.8.3 → 3.8.10 View file →
@@ -2,8 +2,10 @@
2 2 /**
3 3 * @package Polylang
4 4 */
5 5
6 +use WP_Syntex\Polylang\Model\Languages;
7 +
6 8 /**
7 9 * Base class to choose the language
8 10 *
9 11 * @since 1.2
@@ -59,15 +61,22 @@
59 61 *
60 62 * @return void
61 63 */
62 64 public function init() {
63 - if ( Polylang::is_ajax_on_front() || ! wp_using_themes() ) {
64 - $this->set_language( empty( $_REQUEST['lang'] ) ? $this->get_preferred_language() : $this->model->get_language( sanitize_key( $_REQUEST['lang'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification
65 + add_action( 'pre_comment_on_post', array( $this, 'pre_comment_on_post' ) ); // sets the language of comment.
66 + add_action( 'parse_query', array( $this, 'parse_main_query' ), 2 ); // sets the language in special cases.
67 + add_action( 'wp', array( $this, 'maybe_setcookie' ), 7 );
68 +
69 + if ( ! Polylang::is_ajax_on_front() && wp_using_themes() ) {
70 + return;
65 71 }
66 72
67 - add_action( 'pre_comment_on_post', array( $this, 'pre_comment_on_post' ) ); // sets the language of comment
68 - add_action( 'parse_query', array( $this, 'parse_main_query' ), 2 ); // sets the language in special cases
69 - add_action( 'wp', array( $this, 'maybe_setcookie' ), 7 );
73 + if ( isset( $_REQUEST['lang'] ) && is_string( $_REQUEST['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
74 + // Let's accept either WordPress locales or language codes.
75 + $lang = $this->model->languages->get( Languages::is_locale( $_REQUEST['lang'] ) ? $_REQUEST['lang'] : sanitize_key( $_REQUEST['lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
76 + }
77 +
78 + $this->set_language( empty( $lang ) ? $this->get_preferred_language() : $lang );
70 79 }
71 80
72 81 /**
73 82 * Sets the current language.