PluginProbe
Polylang / 2.4
Polylang v2.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 +46 -96 2.9.22.4 View file →
@@ -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 *
@@ -23,33 +19,25 @@
23 19 // Site Wide Language informations
24 20
25 21 add_filter( 'wpml_active_languages', array( $this, 'wpml_active_languages' ), 10, 2 );
26 22 add_filter( 'wpml_display_language_names', array( $this, 'wpml_display_language_names' ), 10, 5 );
27 - // wpml_translated_language_name => not applicable
23 + // wpml_translated_language_name => not applicable
28 24 add_filter( 'wpml_current_language', 'pll_current_language', 10, 0 );
29 25 add_filter( 'wpml_default_language', 'pll_default_language', 10, 0 );
30 - // wpml_add_language_selector => not implemented
31 - // wpml_footer_language_selector => not applicable
26 + // wpml_add_language_selector => not implemented
27 + // wpml_footer_language_selector => not applicable
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 - // 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
31 + // wpml_language_form_input_field => See wpml_add_language_form_field
32 + // wpml_language_has_switched => not implemented
45 33
46 34 // Retrieving Language Information for Content
47 35
48 36 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 );
37 + // wpml_switch_language => not implemented
50 38 add_filter( 'wpml_element_language_code', array( $this, 'wpml_element_language_code' ), 10, 3 );
51 - // wpml_element_language_details => not applicable
39 + // wpml_element_language_details => not applicable
52 40
53 41 // Retrieving Localized Content
54 42
55 43 add_filter( 'wpml_home_url', 'pll_home_url', 10, 0 );
@@ -55,61 +43,49 @@
55 43 add_filter( 'wpml_home_url', 'pll_home_url', 10, 0 );
56 44 add_filter( 'wpml_element_link', 'icl_link_to_element', 10, 7 );
57 45 add_filter( 'wpml_object_id', 'icl_object_id', 10, 4 );
58 46 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
47 + // wpml_translate_string => not applicable
48 + // wpml_unfiltered_admin_string => not implemented
61 49 add_filter( 'wpml_permalink', array( $this, 'wpml_permalink' ), 10, 2 );
62 - // wpml_elements_without_translations => not implemented
50 + // wpml_elements_without_translations => not implemented
63 51 add_filter( 'wpml_get_translated_slug', array( $this, 'wpml_get_translated_slug' ), 10, 3 );
64 52
65 53 // Finding the Translation State of Content
66 54
67 - // wpml_element_translation_type => not implemented
55 + // wpml_element_translation_type
68 56 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
57 + // wpml_master_post_from_duplicate => not applicable
58 + // wpml_post_duplicates => not applicable
71 59
72 60 // Inserting Content
73 61
74 - // wpml_admin_make_post_duplicates => not applicable
75 - // wpml_make_post_duplicates => not applicable
62 + // wpml_admin_make_post_duplicates => not applicable
63 + // wpml_make_post_duplicates => not applicable
76 64 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
65 + // wpml_register_string => not applicable
66 + // wpml_register_string_packages => not applicable
67 + // wpml_delete_package_action => not applicable
68 + // wpml_show_package_language_ui => not applicable
69 + // wpml_set_element_language_details => not implemented
83 70
84 71 // Miscellaneous
85 72
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
73 + // wpml_element_type => not applicable
74 + // wpml_setting => not applicable
75 + // wpml_sub_setting => not applicable
76 + // wpml_editor_cf_to_display => not applicable
77 + // wpml_tm_save_translation_cf => not implemented
78 + // wpml_tm_xliff_export_translated_cf => not applicable
79 + // wpml_tm_xliff_export_original_cf => not applicable
80 + // wpml_duplicate_generic_string => not applicable
81 + // wpml_translatable_user_meta_fields => not implemented
82 + // wpml_cross_domain_language_data => not applicable
83 + // wpml_get_cross_domain_language_data => not applicable
84 + // wpml_loaded => not applicable
85 + // wpml_st_loaded => not applicable
86 + // wpml_tm_loaded => not applicable
87 + // wpml_hide_management_column (3.4.1) => not applicable
112 88 }
113 89
114 90 /**
115 91 * Get a list of the languages enabled for a site
@@ -125,18 +101,20 @@
125 101 }
126 102
127 103 /**
128 104 * 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.
105 + * Since Polylang does not implement the translated name, always returns only the native name
131 106 *
132 107 * @since 2.2
133 108 *
134 - * @param mixed $null Not used.
135 - * @param string $native_name The language native name.
109 + * @param mixed $null Not used.
110 + * @param string $native_name The language native name.
111 + * @param string|bool $translated_name The language translated name. Not used.
112 + * @param bool $native_hidden Whether to hide the language native name or not. Not used.
113 + * @param bool $translated_hidden Whether to hide the language translated name or not. Not used.
136 114 * @return string
137 115 */
138 - public function wpml_display_language_names( $null, $native_name ) {
116 + public function wpml_display_language_names( $null, $native_name, $translated_name = false, $native_hidden = false, $translated_hidden = false ) {
139 117 return $native_name;
140 118 }
141 119
142 120 /**
@@ -147,9 +125,9 @@
147 125 public function wpml_add_language_form_field() {
148 126 $lang = pll_current_language();
149 127 $field = sprintf( '<input type="hidden" name="lang" value="%s" />', esc_attr( $lang ) );
150 128 $field = apply_filters( 'wpml_language_form_input_field', $field, $lang );
151 - echo $field; // phpcs:ignore WordPress.Security.EscapeOutput
129 + echo $field;
152 130 }
153 131
154 132 /**
155 133 * Find out if a specific language is enabled for the site
@@ -169,44 +147,16 @@
169 147 * Find out whether the current language text direction is RTL or not
170 148 *
171 149 * @since 2.0
172 150 *
151 + * @param mixed $null Not used
173 152 * @return bool
174 153 */
175 - public function wpml_is_rtl() {
154 + public function wpml_is_rtl( $null ) {
176 155 return pll_current_language( 'is_rtl' );
177 156 }
178 157
179 158 /**
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 159 * Get the language code for a translatable element
210 160 *
211 161 * @since 2.0
212 162 *
@@ -217,9 +167,9 @@
217 167 public function wpml_element_language_code( $language_code, $args ) {
218 168 $type = $args['element_type'];
219 169 $id = $args['element_id'];
220 170 $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 ) ) {
171 + if ( 'term' === $pll_type && $term = wpcom_vip_get_term_by( 'term_taxonomy_id', $id ) ) {
222 172 $id = $term->term_id;
223 173 }
224 174 return $pll_type ? call_user_func( "pll_get_{$pll_type}_language", $id ) : $language_code;
225 175 }