| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * A class to handle the WPML API based on hooks, introduced since WPML 3.2 |
| 8 | 5 | * It partly relies on the legacy API |
| @@ -11,9 +8,8 @@ | ||
| 11 | 8 | * |
| 12 | 9 | * @since 2.0 |
| 13 | 10 | */ |
| 14 | 11 | class PLL_WPML_API { |
| 15 | - private static $original_language = null; | |
| 16 | 12 | |
| 17 | 13 | /** |
| 18 | 14 | * Constructor |
| 19 | 15 | * |
| @@ -32,9 +28,9 @@ | ||
| 32 | 28 | add_action( 'wpml_add_language_form_field', array( $this, 'wpml_add_language_form_field' ) ); |
| 33 | 29 | add_filter( 'wpml_language_is_active', array( $this, 'wpml_language_is_active' ), 10, 2 ); |
| 34 | 30 | add_filter( 'wpml_is_rtl', array( $this, 'wpml_is_rtl' ) ); |
| 35 | 31 | // wpml_language_form_input_field => See wpml_add_language_form_field |
| 36 | - // wpml_language_has_switched => See wpml_switch_language | |
| 32 | + // wpml_language_has_switched => not implemented | |
| 37 | 33 | // wpml_element_trid => not implemented |
| 38 | 34 | // wpml_get_element_translations => not implemented |
| 39 | 35 | // wpml_language_switcher => not implemented |
| 40 | 36 | // wpml_browser_redirect_language_params => not implemented |
| @@ -45,9 +41,9 @@ | ||
| 45 | 41 | |
| 46 | 42 | // Retrieving Language Information for Content |
| 47 | 43 | |
| 48 | 44 | add_filter( 'wpml_post_language_details', 'wpml_get_language_information', 10, 2 ); |
| 49 | - add_action( 'wpml_switch_language', array( __CLASS__, 'wpml_switch_language' ), 10, 2 ); | |
| 45 | + // wpml_switch_language => not implemented | |
| 50 | 46 | add_filter( 'wpml_element_language_code', array( $this, 'wpml_element_language_code' ), 10, 3 ); |
| 51 | 47 | // wpml_element_language_details => not applicable |
| 52 | 48 | |
| 53 | 49 | // Retrieving Localized Content |
| @@ -149,9 +145,9 @@ | ||
| 149 | 145 | public function wpml_add_language_form_field() { |
| 150 | 146 | $lang = pll_current_language(); |
| 151 | 147 | $field = sprintf( '<input type="hidden" name="lang" value="%s" />', esc_attr( $lang ) ); |
| 152 | 148 | $field = apply_filters( 'wpml_language_form_input_field', $field, $lang ); |
| 153 | - echo $field; // phpcs:ignore WordPress.Security.EscapeOutput | |
| 149 | + echo $field; | |
| 154 | 150 | } |
| 155 | 151 | |
| 156 | 152 | /** |
| 157 | 153 | * Find out if a specific language is enabled for the site |
| @@ -179,37 +175,8 @@ | ||
| 179 | 175 | return pll_current_language( 'is_rtl' ); |
| 180 | 176 | } |
| 181 | 177 | |
| 182 | 178 | /** |
| 183 | - * Switches whole site to the given language or restores the language that was set when first calling this function. | |
| 184 | - * Unlike the WPML original action, it is not possible to set the current language and the cookie to different values. | |
| 185 | - * | |
| 186 | - * @since 2.7 | |
| 187 | - * | |
| 188 | - * @param null|string $lang Language code to switch into, restores the original language if null. | |
| 189 | - * @param bool|string $cookie Optionally also switches the cookie. | |
| 190 | - */ | |
| 191 | - public static function wpml_switch_language( $lang = null, $cookie = false ) { | |
| 192 | - if ( null === self::$original_language ) { | |
| 193 | - self::$original_language = PLL()->curlang; | |
| 194 | - } | |
| 195 | - | |
| 196 | - if ( empty( $lang ) ) { | |
| 197 | - PLL()->curlang = self::$original_language; | |
| 198 | - } elseif ( 'all' === $lang ) { | |
| 199 | - PLL()->curlang = null; | |
| 200 | - } elseif ( in_array( $lang, pll_languages_list() ) ) { | |
| 201 | - PLL()->curlang = PLL()->model->get_language( $lang ); | |
| 202 | - } | |
| 203 | - | |
| 204 | - if ( $cookie && isset( PLL()->choose_lang ) ) { | |
| 205 | - PLL()->choose_lang->maybe_setcookie(); | |
| 206 | - } | |
| 207 | - | |
| 208 | - do_action( 'wpml_language_has_switched', $lang, $cookie, self::$original_language ); | |
| 209 | - } | |
| 210 | - | |
| 211 | - /** | |
| 212 | 179 | * Get the language code for a translatable element |
| 213 | 180 | * |
| 214 | 181 | * @since 2.0 |
| 215 | 182 | * |
| @@ -220,9 +187,9 @@ | ||
| 220 | 187 | public function wpml_element_language_code( $language_code, $args ) { |
| 221 | 188 | $type = $args['element_type']; |
| 222 | 189 | $id = $args['element_id']; |
| 223 | 190 | $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 ) ) { | |
| 191 | + if ( 'term' === $pll_type && $term = wpcom_vip_get_term_by( 'term_taxonomy_id', $id ) ) { | |
| 225 | 192 | $id = $term->term_id; |
| 226 | 193 | } |
| 227 | 194 | return $pll_type ? call_user_func( "pll_get_{$pll_type}_language", $id ) : $language_code; |
| 228 | 195 | } |