PluginProbe
Polylang / 2.3
Polylang v2.3
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 3.0.3 All 233 releases
← All changes | frontend/frontend.php +31 -32 2.82.3 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Frontend controller
8 5 * accessible as $polylang global object
@@ -7,22 +4,20 @@
7 4 * Frontend controller
8 5 * accessible as $polylang global object
9 6 *
10 7 * Properties:
11 - * options => inherited, reference to Polylang options array
12 - * model => inherited, reference to PLL_Model object
13 - * links_model => inherited, reference to PLL_Links_Model object
14 - * links => reference to PLL_Links object
15 - * static_pages => reference to PLL_Frontend_Static_Pages object
16 - * choose_lang => reference to PLL_Choose_Lang object
17 - * curlang => current language
18 - * filters => reference to PLL_Frontend_Filters object
19 - * filters_links => reference to PLL_Frontend_Filters_Links object
20 - * filters_search => reference to PLL_Frontend_Filters_Search object
21 - * posts => reference to PLL_CRUD_Posts object
22 - * terms => reference to PLL_CRUD_Terms object
23 - * nav_menu => reference to PLL_Frontend_Nav_Menu object
24 - * auto_translate => optional, reference to PLL_Auto_Translate object
8 + * options => inherited, reference to Polylang options array
9 + * model => inherited, reference to PLL_Model object
10 + * links_model => inherited, reference to PLL_Links_Model object
11 + * links => reference to PLL_Links object
12 + * static_pages => reference to PLL_Frontend_Static_Pages object
13 + * filters_links => inherited, reference to PLL_Frontend_Filters_Links object
14 + * choose_lang => reference to PLL_Choose_lang object
15 + * curlang => current language
16 + * filters => reference to PLL_Filters object
17 + * filters_search => reference to PLL_Frontend_Filters_Search object
18 + * nav_menu => reference to PLL_Frontend_Nav_Menu object
19 + * auto_translate => optional, reference to PLL_Auto_Translate object
25 20 *
26 21 * @since 1.2
27 22 */
28 23 class PLL_Frontend extends PLL_Base {
@@ -58,25 +53,29 @@
58 53 *
59 54 * @since 1.2
60 55 */
61 56 public function init() {
62 - parent::init();
63 -
64 57 $this->links = new PLL_Frontend_Links( $this );
65 58
66 - // Static front page and page for posts
67 - if ( 'page' === get_option( 'show_on_front' ) ) {
68 - $this->static_pages = new PLL_Frontend_Static_Pages( $this );
69 - }
59 + // Don't set any language for REST requests
60 + if ( 0 === strpos( str_replace( 'index.php', '', $_SERVER['REQUEST_URI'] ), '/' . rest_get_url_prefix() . '/' ) ) {
61 + /** This action is documented in include/class-polylang.php */
62 + do_action( 'pll_no_language_defined' );
63 + } else {
64 + // Static front page and page for posts
65 + if ( 'page' === get_option( 'show_on_front' ) ) {
66 + $this->static_pages = new PLL_Frontend_Static_Pages( $this );
67 + }
70 68
71 - // Setup the language chooser
72 - $c = array( 'Content', 'Url', 'Url', 'Domain' );
73 - $class = 'PLL_Choose_Lang_' . $c[ $this->options['force_lang'] ];
74 - $this->choose_lang = new $class( $this );
75 - $this->choose_lang->init();
69 + // Setup the language chooser
70 + $c = array( 'Content', 'Url', 'Url', 'Domain' );
71 + $class = 'PLL_Choose_Lang_' . $c[ $this->options['force_lang'] ];
72 + $this->choose_lang = new $class( $this );
73 + $this->choose_lang->init();
76 74
77 - // Need to load nav menu class early to correctly define the locations in the customizer when the language is set from the content
78 - $this->nav_menu = new PLL_Frontend_Nav_Menu( $this );
75 + // Need to load nav menu class early to correctly define the locations in the customizer when the language is set from the content
76 + $this->nav_menu = new PLL_Frontend_Nav_Menu( $this );
77 + }
79 78 }
80 79
81 80 /**
82 81 * Setups filters and nav menus once the language has been defined
@@ -111,9 +110,9 @@
111 110 }
112 111 }
113 112
114 113 /**
115 - * Modifies some query vars to "hide" that the language is a taxonomy and avoid conflicts
114 + * mMdifies some query vars to "hide" that the language is a taxonomy and avoid conflicts
116 115 *
117 116 * @since 1.2
118 117 *
119 118 * @param object $query WP_Query object
@@ -134,9 +133,9 @@
134 133 $taxonomies = array_diff( $taxonomies, array( 'language', 'category', 'post_tag' ) );
135 134
136 135 // Remove pages query when the language is set unless we do a search
137 136 // Take care not to break the single page, attachment and taxonomies queries!
138 - if ( empty( $qv['post_type'] ) && ! $query->is_search && ! $query->is_singular && empty( $taxonomies ) && ! $query->is_category && ! $query->is_tag ) {
137 + if ( empty( $qv['post_type'] ) && ! $query->is_search && ! $query->is_page && ! $query->is_attachment && empty( $taxonomies ) ) {
139 138 $query->set( 'post_type', 'post' );
140 139 }
141 140
142 141 // Unset the is_archive flag for language pages to prevent loading the archive template