PluginProbe
Polylang / 3.1.4
Polylang v3.1.4
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 +22 -11 2.73.1.4 View file →
@@ -1,5 +1,8 @@
1 1 <?php
2 +/**
3 + * @package Polylang
4 + */
2 5
3 6 /**
4 7 * A class to handle the WPML API based on hooks, introduced since WPML 3.2
5 8 * It partly relies on the legacy API
@@ -8,8 +11,13 @@
8 11 *
9 12 * @since 2.0
10 13 */
11 14 class PLL_WPML_API {
15 + /**
16 + * Stores the original language when the language is switched.
17 + *
18 + * @var PLL_Language
19 + */
12 20 private static $original_language = null;
13 21
14 22 /**
15 23 * Constructor
@@ -122,20 +130,18 @@
122 130 }
123 131
124 132 /**
125 133 * In WPML, get a language's native and translated name for display in a custom language switcher
126 - * 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.
127 136 *
128 137 * @since 2.2
129 138 *
130 - * @param mixed $null Not used.
131 - * @param string $native_name The language native name.
132 - * @param string|bool $translated_name The language translated name. Not used.
133 - * @param bool $native_hidden Whether to hide the language native name or not. Not used.
134 - * @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.
135 141 * @return string
136 142 */
137 - 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 ) {
138 144 return $native_name;
139 145 }
140 146
141 147 /**
@@ -141,8 +147,10 @@
141 147 /**
142 148 * Returns an HTML hidden input field with name=”lang” and as value the current language
143 149 *
144 150 * @since 2.0
151 + *
152 + * @return void
145 153 */
146 154 public function wpml_add_language_form_field() {
147 155 $lang = pll_current_language();
148 156 $field = sprintf( '<input type="hidden" name="lang" value="%s" />', esc_attr( $lang ) );
@@ -168,12 +176,11 @@
168 176 * Find out whether the current language text direction is RTL or not
169 177 *
170 178 * @since 2.0
171 179 *
172 - * @param mixed $null Not used
173 180 * @return bool
174 181 */
175 - public function wpml_is_rtl( $null ) {
182 + public function wpml_is_rtl() {
176 183 return pll_current_language( 'is_rtl' );
177 184 }
178 185
179 186 /**
@@ -183,8 +190,9 @@
183 190 * @since 2.7
184 191 *
185 192 * @param null|string $lang Language code to switch into, restores the original language if null.
186 193 * @param bool|string $cookie Optionally also switches the cookie.
194 + * @return void
187 195 */
188 196 public static function wpml_switch_language( $lang = null, $cookie = false ) {
189 197 if ( null === self::$original_language ) {
190 198 self::$original_language = PLL()->curlang;
@@ -217,10 +225,13 @@
217 225 public function wpml_element_language_code( $language_code, $args ) {
218 226 $type = $args['element_type'];
219 227 $id = $args['element_id'];
220 228 $pll_type = ( 'post' == $type || pll_is_translated_post_type( $type ) ) ? 'post' : ( 'term' == $type || pll_is_translated_taxonomy( $type ) ? 'term' : false );
221 - if ( 'term' === $pll_type && $term = get_term_by( 'term_taxonomy_id', $id ) ) {
222 - $id = $term->term_id;
229 + if ( 'term' === $pll_type ) {
230 + $term = get_term_by( 'term_taxonomy_id', $id );
231 + if ( $term instanceof WP_Term ) {
232 + $id = $term->term_id;
233 + }
223 234 }
224 235 return $pll_type ? call_user_func( "pll_get_{$pll_type}_language", $id ) : $language_code;
225 236 }
226 237