PluginProbe
Polylang / 3.6.7
Polylang v3.6.7
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 | include/base.php +67 -18 3.0.23.6.7 View file →
@@ -7,8 +7,9 @@
7 7 * Base class for both admin and frontend
8 8 *
9 9 * @since 1.2
10 10 */
11 +#[AllowDynamicProperties]
11 12 abstract class PLL_Base {
12 13 /**
13 14 * Stores the plugin options.
14 15 *
@@ -30,9 +31,9 @@
30 31
31 32 /**
32 33 * Registers hooks on insert / update post related actions and filters.
33 34 *
34 - * @var PLL_CRUD_Posts
35 + * @var PLL_CRUD_Posts|null
35 36 */
36 37 public $posts;
37 38
38 39 /**
@@ -37,9 +38,9 @@
37 38
38 39 /**
39 40 * Registers hooks on insert / update term related action and filters.
40 41 *
41 - * @var PLL_CRUD_Terms
42 + * @var PLL_CRUD_Terms|null
42 43 */
43 44 public $terms;
44 45
45 46 /**
@@ -61,9 +62,9 @@
61 62 // User defined strings translations
62 63 add_action( 'pll_language_defined', array( $this, 'load_strings_translations' ), 5 );
63 64 add_action( 'change_locale', array( $this, 'load_strings_translations' ) ); // Since WP 4.7
64 65 add_action( 'personal_options_update', array( $this, 'load_strings_translations' ), 1, 0 ); // Before WP, for confirmation request when changing the user email.
65 -
66 + add_action( 'lostpassword_post', array( $this, 'load_strings_translations' ), 10, 0 ); // Password reset email.
66 67 // Switch_to_blog
67 68 add_action( 'switch_blog', array( $this, 'switch_blog' ), 10, 2 );
68 69 }
69 70
@@ -75,9 +76,9 @@
75 76 *
76 77 * @return void
77 78 */
78 79 public function init() {
79 - if ( $this->model->get_languages_list() ) {
80 + if ( $this->model->has_languages() ) {
80 81 $this->posts = new PLL_CRUD_Posts( $this );
81 82 $this->terms = new PLL_CRUD_Terms( $this );
82 83
83 84 // WordPress options.
@@ -110,9 +111,9 @@
110 111 *
111 112 * @since 1.2
112 113 * @since 2.1.3 $locale parameter added.
113 114 *
114 - * @param string $locale Locale. Defaults to current locale.
115 + * @param string $locale Language locale or slug. Defaults to current locale.
115 116 * @return void
116 117 */
117 118 public function load_strings_translations( $locale = '' ) {
118 119 if ( empty( $locale ) ) {
@@ -140,31 +141,79 @@
140 141 * @param int $prev_blog_id Previous blog ID.
141 142 * @return void
142 143 */
143 144 public function switch_blog( $new_blog_id, $prev_blog_id ) {
144 - if ( $this->is_active_on_new_blog( $new_blog_id, $prev_blog_id ) ) {
145 - $this->options = get_option( 'polylang' ); // Needed for menus.
146 - remove_action( 'pre_option_rewrite_rules', array( $this->links_model, 'prepare_rewrite_rules' ) );
145 + if ( (int) $new_blog_id === (int) $prev_blog_id ) {
146 + // Do nothing if same blog.
147 + return;
148 + }
149 +
150 + $this->links_model->remove_filters();
151 +
152 + if ( $this->is_active_on_current_site() ) {
153 + $this->options = get_option( 'polylang' ); // Needed for menus.
147 154 $this->links_model = $this->model->get_links_model();
148 155 }
149 156 }
150 157
151 158 /**
152 - * Checks if Polylang is active on the new blog when the blog is switched.
159 + * Checks if Polylang is active on the current blog (useful when the blog is switched).
153 160 *
154 - * @since 3.0
161 + * @since 3.5.2
155 162 *
156 - * @param int $new_blog_id New blog ID.
157 - * @param int $prev_blog_id Previous blog ID.
158 163 * @return bool
159 164 */
160 - protected function is_active_on_new_blog( $new_blog_id, $prev_blog_id ) {
161 - $plugins = ( $sitewide_plugins = get_site_option( 'active_sitewide_plugins' ) ) && is_array( $sitewide_plugins ) ? array_keys( $sitewide_plugins ) : array();
162 - $plugins = array_merge( $plugins, get_option( 'active_plugins', array() ) );
165 + protected function is_active_on_current_site(): bool {
166 + return pll_is_plugin_active( POLYLANG_BASENAME ) && get_option( 'polylang' );
167 + }
163 168
169 + /**
170 + * Check if the customize menu should be removed or not.
171 + *
172 + * @since 3.2
173 + *
174 + * @return bool True if it should be removed, false otherwise.
175 + */
176 + public function should_customize_menu_be_removed() {
177 + // Exit if a block theme isn't activated.
178 + if ( ! function_exists( 'wp_is_block_theme' ) || ! wp_is_block_theme() ) {
179 + return false;
180 + }
181 +
182 + return ! $this->is_customize_register_hooked();
183 + }
184 +
185 + /**
186 + * Tells whether or not Polylang or third party callbacks are hooked to `customize_register`.
187 + *
188 + * @since 3.4.3
189 + *
190 + * @global $wp_filter
191 + *
192 + * @return bool True if Polylang's callbacks are hooked, false otherwise.
193 + */
194 + protected function is_customize_register_hooked() {
195 + global $wp_filter;
196 +
197 + if ( empty( $wp_filter['customize_register'] ) || ! $wp_filter['customize_register'] instanceof WP_Hook ) {
198 + return false;
199 + }
200 +
164 201 /*
165 - * The 2nd test is needed when Polylang is not networked activated.
166 - * The 3rd test is needed when Polylang is networked activated and a new site is created.
202 + * 'customize_register' is hooked by:
203 + * @see PLL_Nav_Menu::create_nav_menu_locations()
204 + * @see PLL_Frontend_Static_Pages::filter_customizer()
167 205 */
168 - return $new_blog_id !== $prev_blog_id && in_array( POLYLANG_BASENAME, $plugins ) && get_option( 'polylang' );
206 + $floor = 0;
207 + if ( ! empty( $this->nav_menu ) && (bool) $wp_filter['customize_register']->has_filter( 'customize_register', array( $this->nav_menu, 'create_nav_menu_locations' ) ) ) {
208 + ++$floor;
209 + }
210 +
211 + if ( ! empty( $this->static_pages ) && (bool) $wp_filter['customize_register']->has_filter( 'customize_register', array( $this->static_pages, 'filter_customizer' ) ) ) {
212 + ++$floor;
213 + }
214 +
215 + $count = array_sum( array_map( 'count', $wp_filter['customize_register']->callbacks ) );
216 +
217 + return $count > $floor;
169 218 }
170 219 }