| @@ -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 |
| @@ -125,18 +121,20 @@ | ||
| 125 | 121 | } |
| 126 | 122 | |
| 127 | 123 | /** |
| 128 | 124 | * 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, | |
| 130 | - * so the 3rd, 4th and 5th parameters are not used. | |
| 125 | + * Since Polylang does not implement the translated name, always returns only the native name | |
| 131 | 126 | * |
| 132 | 127 | * @since 2.2 |
| 133 | 128 | * |
| 134 | - * @param mixed $null Not used. | |
| 135 | - * @param string $native_name The language native name. | |
| 129 | + * @param mixed $null Not used. | |
| 130 | + * @param string $native_name The language native name. | |
| 131 | + * @param string|bool $translated_name The language translated name. Not used. | |
| 132 | + * @param bool $native_hidden Whether to hide the language native name or not. Not used. | |
| 133 | + * @param bool $translated_hidden Whether to hide the language translated name or not. Not used. | |
| 136 | 134 | * @return string |
| 137 | 135 | */ |
| 138 | - public function wpml_display_language_names( $null, $native_name ) { | |
| 136 | + public function wpml_display_language_names( $null, $native_name, $translated_name = false, $native_hidden = false, $translated_hidden = false ) { | |
| 139 | 137 | return $native_name; |
| 140 | 138 | } |
| 141 | 139 | |
| 142 | 140 | /** |
| @@ -147,9 +145,9 @@ | ||
| 147 | 145 | public function wpml_add_language_form_field() { |
| 148 | 146 | $lang = pll_current_language(); |
| 149 | 147 | $field = sprintf( '<input type="hidden" name="lang" value="%s" />', esc_attr( $lang ) ); |
| 150 | 148 | $field = apply_filters( 'wpml_language_form_input_field', $field, $lang ); |
| 151 | - echo $field; // phpcs:ignore WordPress.Security.EscapeOutput | |
| 149 | + echo $field; | |
| 152 | 150 | } |
| 153 | 151 | |
| 154 | 152 | /** |
| 155 | 153 | * Find out if a specific language is enabled for the site |
| @@ -169,44 +167,16 @@ | ||
| 169 | 167 | * Find out whether the current language text direction is RTL or not |
| 170 | 168 | * |
| 171 | 169 | * @since 2.0 |
| 172 | 170 | * |
| 171 | + * @param mixed $null Not used | |
| 173 | 172 | * @return bool |
| 174 | 173 | */ |
| 175 | - public function wpml_is_rtl() { | |
| 174 | + public function wpml_is_rtl( $null ) { | |
| 176 | 175 | return pll_current_language( 'is_rtl' ); |
| 177 | 176 | } |
| 178 | 177 | |
| 179 | 178 | /** |
| 180 | - * Switches whole site to the given language or restores the language that was set when first calling this function. | |
| 181 | - * Unlike the WPML original action, it is not possible to set the current language and the cookie to different values. | |
| 182 | - * | |
| 183 | - * @since 2.7 | |
| 184 | - * | |
| 185 | - * @param null|string $lang Language code to switch into, restores the original language if null. | |
| 186 | - * @param bool|string $cookie Optionally also switches the cookie. | |
| 187 | - */ | |
| 188 | - public static function wpml_switch_language( $lang = null, $cookie = false ) { | |
| 189 | - if ( null === self::$original_language ) { | |
| 190 | - self::$original_language = PLL()->curlang; | |
| 191 | - } | |
| 192 | - | |
| 193 | - if ( empty( $lang ) ) { | |
| 194 | - PLL()->curlang = self::$original_language; | |
| 195 | - } elseif ( 'all' === $lang ) { | |
| 196 | - PLL()->curlang = null; | |
| 197 | - } elseif ( in_array( $lang, pll_languages_list() ) ) { | |
| 198 | - PLL()->curlang = PLL()->model->get_language( $lang ); | |
| 199 | - } | |
| 200 | - | |
| 201 | - if ( $cookie && isset( PLL()->choose_lang ) ) { | |
| 202 | - PLL()->choose_lang->maybe_setcookie(); | |
| 203 | - } | |
| 204 | - | |
| 205 | - do_action( 'wpml_language_has_switched', $lang, $cookie, self::$original_language ); | |
| 206 | - } | |
| 207 | - | |
| 208 | - /** | |
| 209 | 179 | * Get the language code for a translatable element |
| 210 | 180 | * |
| 211 | 181 | * @since 2.0 |
| 212 | 182 | * |
| @@ -217,9 +187,9 @@ | ||
| 217 | 187 | public function wpml_element_language_code( $language_code, $args ) { |
| 218 | 188 | $type = $args['element_type']; |
| 219 | 189 | $id = $args['element_id']; |
| 220 | 190 | $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 ) ) { | |
| 191 | + if ( 'term' === $pll_type && $term = wpcom_vip_get_term_by( 'term_taxonomy_id', $id ) ) { | |
| 222 | 192 | $id = $term->term_id; |
| 223 | 193 | } |
| 224 | 194 | return $pll_type ? call_user_func( "pll_get_{$pll_type}_language", $id ) : $language_code; |
| 225 | 195 | } |