PluginProbe
Polylang / 3.6.7
Polylang v3.6.7
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 | frontend/frontend.php +82 -25 3.0.1 → 3.6.7 View file →
@@ -11,14 +11,14 @@
11 11 class PLL_Frontend extends PLL_Base {
12 12 /**
13 13 * Current language.
14 14 *
15 - * @var PLL_Language
15 + * @var PLL_Language|null
16 16 */
17 17 public $curlang;
18 18
19 19 /**
20 - * @var PLL_Frontend_Auto_Translate
20 + * @var PLL_Frontend_Auto_Translate|null
21 21 */
22 22 public $auto_translate;
23 23
24 24 /**
@@ -23,43 +23,48 @@
23 23
24 24 /**
25 25 * The class selecting the current language.
26 26 *
27 - * @var PLL_Choose_Lang
27 + * @var PLL_Choose_Lang|null
28 28 */
29 29 public $choose_lang;
30 30
31 31 /**
32 - * @var PLL_Frontend_Filters
32 + * @var PLL_Frontend_Filters|null
33 33 */
34 34 public $filters;
35 35
36 36 /**
37 - * @var PLL_Frontend_Filters_Links
37 + * @var PLL_Frontend_Filters_Links|null
38 38 */
39 39 public $filters_links;
40 40
41 41 /**
42 - * @var PLL_Frontend_Filters_Search
42 + * @var PLL_Frontend_Filters_Search|null
43 43 */
44 44 public $filters_search;
45 45
46 46 /**
47 - * @var PLL_Frontend_Links
47 + * @var PLL_Frontend_Links|null
48 48 */
49 49 public $links;
50 50
51 51 /**
52 - * @var PLL_Frontend_Nav_Menu
52 + * @var PLL_Frontend_Nav_Menu|null
53 53 */
54 54 public $nav_menu;
55 55
56 56 /**
57 - * @var PLL_Frontend_Static_Pages
57 + * @var PLL_Frontend_Static_Pages|null
58 58 */
59 59 public $static_pages;
60 60
61 61 /**
62 + * @var PLL_Frontend_Filters_Widgets|null
63 + */
64 + public $filters_widgets;
65 +
66 + /**
62 67 * Constructor.
63 68 *
64 69 * @since 1.2
65 70 *
@@ -79,8 +84,22 @@
79 84 // Not before 'check_canonical_url'
80 85 if ( ! defined( 'PLL_AUTO_TRANSLATE' ) || PLL_AUTO_TRANSLATE ) {
81 86 add_action( 'template_redirect', array( $this, 'auto_translate' ), 7 );
82 87 }
88 +
89 + add_action( 'admin_bar_menu', array( $this, 'remove_customize_admin_bar' ), 41 ); // After WP_Admin_Bar::add_menus
90 +
91 + /*
92 + * Static front page and page for posts.
93 + *
94 + * Early instantiated to be able to correctly initialize language properties.
95 + * Also loaded in customizer preview, directly reading the request as we act before WP.
96 + */
97 + if ( 'page' === get_option( 'show_on_front' ) || ( isset( $_REQUEST['wp_customize'] ) && 'on' === $_REQUEST['wp_customize'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
98 + $this->static_pages = new PLL_Frontend_Static_Pages( $this );
99 + }
100 +
101 + $this->model->set_languages_ready();
83 102 }
84 103
85 104 /**
86 105 * Setups the language chooser based on options
@@ -91,13 +110,8 @@
91 110 parent::init();
92 111
93 112 $this->links = new PLL_Frontend_Links( $this );
94 113
95 - // Static front page and page for posts
96 - if ( 'page' === get_option( 'show_on_front' ) ) {
97 - $this->static_pages = new PLL_Frontend_Static_Pages( $this );
98 - }
99 -
100 114 // Setup the language chooser
101 115 $c = array( 'Content', 'Url', 'Url', 'Domain' );
102 116 $class = 'PLL_Choose_Lang_' . $c[ $this->options['force_lang'] ];
103 117 $this->choose_lang = new $class( $this );
@@ -118,9 +132,18 @@
118 132 // Filters
119 133 $this->filters_links = new PLL_Frontend_Filters_Links( $this );
120 134 $this->filters = new PLL_Frontend_Filters( $this );
121 135 $this->filters_search = new PLL_Frontend_Filters_Search( $this );
136 + $this->filters_widgets = new PLL_Frontend_Filters_Widgets( $this );
122 137
138 + /*
139 + * Redirects to canonical url before WordPress redirect_canonical
140 + * but after Nextgen Gallery which hacks $_SERVER['REQUEST_URI'] !!!
141 + * and restores it in 'template_redirect' with priority 1.
142 + */
143 + $this->canonical = new PLL_Canonical( $this );
144 + add_action( 'template_redirect', array( $this->canonical, 'check_canonical_url' ), 4 );
145 +
123 146 // Auto translate for Ajax
124 147 if ( ( ! defined( 'PLL_AUTO_TRANSLATE' ) || PLL_AUTO_TRANSLATE ) && wp_doing_ajax() ) {
125 148 $this->auto_translate();
126 149 }
@@ -207,24 +230,58 @@
207 230 * @param int $prev_blog_id Previous blog ID.
208 231 * @return void
209 232 */
210 233 public function switch_blog( $new_blog_id, $prev_blog_id ) {
234 + if ( (int) $new_blog_id === (int) $prev_blog_id ) {
235 + // Do nothing if same blog.
236 + return;
237 + }
238 +
211 239 parent::switch_blog( $new_blog_id, $prev_blog_id );
212 240
213 241 // Need to check that some languages are defined when user is logged in, has several blogs, some without any languages.
214 - if ( $this->is_active_on_new_blog( $new_blog_id, $prev_blog_id ) && did_action( 'pll_language_defined' ) && $this->model->get_languages_list() ) {
215 - static $restore_curlang;
216 - if ( empty( $restore_curlang ) ) {
217 - $restore_curlang = $this->curlang->slug; // To always remember the current language through blogs.
218 - }
242 + if ( ! $this->is_active_on_current_site() || ! $this->model->has_languages() || ! did_action( 'pll_language_defined' ) ) {
243 + return;
244 + }
219 245
220 - $lang = $this->model->get_language( $restore_curlang );
221 - $this->curlang = $lang ? $lang : $this->model->get_language( $this->options['default_lang'] );
246 + static $restore_curlang;
222 247
223 - if ( isset( $this->static_pages ) ) {
224 - $this->static_pages->init();
225 - }
248 + if ( empty( $restore_curlang ) ) {
249 + $restore_curlang = $this->curlang->slug; // To always remember the current language through blogs.
250 + }
226 251
227 - $this->load_strings_translations();
252 + $lang = $this->model->get_language( $restore_curlang );
253 + $this->curlang = $lang ? $lang : $this->model->get_default_language();
254 + if ( empty( $this->curlang ) ) {
255 + return;
228 256 }
257 +
258 + if ( isset( $this->static_pages ) ) {
259 + $this->static_pages->init();
260 + }
261 +
262 + // Send the slug instead of the locale here to avoid conflicts with same locales.
263 + $this->load_strings_translations( $this->curlang->slug );
264 + }
265 +
266 + /**
267 + * Remove the customize admin bar on front-end when using a block theme.
268 + *
269 + * WordPress removes the Customizer menu if a block theme is activated and no other plugins interact with it.
270 + * As Polylang interacts with the Customizer, we have to delete this menu ourselves in the case of a block theme,
271 + * unless another plugin than Polylang interacts with the Customizer.
272 + *
273 + * @since 3.2
274 + *
275 + * @return void
276 + */
277 + public function remove_customize_admin_bar() {
278 + if ( ! $this->should_customize_menu_be_removed() ) {
279 + return;
280 + }
281 +
282 + global $wp_admin_bar;
283 +
284 + remove_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' ); // To avoid the script launch.
285 + $wp_admin_bar->remove_menu( 'customize' );
229 286 }
230 287 }