PluginProbe
Polylang / 2.3.6
Polylang v2.3.6
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 +18 -20 2.92.3.6 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * It is best practice that plugins do nothing before plugins_loaded is fired
8 5 * so it is what Polylang intends to do
@@ -12,9 +9,9 @@
12 9 *
13 10 * @since 1.2
14 11 */
15 12 class PLL_OLT_Manager {
16 - protected static $instance; // For singleton
13 + static protected $instance; // For singleton
17 14 protected $default_locale;
18 15 protected $list_textdomains = array(); // All text domains
19 16 public $labels = array(); // Post types and taxonomies labels to translate
20 17
@@ -29,9 +26,9 @@
29 26 add_filter( 'pre_update_option_active_sitewide_plugins', array( $this, 'make_polylang_first' ) );
30 27
31 28 // Overriding load text domain only on front since WP 4.7
32 29 // 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' ) ) {
30 + if ( is_admin() && function_exists( 'get_user_locale' ) ) {
34 31 return;
35 32 }
36 33
37 34 // Saves the default locale before we start any language manipulation
@@ -41,11 +38,13 @@
41 38 add_filter( 'load_textdomain_mofile', array( $this, 'load_textdomain_mofile' ), 10, 2 );
42 39 add_filter( 'gettext', array( $this, 'gettext' ), 10, 3 );
43 40 add_filter( 'gettext_with_context', array( $this, 'gettext_with_context' ), 10, 4 );
44 41
45 - // Loads text domains
46 - add_action( 'pll_language_defined', array( $this, 'load_textdomains' ), 2 ); // After PLL_Frontend::pll_language_defined
47 - add_action( 'pll_no_language_defined', array( $this, 'load_textdomains' ) );
42 + if ( ! Polylang::is_ajax_on_front() ) {
43 + // Loads text domains
44 + add_action( 'pll_language_defined', array( $this, 'load_textdomains' ), 2 ); // After PLL_Frontend::pll_language_defined
45 + add_action( 'pll_no_language_defined', array( $this, 'load_textdomains' ) );
46 + }
48 47 }
49 48
50 49 /**
51 50 * Access to the single instance of the class
@@ -53,9 +52,9 @@
53 52 * @since 1.7
54 53 *
55 54 * @return object
56 55 */
57 - public static function instance() {
56 + static public function instance() {
58 57 if ( empty( self::$instance ) ) {
59 58 self::$instance = new self();
60 59 }
61 60
@@ -76,14 +75,13 @@
76 75
77 76 // Don't try to save time for en_US as some users have theme written in another language
78 77 // Now we can load all overridden text domains with the right language
79 78 if ( ! empty( $this->list_textdomains ) ) {
80 - /*
81 - * FIXME: Backward compatibility with WP < 5.6
82 - * 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 - * See WP_Locale_Switcher::change_locale()
84 - */
85 - if ( ! class_exists( 'WP_Textdomain_Registry' ) && function_exists( '_get_path_to_translation' ) ) {
79 +
80 + // Since WP 4.7 we need to reset the internal cache of _get_path_to_translation when switching from any locale to en_US
81 + // See WP_Locale_Switcher::change_locale()
82 + // FIXME test _get_path_to_translation for backward compatibility with WP < 4.7
83 + if ( function_exists( '_get_path_to_translation' ) ) {
86 84 _get_path_to_translation( null, true );
87 85 }
88 86
89 87 foreach ( $this->list_textdomains as $textdomain ) {
@@ -139,16 +137,18 @@
139 137 }
140 138
141 139 /**
142 140 * FIXME: Backward compatibility with Polylang for WooCommerce < 0.3.4
143 - * Was formerly hooked to the filter 'override_load_textdomain'
141 + * To remove in Polylang 2.1
144 142 *
145 143 * @since 0.1
146 144 *
147 - * @param bool $bool Whether to override the .mo file loading.
145 + * @param bool $bool not used
146 + * @param string $domain text domain name
147 + * @param string $mofile translation file name
148 148 * @return bool
149 149 */
150 - public function mofile( $bool ) {
150 + public function mofile( $bool, $domain, $mofile ) {
151 151 return $bool;
152 152 }
153 153
154 154 /**
@@ -217,13 +217,11 @@
217 217
218 218 foreach ( $type->labels as $key => $label ) {
219 219 if ( is_string( $label ) && isset( $this->labels[ $label ] ) ) {
220 220 if ( empty( $translated[ $label ] ) ) {
221 - // PHPCS:disable WordPress.WP.I18n
222 221 $type->labels->$key = $translated[ $label ] = isset( $this->labels[ $label ]['context'] ) ?
223 222 _x( $label, $this->labels[ $label ]['context'], $this->labels[ $label ]['domain'] ) :
224 223 __( $label, $this->labels[ $label ]['domain'] );
225 - // PHPCS:enable
226 224 }
227 225 else {
228 226 $type->labels->$key = $translated[ $label ];
229 227 }