PluginProbe
Polylang / 3.3
Polylang v3.3
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-api.php +35 -16 2.83.3 View file →
@@ -11,8 +11,13 @@
11 11 *
12 12 * @since 2.0
13 13 */
14 14 class PLL_WPML_API {
15 + /**
16 + * Stores the original language when the language is switched.
17 + *
18 + * @var PLL_Language|null
19 + */
15 20 private static $original_language = null;
16 21
17 22 /**
18 23 * Constructor
@@ -125,20 +130,18 @@
125 130 }
126 131
127 132 /**
128 133 * In WPML, get a language's native and translated name for display in a custom language switcher
129 - * Since Polylang does not implement the translated name, always returns only the native name
134 + * Since Polylang does not implement the translated name, always returns only the native name,
135 + * so the 3rd, 4th and 5th parameters are not used.
130 136 *
131 137 * @since 2.2
132 138 *
133 - * @param mixed $null Not used.
134 - * @param string $native_name The language native name.
135 - * @param string|bool $translated_name The language translated name. Not used.
136 - * @param bool $native_hidden Whether to hide the language native name or not. Not used.
137 - * @param bool $translated_hidden Whether to hide the language translated name or not. Not used.
139 + * @param mixed $null Not used.
140 + * @param string $native_name The language native name.
138 141 * @return string
139 142 */
140 - public function wpml_display_language_names( $null, $native_name, $translated_name = false, $native_hidden = false, $translated_hidden = false ) {
143 + public function wpml_display_language_names( $null, $native_name ) {
141 144 return $native_name;
142 145 }
143 146
144 147 /**
@@ -144,8 +147,10 @@
144 147 /**
145 148 * Returns an HTML hidden input field with name=”lang” and as value the current language
146 149 *
147 150 * @since 2.0
151 + *
152 + * @return void
148 153 */
149 154 public function wpml_add_language_form_field() {
150 155 $lang = pll_current_language();
151 156 $field = sprintf( '<input type="hidden" name="lang" value="%s" />', esc_attr( $lang ) );
@@ -171,12 +176,11 @@
171 176 * Find out whether the current language text direction is RTL or not
172 177 *
173 178 * @since 2.0
174 179 *
175 - * @param mixed $null Not used
176 180 * @return bool
177 181 */
178 - public function wpml_is_rtl( $null ) {
182 + public function wpml_is_rtl() {
179 183 return pll_current_language( 'is_rtl' );
180 184 }
181 185
182 186 /**
@@ -186,8 +190,9 @@
186 190 * @since 2.7
187 191 *
188 192 * @param null|string $lang Language code to switch into, restores the original language if null.
189 193 * @param bool|string $cookie Optionally also switches the cookie.
194 + * @return void
190 195 */
191 196 public static function wpml_switch_language( $lang = null, $cookie = false ) {
192 197 if ( null === self::$original_language ) {
193 198 self::$original_language = PLL()->curlang;
@@ -218,14 +223,23 @@
218 223 * @return string
219 224 */
220 225 public function wpml_element_language_code( $language_code, $args ) {
221 226 $type = $args['element_type'];
222 - $id = $args['element_id'];
223 - $pll_type = ( 'post' == $type || pll_is_translated_post_type( $type ) ) ? 'post' : ( 'term' == $type || pll_is_translated_taxonomy( $type ) ? 'term' : false );
224 - if ( 'term' === $pll_type && $term = get_term_by( 'term_taxonomy_id', $id ) ) {
225 - $id = $term->term_id;
227 + $id = $args['element_id'];
228 +
229 + if ( 'post' === $type || pll_is_translated_post_type( $type ) ) {
230 + return pll_get_post_language( $id );
226 231 }
227 - return $pll_type ? call_user_func( "pll_get_{$pll_type}_language", $id ) : $language_code;
232 +
233 + if ( 'term' === $type || pll_is_translated_taxonomy( $type ) ) {
234 + $term = get_term_by( 'term_taxonomy_id', $id );
235 + if ( $term instanceof WP_Term ) {
236 + $id = $term->term_id;
237 + }
238 + return pll_get_term_language( $id );
239 + }
240 +
241 + return $language_code;
228 242 }
229 243
230 244 /**
231 245 * Translates a string
@@ -293,8 +307,13 @@
293 307 * @param string $type The post type or taxonomy
294 308 * @return bool
295 309 */
296 310 public function wpml_element_has_translations( $null, $id, $type ) {
297 - $pll_type = ( 'post' == $type || pll_is_translated_post_type( $type ) ) ? 'post' : ( 'term' == $type || pll_is_translated_taxonomy( $type ) ? 'term' : false );
298 - return ( $pll_type && $translations = call_user_func( "pll_get_{$pll_type}_translations", $id ) ) ? count( $translations ) > 1 : false;
311 + if ( 'post' === $type || pll_is_translated_post_type( $type ) ) {
312 + return count( pll_get_post_translations( $id ) ) > 1;
313 + } elseif ( 'term' === $type || pll_is_translated_taxonomy( $type ) ) {
314 + return count( pll_get_term_translations( $id ) ) > 1;
315 + }
316 +
317 + return false;
299 318 }
300 319 }