PluginProbe
Polylang / 2.1
Polylang v2.1
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 +12 -20 2.8.22.1 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
@@ -44,8 +41,9 @@
44 41
45 42 // Loads text domains
46 43 add_action( 'pll_language_defined', array( $this, 'load_textdomains' ), 2 ); // After PLL_Frontend::pll_language_defined
47 44 add_action( 'pll_no_language_defined', array( $this, 'load_textdomains' ) );
45 +
48 46 }
49 47
50 48 /**
51 49 * Access to the single instance of the class
@@ -53,9 +51,9 @@
53 51 * @since 1.7
54 52 *
55 53 * @return object
56 54 */
57 - public static function instance() {
55 + static public function instance() {
58 56 if ( empty( self::$instance ) ) {
59 57 self::$instance = new self();
60 58 }
61 59
@@ -73,14 +71,15 @@
73 71 remove_filter( 'gettext', array( $this, 'gettext' ), 10, 3 );
74 72 remove_filter( 'gettext_with_context', array( $this, 'gettext_with_context' ), 10, 4 );
75 73 $new_locale = get_locale();
76 74
75 +
77 76 // Don't try to save time for en_US as some users have theme written in another language
78 - // Now we can load all overridden text domains with the right language
77 + // Now we can load all overriden text domains with the right language
79 78 if ( ! empty( $this->list_textdomains ) ) {
80 79
81 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
82 - // See WP_Locale_Switcher::change_locale()
81 + // See WP_Locale_Switcher::changle_locale()
83 82 // FIXME test _get_path_to_translation for backward compatibility with WP < 4.7
84 83 if ( function_exists( '_get_path_to_translation' ) ) {
85 84 _get_path_to_translation( null, true );
86 85 }
@@ -97,16 +96,16 @@
97 96 }
98 97 }
99 98
100 99 // First remove taxonomies and post_types labels that we don't need to translate
101 - $taxonomies = get_taxonomies( array( '_pll' => true ) );
102 - $post_types = get_post_types( array( '_pll' => true ) );
100 + $taxonomies = array( 'language', 'term_language', 'term_translations', 'post_translations' );
101 + $post_types = array( 'polylang_mo' );
103 102
104 103 // We don't need to translate core taxonomies and post types labels when setting the language from the url
105 104 // As they will be translated when registered the second time
106 105 if ( ! did_action( 'setup_theme' ) ) {
107 - $taxonomies = array_merge( get_taxonomies( array( '_builtin' => true ) ), $taxonomies );
108 - $post_types = array_merge( get_post_types( array( '_builtin' => true ) ), $post_types );
106 + $taxonomies = array_merge( array( 'category', 'post_tag', 'nav_menu', 'link_category', 'post_format' ), $taxonomies );
107 + $post_types = array_merge( array( 'post', 'page', 'attachment', 'revision', 'nav_menu_item' ), $post_types );
109 108 }
110 109
111 110 // Translate labels of post types and taxonomies
112 111 foreach ( array_diff_key( $GLOBALS['wp_taxonomies'], array_flip( $taxonomies ) ) as $tax ) {
@@ -162,14 +161,9 @@
162 161 * @param string $domain text domain name
163 162 * @return bool
164 163 */
165 164 public function load_textdomain_mofile( $mofile, $domain ) {
166 - // On multisite, 2 files are sharing the same domain so we need to distinguish them
167 - if ( 'default' === $domain && false !== strpos( $mofile, '/ms-' ) ) {
168 - $this->list_textdomains['ms-default'] = array( 'mo' => $mofile, 'domain' => $domain );
169 - } else {
170 - $this->list_textdomains[ $domain ] = array( 'mo' => $mofile, 'domain' => $domain );
171 - }
165 + $this->list_textdomains[ $domain ] = array( 'mo' => $mofile, 'domain' => $domain );
172 166 return ''; // Hack to prevent WP loading text domains as we will load them all later
173 167 }
174 168
175 169 /**
@@ -218,13 +212,11 @@
218 212
219 213 foreach ( $type->labels as $key => $label ) {
220 214 if ( is_string( $label ) && isset( $this->labels[ $label ] ) ) {
221 215 if ( empty( $translated[ $label ] ) ) {
222 - // PHPCS:disable WordPress.WP.I18n
223 216 $type->labels->$key = $translated[ $label ] = isset( $this->labels[ $label ]['context'] ) ?
224 217 _x( $label, $this->labels[ $label ]['context'], $this->labels[ $label ]['domain'] ) :
225 218 __( $label, $this->labels[ $label ]['domain'] );
226 - // PHPCS:enable
227 219 }
228 220 else {
229 221 $type->labels->$key = $translated[ $label ];
230 222 }