nguage // Test to avoid crash if get_home_url returns something wrong // FIXME why this happens? http://wordpress.org/support/topic/polylang-crashes-1 // Don't redirect if $_POST is not empty as it could break other plugins elseif ( is_string( $redirect = $this->curlang->get_home_url() ) && empty( $_POST ) ) { // phpcs:ignore WordPress.Security.NonceVerification // Don't forget the query string which may be added by plugins $query_string = wp_parse_url( pll_get_requested_url(), PHP_URL_QUERY ); if ( ! empty( $query_string ) ) { $redirect .= ( $this->links_model->using_permalinks ? '?' : '&' ) . $query_string; } /** * When a visitor reaches the site home, Polylang redirects to the home page in the correct language. * This filter allows plugins to modify the redirected url or prevent this redirection * /!\ this filter may be fired *before* the theme is loaded * * @since 1.1.1 * * @param string $redirect the url the visitor will be redirected to */ $redirect = apply_filters( 'pll_redirect_home', $redirect ); if ( $redirect && wp_validate_redirect( $redirect ) ) { $this->maybe_setcookie(); header( 'Vary: Accept-Language' ); wp_safe_redirect( $redirect, 302, POLYLANG ); exit; } } } /** * Set the language when posting a comment * * @since 0.8.4 * * @param int $post_id the post being commented * @return void */ public function pre_comment_on_post( $post_id ) { $this->set_language( $this->model->post->get_language( $post_id ) ); } /** * Modifies some main query vars for the home page and the page for posts * to enable one home page (and one page for posts) per language. * * @since 1.2 * * @param WP_Query $query Instance of WP_Query. * @return void */ public function parse_main_query( $query ) { if ( ! $query->is_main_query() ) { return; } /** * This filter allows to set the language based on information contained in the main query * * @since 1.8 * * @param PLL_Language|false $lang Language object or false. * @param WP_Query $query WP_Query object. */ if ( $lang = apply_filters( 'pll_set_language_from_query', false, $query ) ) { $this->set_language( $lang ); $this->set_curlang_in_query( $query ); } elseif ( ( count( $query->query ) == 1 || ( is_paged() && count( $query->query ) == 2 ) ) && $lang = get_query_var( 'lang' ) ) { $lang = $this->model->get_language( $lang ); $this->set_language( $lang ); // Set the language now otherwise it will be too late to filter sticky posts! // Set is_home on translated home page when it displays posts. It must be true on page 2, 3... too. $query->is_home = true; $query->is_tax = false; $query->is_archive = false; // Filters is_front_page() in case a static front page is not translated in this language. add_filter( 'option_show_on_front', array( $this, 'filter_option_show_on_front' ) ); } } /** * Filters the option show_on_front when the current front page displays posts. * * This is useful when a static front page is not translated in all languages. * * @return string */ public function filter_option_show_on_front() { return 'posts'; } /** * Sets the current language in the query. * * @since 2.2 * * @param WP_Query $query Instance of WP_Query. * @return void */ protected function set_curlang_in_query( &$query ) { if ( ! empty( $this->curlang ) ) { $pll_query = new PLL_Query( $query, $this->model ); $pll_query->set_language( $this->curlang ); } } }