PluginProbe
Polylang / 3.1.4
Polylang v3.1.4
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/olt-manager.php +45 -33 2.93.1.4 View file →
@@ -12,14 +12,37 @@
12 12 *
13 13 * @since 1.2
14 14 */
15 15 class PLL_OLT_Manager {
16 - protected static $instance; // For singleton
16 + /**
17 + * Singleton instance
18 + *
19 + * @var PLL_OLT_Manager
20 + */
21 + protected static $instance;
22 +
23 + /**
24 + * Stores the default site locale before it is modified.
25 + *
26 + * @var string
27 + */
17 28 protected $default_locale;
18 - protected $list_textdomains = array(); // All text domains
19 - public $labels = array(); // Post types and taxonomies labels to translate
20 29
21 30 /**
31 + * Stores all loaded text domains and mo files.
32 + *
33 + * @var string[][]
34 + */
35 + protected $list_textdomains = array();
36 +
37 + /**
38 + * Stores post types an taxonomies labels to translate.
39 + *
40 + * @var string[][]
41 + */
42 + public $labels = array();
43 +
44 + /**
22 45 * Constructor: setups relevant filters
23 46 *
24 47 * @since 1.2
25 48 */
@@ -27,11 +50,10 @@
27 50 // Allows Polylang to be the first plugin loaded ;-)
28 51 add_filter( 'pre_update_option_active_plugins', array( $this, 'make_polylang_first' ) );
29 52 add_filter( 'pre_update_option_active_sitewide_plugins', array( $this, 'make_polylang_first' ) );
30 53
31 - // Overriding load text domain only on front since WP 4.7
32 - // FIXME test get_user_locale for backward compatibility with WP < 4.7
33 - if ( is_admin() && ! Polylang::is_ajax_on_front() && function_exists( 'get_user_locale' ) ) {
54 + // Overriding load text domain only on front since WP 4.7.
55 + if ( is_admin() && ! Polylang::is_ajax_on_front() ) {
34 56 return;
35 57 }
36 58
37 59 // Saves the default locale before we start any language manipulation
@@ -65,8 +87,10 @@
65 87 /**
66 88 * Loads text domains
67 89 *
68 90 * @since 0.1
91 + *
92 + * @return void
69 93 */
70 94 public function load_textdomains() {
71 95 // Our load_textdomain_mofile filter has done its job. let's remove it before calling load_textdomain
72 96 remove_filter( 'load_textdomain_mofile', array( $this, 'load_textdomain_mofile' ), 10, 2 );
@@ -82,9 +106,9 @@
82 106 * From WP 4.7 to 5.5, we need to reset the internal cache of _get_path_to_translation when switching from any locale to en_US.
83 107 * See WP_Locale_Switcher::change_locale()
84 108 */
85 109 if ( ! class_exists( 'WP_Textdomain_Registry' ) && function_exists( '_get_path_to_translation' ) ) {
86 - _get_path_to_translation( null, true );
110 + _get_path_to_translation( '', true );
87 111 }
88 112
89 113 foreach ( $this->list_textdomains as $textdomain ) {
90 114 // Since WP 4.6, plugins translations are first loaded from wp-content/languages
@@ -138,38 +162,25 @@
138 162 unset( $this->default_locale, $this->list_textdomains, $this->labels );
139 163 }
140 164
141 165 /**
142 - * FIXME: Backward compatibility with Polylang for WooCommerce < 0.3.4
143 - * Was formerly hooked to the filter 'override_load_textdomain'
166 + * Saves all text domains in a table for later usage.
167 + * It replaces the 'override_load_textdomain' filter previously used.
144 168 *
145 - * @since 0.1
146 - *
147 - * @param bool $bool Whether to override the .mo file loading.
148 - * @return bool
149 - */
150 - public function mofile( $bool ) {
151 - return $bool;
152 - }
153 -
154 - /**
155 - * Saves all text domains in a table for later usage
156 - * It replaces the 'override_load_textdomain' filter used since 0.1
157 - *
158 169 * @since 2.0.4
159 170 *
160 - * @param string $mofile translation file name
161 - * @param string $domain text domain name
162 - * @return bool
171 + * @param string $mofile The translation file name.
172 + * @param string $domain The text domain name.
173 + * @return string
163 174 */
164 175 public function load_textdomain_mofile( $mofile, $domain ) {
165 - // On multisite, 2 files are sharing the same domain so we need to distinguish them
176 + // On multisite, 2 files are sharing the same domain so we need to distinguish them.
166 177 if ( 'default' === $domain && false !== strpos( $mofile, '/ms-' ) ) {
167 178 $this->list_textdomains['ms-default'] = array( 'mo' => $mofile, 'domain' => $domain );
168 179 } else {
169 180 $this->list_textdomains[ $domain ] = array( 'mo' => $mofile, 'domain' => $domain );
170 181 }
171 - return ''; // Hack to prevent WP loading text domains as we will load them all later
182 + return ''; // Hack to prevent WP loading text domains as we will load them all later.
172 183 }
173 184
174 185 /**
175 186 * Saves post types and taxonomies labels for a later usage
@@ -204,19 +215,20 @@
204 215 return $translation;
205 216 }
206 217
207 218 /**
208 - * Translates post types and taxonomies labels once the language is known
219 + * Translates post types and taxonomies labels once the language is known.
209 220 *
210 221 * @since 0.9
211 222 *
212 - * @param object $type either a post type or a taxonomy
223 + * @param WP_Post_Type|WP_Taxonomy $type Either a post type or a taxonomy.
224 + * @return void
213 225 */
214 226 public function translate_labels( $type ) {
215 227 // Use static array to avoid translating several times the same ( default ) labels
216 228 static $translated = array();
217 229
218 - foreach ( $type->labels as $key => $label ) {
230 + foreach ( (array) $type->labels as $key => $label ) {
219 231 if ( is_string( $label ) && isset( $this->labels[ $label ] ) ) {
220 232 if ( empty( $translated[ $label ] ) ) {
221 233 // PHPCS:disable WordPress.WP.I18n
222 234 $type->labels->$key = $translated[ $label ] = isset( $this->labels[ $label ]['context'] ) ?
@@ -231,14 +243,14 @@
231 243 }
232 244 }
233 245
234 246 /**
235 - * Allows Polylang to be the first plugin loaded ;- )
247 + * Allows Polylang to be the first plugin loaded ;-).
236 248 *
237 249 * @since 1.2
238 250 *
239 - * @param array $plugins list of active plugins
240 - * @return array list of active plugins
251 + * @param string[] $plugins List of active plugins.
252 + * @return string[] List of active plugins.
241 253 */
242 254 public function make_polylang_first( $plugins ) {
243 255 if ( $key = array_search( POLYLANG_BASENAME, $plugins ) ) {
244 256 unset( $plugins[ $key ] );