| @@ -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 |
| @@ -21,9 +18,9 @@ | ||
| 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 | |
| @@ -104,10 +101,9 @@ | ||
| 104 | 101 | |
| 105 | 102 | // Registers the string if it does not exist yet (multiline as in WPML). |
| 106 | 103 | $to_register = array( 'context' => $context, 'name' => $name, 'string' => $string, 'multiline' => true, 'icl' => true ); |
| 107 | 104 | if ( ! in_array( $to_register, self::$strings ) && $to_register['string'] ) { |
| 108 | - $key = md5( "$context | $name" ); | |
| 109 | - self::$strings[ $key ] = $to_register; | |
| 105 | + self::$strings[] = $to_register; | |
| 110 | 106 | update_option( 'polylang_wpml_strings', self::$strings ); |
| 111 | 107 | } |
| 112 | 108 | } |
| 113 | 109 | |
| @@ -115,16 +111,17 @@ | ||
| 115 | 111 | * Removes a string from the registered strings list |
| 116 | 112 | * |
| 117 | 113 | * @since 1.0.2 |
| 118 | 114 | * |
| 119 | - * @param string $context The group in which the string is registered. | |
| 120 | - * @param string $name A unique name for the string. | |
| 115 | + * @param string $context the group in which the string is registered, defaults to 'polylang' | |
| 116 | + * @param string $name a unique name for the string | |
| 121 | 117 | */ |
| 122 | 118 | 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 ); | |
| 119 | + foreach ( self::$strings as $key => $string ) { | |
| 120 | + if ( $string['context'] == $context && $string['name'] == $name ) { | |
| 121 | + unset( self::$strings[ $key ] ); | |
| 122 | + update_option( 'polylang_wpml_strings', self::$strings ); | |
| 123 | + } | |
| 127 | 124 | } |
| 128 | 125 | } |
| 129 | 126 | |
| 130 | 127 | /** |
| @@ -143,13 +140,17 @@ | ||
| 143 | 140 | * Get a registered string by its context and name |
| 144 | 141 | * |
| 145 | 142 | * @since 2.0 |
| 146 | 143 | * |
| 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. | |
| 144 | + * @param string $context the group in which the string is registered | |
| 145 | + * @param string $name a unique name for the string | |
| 146 | + * @return bool|string the registered string, false if none was found | |
| 150 | 147 | */ |
| 151 | 148 | 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; | |
| 149 | + foreach ( self::$strings as $string ) { | |
| 150 | + if ( $string['context'] == $context && $string['name'] == $name ) { | |
| 151 | + return $string['string']; | |
| 152 | + } | |
| 153 | + } | |
| 154 | + return false; | |
| 154 | 155 | } |
| 155 | 156 | } |