| @@ -1,19 +1,14 @@ | ||
| 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 |
| 9 | - * | |
| 10 | 6 | * @see https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/ |
| 11 | 7 | * |
| 12 | 8 | * @since 2.0 |
| 13 | 9 | */ |
| 14 | 10 | class PLL_WPML_API { |
| 15 | - private static $original_language = null; | |
| 16 | 11 | |
| 17 | 12 | /** |
| 18 | 13 | * Constructor |
| 19 | 14 | * |
| @@ -23,33 +18,25 @@ | ||
| 23 | 18 | // Site Wide Language informations |
| 24 | 19 | |
| 25 | 20 | add_filter( 'wpml_active_languages', array( $this, 'wpml_active_languages' ), 10, 2 ); |
| 26 | 21 | add_filter( 'wpml_display_language_names', array( $this, 'wpml_display_language_names' ), 10, 5 ); |
| 27 | - // wpml_translated_language_name => not applicable | |
| 22 | + // wpml_translated_language_name => not applicable | |
| 28 | 23 | add_filter( 'wpml_current_language', 'pll_current_language', 10, 0 ); |
| 29 | 24 | add_filter( 'wpml_default_language', 'pll_default_language', 10, 0 ); |
| 30 | - // wpml_add_language_selector => not implemented | |
| 31 | - // wpml_footer_language_selector => not applicable | |
| 25 | + // wpml_add_language_selector => not implemented | |
| 26 | + // wpml_footer_language_selector => not applicable | |
| 32 | 27 | add_action( 'wpml_add_language_form_field', array( $this, 'wpml_add_language_form_field' ) ); |
| 33 | 28 | add_filter( 'wpml_language_is_active', array( $this, 'wpml_language_is_active' ), 10, 2 ); |
| 34 | 29 | add_filter( 'wpml_is_rtl', array( $this, 'wpml_is_rtl' ) ); |
| 35 | - // wpml_language_form_input_field => See wpml_add_language_form_field | |
| 36 | - // wpml_language_has_switched => See wpml_switch_language | |
| 37 | - // wpml_element_trid => not implemented | |
| 38 | - // wpml_get_element_translations => not implemented | |
| 39 | - // wpml_language_switcher => not implemented | |
| 40 | - // wpml_browser_redirect_language_params => not implemented | |
| 41 | - // wpml_enqueue_browser_redirect_language => not applicable | |
| 42 | - // wpml_enqueued_browser_redirect_language => not applicable | |
| 43 | - // wpml_encode_string => not applicable | |
| 44 | - // wpml_decode_string => not applicable | |
| 30 | + // wpml_language_form_input_field => See wpml_add_language_form_field | |
| 31 | + // wpml_language_has_switched => not implemented | |
| 45 | 32 | |
| 46 | 33 | // Retrieving Language Information for Content |
| 47 | 34 | |
| 48 | 35 | 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 ); | |
| 36 | + // wpml_switch_language => not implemented | |
| 50 | 37 | add_filter( 'wpml_element_language_code', array( $this, 'wpml_element_language_code' ), 10, 3 ); |
| 51 | - // wpml_element_language_details => not applicable | |
| 38 | + // wpml_element_language_details => not applicable | |
| 52 | 39 | |
| 53 | 40 | // Retrieving Localized Content |
| 54 | 41 | |
| 55 | 42 | add_filter( 'wpml_home_url', 'pll_home_url', 10, 0 ); |
| @@ -55,61 +42,49 @@ | ||
| 55 | 42 | add_filter( 'wpml_home_url', 'pll_home_url', 10, 0 ); |
| 56 | 43 | add_filter( 'wpml_element_link', 'icl_link_to_element', 10, 7 ); |
| 57 | 44 | add_filter( 'wpml_object_id', 'icl_object_id', 10, 4 ); |
| 58 | 45 | add_filter( 'wpml_translate_single_string', array( $this, 'wpml_translate_single_string' ), 10, 4 ); |
| 59 | - // wpml_translate_string => not applicable | |
| 60 | - // wpml_unfiltered_admin_string => not implemented | |
| 46 | + // wpml_translate_string => not applicable | |
| 47 | + // wpml_unfiltered_admin_string => not implemented | |
| 61 | 48 | add_filter( 'wpml_permalink', array( $this, 'wpml_permalink' ), 10, 2 ); |
| 62 | - // wpml_elements_without_translations => not implemented | |
| 49 | + // wpml_elements_without_translations => not implemented | |
| 63 | 50 | add_filter( 'wpml_get_translated_slug', array( $this, 'wpml_get_translated_slug' ), 10, 3 ); |
| 64 | 51 | |
| 65 | 52 | // Finding the Translation State of Content |
| 66 | 53 | |
| 67 | - // wpml_element_translation_type => not implemented | |
| 54 | + // wpml_element_translation_type | |
| 68 | 55 | add_filter( 'wpml_element_has_translations', array( $this, 'wpml_element_has_translations' ), 10, 3 ); |
| 69 | - // wpml_master_post_from_duplicate => not applicable | |
| 70 | - // wpml_post_duplicates => not applicable | |
| 56 | + // wpml_master_post_from_duplicate => not applicable | |
| 57 | + // wpml_post_duplicates => not applicable | |
| 71 | 58 | |
| 72 | 59 | // Inserting Content |
| 73 | 60 | |
| 74 | - // wpml_admin_make_post_duplicates => not applicable | |
| 75 | - // wpml_make_post_duplicates => not applicable | |
| 61 | + // wpml_admin_make_post_duplicates => not applicable | |
| 62 | + // wpml_make_post_duplicates => not applicable | |
| 76 | 63 | add_action( 'wpml_register_single_string', 'icl_register_string', 10, 3 ); |
| 77 | - // wpml_register_string => not applicable | |
| 78 | - // wpml_register_string_packages => not applicable | |
| 79 | - // wpml_delete_package_action => not applicable | |
| 80 | - // wpml_show_package_language_ui => not applicable | |
| 81 | - // wpml_set_element_language_details => not implemented | |
| 82 | - // wpml_multilingual_options => not applicable | |
| 64 | + // wpml_register_string => not applicable | |
| 65 | + // wpml_register_string_packages => not applicable | |
| 66 | + // wpml_delete_package_action => not applicable | |
| 67 | + // wpml_show_package_language_ui => not applicable | |
| 68 | + // wpml_set_element_language_details => not implemented | |
| 83 | 69 | |
| 84 | 70 | // Miscellaneous |
| 85 | 71 | |
| 86 | - // wpml_element_type => not applicable | |
| 87 | - // wpml_setting => not applicable | |
| 88 | - // wpml_sub_setting => not applicable | |
| 89 | - // wpml_editor_cf_to_display => not applicable | |
| 90 | - // wpml_tm_save_translation_cf => not implemented | |
| 91 | - // wpml_tm_xliff_export_translated_cf => not applicable | |
| 92 | - // wpml_tm_xliff_export_original_cf => not applicable | |
| 93 | - // wpml_duplicate_generic_string => not applicable | |
| 94 | - // wpml_translatable_user_meta_fields => not implemented | |
| 95 | - // wpml_cross_domain_language_data => not applicable | |
| 96 | - // wpml_get_cross_domain_language_data => not applicable | |
| 97 | - // wpml_loaded => not applicable | |
| 98 | - // wpml_st_loaded => not applicable | |
| 99 | - // wpml_tm_loaded => not applicable | |
| 100 | - // wpml_hide_management_column (3.4.1) => not applicable | |
| 101 | - // wpml_ls_directories_to_scan => not applicable | |
| 102 | - // wpml_ls_model_css_classes => not applicable | |
| 103 | - // wpml_ls_model_language_css_classes => not applicable | |
| 104 | - // wpml_tf_feedback_open_link => not applicable | |
| 105 | - // wpml_sync_custom_field => not implemented | |
| 106 | - // wpml_sync_all_custom_fields => not implemented | |
| 107 | - // wpml_is_redirected => not implemented | |
| 108 | - | |
| 109 | - // Updating Content | |
| 110 | - | |
| 111 | - // wpml_set_translation_mode_for_post_type => not implemented | |
| 72 | + // wpml_element_type => not applicable | |
| 73 | + // wpml_setting => not applicable | |
| 74 | + // wpml_sub_setting => not applicable | |
| 75 | + // wpml_editor_cf_to_display => not applicable | |
| 76 | + // wpml_tm_save_translation_cf => not implemented | |
| 77 | + // wpml_tm_xliff_export_translated_cf => not applicable | |
| 78 | + // wpml_tm_xliff_export_original_cf => not applicable | |
| 79 | + // wpml_duplicate_generic_string => not applicable | |
| 80 | + // wpml_translatable_user_meta_fields => not implemented | |
| 81 | + // wpml_cross_domain_language_data => not applicable | |
| 82 | + // wpml_get_cross_domain_language_data => not applicable | |
| 83 | + // wpml_loaded => not applicable | |
| 84 | + // wpml_st_loaded => not applicable | |
| 85 | + // wpml_tm_loaded => not applicable | |
| 86 | + // wpml_hide_management_column (3.4.1) => not applicable | |
| 112 | 87 | } |
| 113 | 88 | |
| 114 | 89 | /** |
| 115 | 90 | * Get a list of the languages enabled for a site |
| @@ -149,9 +124,9 @@ | ||
| 149 | 124 | public function wpml_add_language_form_field() { |
| 150 | 125 | $lang = pll_current_language(); |
| 151 | 126 | $field = sprintf( '<input type="hidden" name="lang" value="%s" />', esc_attr( $lang ) ); |
| 152 | 127 | $field = apply_filters( 'wpml_language_form_input_field', $field, $lang ); |
| 153 | - echo $field; // phpcs:ignore WordPress.Security.EscapeOutput | |
| 128 | + echo $field; | |
| 154 | 129 | } |
| 155 | 130 | |
| 156 | 131 | /** |
| 157 | 132 | * Find out if a specific language is enabled for the site |
| @@ -179,37 +154,8 @@ | ||
| 179 | 154 | return pll_current_language( 'is_rtl' ); |
| 180 | 155 | } |
| 181 | 156 | |
| 182 | 157 | /** |
| 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 | 158 | * Get the language code for a translatable element |
| 213 | 159 | * |
| 214 | 160 | * @since 2.0 |
| 215 | 161 | * |
| @@ -220,9 +166,9 @@ | ||
| 220 | 166 | public function wpml_element_language_code( $language_code, $args ) { |
| 221 | 167 | $type = $args['element_type']; |
| 222 | 168 | $id = $args['element_id']; |
| 223 | 169 | $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 ) ) { | |
| 170 | + if ( 'term' === $pll_type && $term = wpcom_vip_get_term_by( 'term_taxonomy_id', $id ) ) { | |
| 225 | 171 | $id = $term->term_id; |
| 226 | 172 | } |
| 227 | 173 | return $pll_type ? call_user_func( "pll_get_{$pll_type}_language", $id ) : $language_code; |
| 228 | 174 | } |