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