| @@ -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 | |
| 19 | + */ | |
| 15 | 20 | private static $original_language = null; |
| 16 | 21 | |
| 17 | 22 | /** |
| 18 | 23 | * Constructor |
| @@ -142,8 +147,10 @@ | ||
| 142 | 147 | /** |
| 143 | 148 | * Returns an HTML hidden input field with name=”lang” and as value the current language |
| 144 | 149 | * |
| 145 | 150 | * @since 2.0 |
| 151 | + * | |
| 152 | + * @return void | |
| 146 | 153 | */ |
| 147 | 154 | public function wpml_add_language_form_field() { |
| 148 | 155 | $lang = pll_current_language(); |
| 149 | 156 | $field = sprintf( '<input type="hidden" name="lang" value="%s" />', esc_attr( $lang ) ); |
| @@ -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 | |