PluginProbe
Polylang / 2.0.12
Polylang v2.0.12
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 | modules/wpml/wpml-compat.php +27 -44 2.8.32.0.12 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * WPML Compatibility class
8 5 * Defines some WPML constants
@@ -10,10 +7,10 @@
10 7 *
11 8 * @since 1.0.2
12 9 */
13 10 class PLL_WPML_Compat {
14 - protected static $instance; // For singleton
15 - protected static $strings; // Used for cache
11 + static protected $instance; // For singleton
12 + static protected $strings; // Used for cache
16 13 public $api;
17 14
18 15 /**
19 16 * Constructor
@@ -21,16 +18,15 @@
21 18 * @since 1.0.2
22 19 */
23 20 protected function __construct() {
24 21 // Load the WPML API
25 - require_once __DIR__ . '/wpml-legacy-api.php';
22 + require_once( PLL_MODULES_INC . '/wpml/wpml-legacy-api.php' );
26 23 $this->api = new PLL_WPML_API();
27 24
28 25 self::$strings = get_option( 'polylang_wpml_strings', array() );
29 26
30 27 add_action( 'pll_language_defined', array( $this, 'define_constants' ) );
31 - add_action( 'pll_no_language_defined', array( $this, 'define_constants' ) );
32 - add_filter( 'pll_get_strings', array( $this, 'get_strings' ) );
28 + add_action( 'pll_get_strings', array( $this, 'get_strings' ) );
33 29 }
34 30
35 31 /**
36 32 * Access to the single instance of the class
@@ -38,9 +34,9 @@
38 34 * @since 1.7
39 35 *
40 36 * @return object
41 37 */
42 - public static function instance() {
38 + static public function instance() {
43 39 if ( empty( self::$instance ) ) {
44 40 self::$instance = new self();
45 41 }
46 42 return self::$instance;
@@ -79,35 +75,17 @@
79 75 * we use a serialized option to do this
80 76 *
81 77 * @since 1.0.2
82 78 *
83 - * @param string $context The group in which the string is registered.
84 - * @param string $name A unique name for the string.
85 - * @param string $string The string to register.
79 + * @param string $context the group in which the string is registered, defaults to 'polylang'
80 + * @param string $name a unique name for the string
81 + * @param string $string the string to register
86 82 */
87 83 public function register_string( $context, $name, $string ) {
88 - // If a string has already been registered with the same name and context, let's replace it.
89 - $exist_string = $this->get_string_by_context_and_name( $context, $name );
90 - if ( $exist_string && $exist_string !== $string ) {
91 - $languages = PLL()->model->get_languages_list();
92 -
93 - // Assign translations of the old string to the new string, except for the default language.
94 - foreach ( $languages as $language ) {
95 - if ( pll_default_language() !== $language->slug ) {
96 - $mo = new PLL_MO();
97 - $mo->import_from_db( $language );
98 - $mo->add_entry( $mo->make_entry( $string, $mo->translate( $exist_string ) ) );
99 - $mo->export_to_db( $language );
100 - }
101 - }
102 - $this->unregister_string( $context, $name );
103 - }
104 -
105 - // Registers the string if it does not exist yet (multiline as in WPML).
106 - $to_register = array( 'context' => $context, 'name' => $name, 'string' => $string, 'multiline' => true, 'icl' => true );
84 + // Registers the string if it does not exist yet
85 + $to_register = array( 'context' => $context, 'name' => $name, 'string' => $string, 'multiline' => false, 'icl' => true );
107 86 if ( ! in_array( $to_register, self::$strings ) && $to_register['string'] ) {
108 - $key = md5( "$context | $name" );
109 - self::$strings[ $key ] = $to_register;
87 + self::$strings[] = $to_register;
110 88 update_option( 'polylang_wpml_strings', self::$strings );
111 89 }
112 90 }
113 91
@@ -115,16 +93,17 @@
115 93 * Removes a string from the registered strings list
116 94 *
117 95 * @since 1.0.2
118 96 *
119 - * @param string $context The group in which the string is registered.
120 - * @param string $name A unique name for the string.
97 + * @param string $context the group in which the string is registered, defaults to 'polylang'
98 + * @param string $name a unique name for the string
121 99 */
122 100 public function unregister_string( $context, $name ) {
123 - $key = md5( "$context | $name" );
124 - if ( isset( self::$strings[ $key ] ) ) {
125 - unset( self::$strings[ $key ] );
126 - update_option( 'polylang_wpml_strings', self::$strings );
101 + foreach ( self::$strings as $key => $string ) {
102 + if ( $string['context'] == $context && $string['name'] == $name ) {
103 + unset( self::$strings[ $key ] );
104 + update_option( 'polylang_wpml_strings', self::$strings );
105 + }
127 106 }
128 107 }
129 108
130 109 /**
@@ -143,13 +122,17 @@
143 122 * Get a registered string by its context and name
144 123 *
145 124 * @since 2.0
146 125 *
147 - * @param string $context The group in which the string is registered.
148 - * @param string $name A unique name for the string.
149 - * @return bool|string The registered string, false if none was found.
126 + * @param string $context the group in which the string is registered
127 + * @param string $name a unique name for the string
128 + * @return bool|string the registered string, false if none was found
150 129 */
151 130 public function get_string_by_context_and_name( $context, $name ) {
152 - $key = md5( "$context | $name" );
153 - return isset( self::$strings[ $key ] ) ? self::$strings[ $key ]['string'] : false;
131 + foreach ( self::$strings as $string ) {
132 + if ( $string['context'] == $context && $string['name'] == $name ) {
133 + return $string['string'];
134 + }
135 + }
136 + return false;
154 137 }
155 138 }