PluginProbe
Polylang / 3.3
Polylang v3.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 +109 -33 2.83.3 View file →
@@ -3,39 +3,73 @@
3 3 * @package Polylang
4 4 */
5 5
6 6 /**
7 - * Frontend controller
8 - * accessible as $polylang global object
7 + * Main Polylang class when on frontend, accessible from @see PLL().
9 8 *
10 - * 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
25 - *
26 9 * @since 1.2
27 10 */
28 11 class PLL_Frontend extends PLL_Base {
12 + /**
13 + * Current language.
14 + *
15 + * @var PLL_Language|null
16 + */
29 17 public $curlang;
30 - public $links, $choose_lang, $filters, $filters_search, $nav_menu, $auto_translate;
31 18
32 19 /**
33 - * Constructor
20 + * @var PLL_Frontend_Auto_Translate|null
21 + */
22 + public $auto_translate;
23 +
24 + /**
25 + * The class selecting the current language.
34 26 *
27 + * @var PLL_Choose_Lang|null
28 + */
29 + public $choose_lang;
30 +
31 + /**
32 + * @var PLL_Frontend_Filters|null
33 + */
34 + public $filters;
35 +
36 + /**
37 + * @var PLL_Frontend_Filters_Links|null
38 + */
39 + public $filters_links;
40 +
41 + /**
42 + * @var PLL_Frontend_Filters_Search|null
43 + */
44 + public $filters_search;
45 +
46 + /**
47 + * @var PLL_Frontend_Links|null
48 + */
49 + public $links;
50 +
51 + /**
52 + * @var PLL_Frontend_Nav_Menu|null
53 + */
54 + public $nav_menu;
55 +
56 + /**
57 + * @var PLL_Frontend_Static_Pages|null
58 + */
59 + public $static_pages;
60 +
61 + /**
62 + * @var PLL_Frontend_Filters_Widgets|null
63 + */
64 + public $filters_widgets;
65 +
66 + /**
67 + * Constructor.
68 + *
35 69 * @since 1.2
36 70 *
37 - * @param object $links_model
71 + * @param PLL_Links_Model $links_model Reference to the links model.
38 72 */
39 73 public function __construct( &$links_model ) {
40 74 parent::__construct( $links_model );
41 75
@@ -50,8 +84,10 @@
50 84 // Not before 'check_canonical_url'
51 85 if ( ! defined( 'PLL_AUTO_TRANSLATE' ) || PLL_AUTO_TRANSLATE ) {
52 86 add_action( 'template_redirect', array( $this, 'auto_translate' ), 7 );
53 87 }
88 +
89 + add_action( 'admin_bar_menu', array( $this, 'remove_customize_admin_bar' ), 41 ); // After WP_Admin_Bar::add_menus
54 90 }
55 91
56 92 /**
57 93 * Setups the language chooser based on options
@@ -81,8 +117,10 @@
81 117 /**
82 118 * Setups filters and nav menus once the language has been defined
83 119 *
84 120 * @since 1.2
121 + *
122 + * @return void
85 123 */
86 124 public function pll_language_defined() {
87 125 // Filters
88 126 $this->filters_links = new PLL_Frontend_Filters_Links( $this );
@@ -87,9 +125,18 @@
87 125 // Filters
88 126 $this->filters_links = new PLL_Frontend_Filters_Links( $this );
89 127 $this->filters = new PLL_Frontend_Filters( $this );
90 128 $this->filters_search = new PLL_Frontend_Filters_Search( $this );
129 + $this->filters_widgets = new PLL_Frontend_Filters_Widgets( $this );
91 130
131 + /*
132 + * Redirects to canonical url before WordPress redirect_canonical
133 + * but after Nextgen Gallery which hacks $_SERVER['REQUEST_URI'] !!!
134 + * and restores it in 'template_redirect' with priority 1.
135 + */
136 + $this->canonical = new PLL_Canonical( $this );
137 + add_action( 'template_redirect', array( $this->canonical, 'check_canonical_url' ), 4 );
138 +
92 139 // Auto translate for Ajax
93 140 if ( ( ! defined( 'PLL_AUTO_TRANSLATE' ) || PLL_AUTO_TRANSLATE ) && wp_doing_ajax() ) {
94 141 $this->auto_translate();
95 142 }
@@ -95,13 +142,14 @@
95 142 }
96 143 }
97 144
98 145 /**
99 - * When querying multiple taxonomies, makes sure that the language is not the queried object
146 + * When querying multiple taxonomies, makes sure that the language is not the queried object.
100 147 *
101 148 * @since 1.8
102 149 *
103 - * @param object $query WP_Query object
150 + * @param WP_Query $query WP_Query object.
151 + * @return void
104 152 */
105 153 public function parse_tax_query( $query ) {
106 154 $pll_query = new PLL_Query( $query, $this->model );
107 155 $queried_taxonomies = $pll_query->get_queried_taxonomies();
@@ -111,13 +159,14 @@
111 159 }
112 160 }
113 161
114 162 /**
115 - * Modifies some query vars to "hide" that the language is a taxonomy and avoid conflicts
163 + * Modifies some query vars to "hide" that the language is a taxonomy and avoid conflicts.
116 164 *
117 165 * @since 1.2
118 166 *
119 - * @param object $query WP_Query object
167 + * @param WP_Query $query WP_Query object.
168 + * @return void
120 169 */
121 170 public function parse_query( $query ) {
122 171 $qv = $query->query_vars;
123 172 $pll_query = new PLL_Query( $query, $this->model );
@@ -156,8 +205,10 @@
156 205 /**
157 206 * Auto translate posts and terms ids
158 207 *
159 208 * @since 1.2
209 + *
210 + * @return void
160 211 */
161 212 public function auto_translate() {
162 213 $this->auto_translate = new PLL_Frontend_Auto_Translate( $this );
163 214 }
@@ -162,22 +213,25 @@
162 213 $this->auto_translate = new PLL_Frontend_Auto_Translate( $this );
163 214 }
164 215
165 216 /**
166 - * Resets some variables when switching blog
167 - * Overrides parent method
217 + * Resets some variables when the blog is switched.
218 + * Overrides the parent method.
168 219 *
169 220 * @since 1.5.1
170 221 *
171 - * @param int $new_blog
172 - * @param int $old_blog
222 + * @param int $new_blog_id New blog ID.
223 + * @param int $prev_blog_id Previous blog ID.
224 + * @return void
173 225 */
174 - public function switch_blog( $new_blog, $old_blog ) {
175 - // Need to check that some languages are defined when user is logged in, has several blogs, some without any languages
176 - if ( parent::switch_blog( $new_blog, $old_blog ) && did_action( 'pll_language_defined' ) && $this->model->get_languages_list() ) {
226 + public function switch_blog( $new_blog_id, $prev_blog_id ) {
227 + parent::switch_blog( $new_blog_id, $prev_blog_id );
228 +
229 + // Need to check that some languages are defined when user is logged in, has several blogs, some without any languages.
230 + if ( $this->is_active_on_new_blog( $new_blog_id, $prev_blog_id ) && did_action( 'pll_language_defined' ) && $this->model->get_languages_list() ) {
177 231 static $restore_curlang;
178 232 if ( empty( $restore_curlang ) ) {
179 - $restore_curlang = $this->curlang->slug; // To always remember the current language through blogs
233 + $restore_curlang = $this->curlang->slug; // To always remember the current language through blogs.
180 234 }
181 235
182 236 $lang = $this->model->get_language( $restore_curlang );
183 237 $this->curlang = $lang ? $lang : $this->model->get_language( $this->options['default_lang'] );
@@ -187,6 +241,28 @@
187 241 }
188 242
189 243 $this->load_strings_translations();
190 244 }
245 + }
246 +
247 + /**
248 + * Remove the customize admin bar on front-end when using a block theme.
249 + *
250 + * WordPress removes the Customizer menu if a block theme is activated and no other plugins interact with it.
251 + * As Polylang interacts with the Customizer, we have to delete this menu ourselves in the case of a block theme,
252 + * unless another plugin than Polylang interacts with the Customizer.
253 + *
254 + * @since 3.2
255 + *
256 + * @return void
257 + */
258 + public function remove_customize_admin_bar() {
259 + if ( ! $this->should_customize_menu_be_removed() ) {
260 + return;
261 + }
262 +
263 + global $wp_admin_bar;
264 +
265 + remove_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' ); // To avoid the script launch.
266 + $wp_admin_bar->remove_menu( 'customize' );
191 267 }
192 268 }