PluginProbe
Polylang / 2.5.2
Polylang v2.5.2
3.8.10 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 All 234 releases
← All changes | modules/wpml/wpml-legacy-api.php +21 -23 3.0 → 2.5.2 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Compatibility with WPML legacy API
8 5 * Deprecated since WPML 3.2 and no more documented
@@ -58,10 +55,14 @@
58 55 $arr = array();
59 56
60 57 // NB: When 'skip_missing' is false, WPML returns all languages even if there is no content
61 58 $languages = PLL()->model->get_languages_list( array( 'hide_empty' => $args['skip_missing'] ) );
62 - $languages = wp_list_sort( $languages, $orderby, $order ); // Since WP 4.7
63 59
60 + // FIXME: Backward compatibility with WP < 4.7
61 + if ( function_exists( 'wp_list_sort' ) ) {
62 + $languages = wp_list_sort( $languages, $orderby, $order ); // Since WP 4.7
63 + }
64 +
64 65 foreach ( $languages as $lang ) {
65 66 // We can find a translation only on frontend once the global $wp_query object has been instantiated
66 67 if ( method_exists( PLL()->links, 'get_translation_url' ) && ! empty( $GLOBALS['wp_query'] ) ) {
67 68 $url = PLL()->links->get_translation_url( $lang );
@@ -78,9 +79,9 @@
78 79 'native_name' => $lang->name,
79 80 'missing' => empty( $url ) ? 1 : 0,
80 81 'translated_name' => '', // Does not exist in Polylang
81 82 'language_code' => $lang->slug,
82 - 'country_flag_url' => $lang->get_display_flag_url(),
83 + 'country_flag_url' => $lang->flag_url,
83 84 'url' => ! empty( $url ) ? $url :
84 85 ( empty( $args['link_empty_to'] ) ? PLL()->links->get_home_url( $lang ) :
85 86 str_replace( '{$lang}', $lang->slug, $args['link_empty_to'] ) ),
86 87 );
@@ -114,9 +115,9 @@
114 115 $type = 'post_tag';
115 116 }
116 117
117 118 $pll_type = ( 'post' == $type || pll_is_translated_post_type( $type ) ) ? 'post' : ( 'term' == $type || pll_is_translated_taxonomy( $type ) ? 'term' : false );
118 - if ( $pll_type && ( $lang = pll_current_language() ) && ( $tr_id = PLL()->model->$pll_type->get_translation( $id, $lang ) ) && ( 'term' === $pll_type || PLL()->model->post->current_user_can_read( $tr_id ) ) ) {
119 + if ( $pll_type && ( $lang = pll_current_language() ) && ( $tr_id = PLL()->model->$pll_type->get_translation( $id, $lang ) ) && ( 'term' === $pll_type || PLL()->links->current_user_can_read( $tr_id ) ) ) {
119 120 $id = $tr_id;
120 121 } elseif ( ! $return_original_if_missing ) {
121 122 return '';
122 123 }
@@ -126,10 +127,10 @@
126 127 if ( empty( $text ) ) {
127 128 $text = get_the_title( $id );
128 129 }
129 130 } elseif ( taxonomy_exists( $type ) ) {
130 - $link = get_term_link( $id, $type );
131 - if ( empty( $text ) && ( $term = get_term( $id, $type ) ) && $term instanceof WP_Term ) {
131 + $link = wpcom_vip_get_term_link( $id, $type );
132 + if ( empty( $text ) && ( $term = get_term( $id, $type ) ) && ! empty( $term ) && ! is_wp_error( $term ) ) {
132 133 $text = $term->name;
133 134 }
134 135 }
135 136
@@ -147,9 +148,9 @@
147 148
148 149 $link = sprintf( '<a href="%s">%s</a>', esc_url( $link ), esc_html( $text ) );
149 150
150 151 if ( $echo ) {
151 - echo $link; // phpcs:ignore WordPress.Security.EscapeOutput
152 + echo $link;
152 153 }
153 154
154 155 return $link;
155 156 }
@@ -166,15 +167,15 @@
166 167 * @param bool $return_original_if_missing Optional, true if Polylang should return the original id if the translation is missing, defaults to false
167 168 * @param string $lang Optional, language code, defaults to current language
168 169 * @return int|null The object id of the translation, null if the translation is missing and $return_original_if_missing set to false
169 170 */
170 - function icl_object_id( $id, $type = 'post', $return_original_if_missing = false, $lang = '' ) {
171 + function icl_object_id( $id, $type = 'post', $return_original_if_missing = false, $lang = false ) {
171 172 $lang = $lang ? $lang : pll_current_language();
172 173
173 174 if ( 'nav_menu' === $type ) {
174 175 $theme = get_option( 'stylesheet' );
175 176 if ( isset( PLL()->options['nav_menus'][ $theme ] ) ) {
176 - foreach ( PLL()->options['nav_menus'][ $theme ] as $menu ) {
177 + foreach ( PLL()->options['nav_menus'][ $theme ] as $loc => $menu ) {
177 178 if ( array_search( $id, $menu ) && ! empty( $menu[ $lang ] ) ) {
178 179 $tr_id = $menu[ $lang ];
179 180 break;
180 181 }
@@ -209,9 +210,9 @@
209 210 /**
210 211 * Undocumented function used by the theme Maya
211 212 * returns the post language
212 213 *
213 - * @see https://wpml.org/forums/topic/canonical-urls-for-wpml-duplicated-posts/#post-52198 for the original WPML code
214 + * @see original WPML code at https://wpml.org/forums/topic/canonical-urls-for-wpml-duplicated-posts/#post-52198
214 215 *
215 216 * @since 1.8
216 217 *
217 218 * @param null $empty optional, not used
@@ -238,18 +239,17 @@
238 239 if ( ! function_exists( 'icl_register_string' ) ) {
239 240 /**
240 241 * Registers a string for translation in the "strings translation" panel
241 242 *
242 - * The 4th and 5th parameters $allow_empty_value and $source_lang are not used by Polylang.
243 - *
244 243 * @since 0.9.3
245 244 *
246 245 * @param string $context the group in which the string is registered, defaults to 'polylang'
247 246 * @param string $name a unique name for the string
248 247 * @param string $string the string to register
249 - * @return void
248 + * @param bool $allow_empty_value not used
249 + * @param string $source_lang not used by Polylang
250 250 */
251 - function icl_register_string( $context, $name, $string ) {
251 + function icl_register_string( $context, $name, $string, $allow_empty_value = false, $source_lang = '' ) {
252 252 PLL_WPML_Compat::instance()->register_string( $context, $name, $string );
253 253 }
254 254 }
255 255
@@ -260,9 +260,8 @@
260 260 * @since 1.0.2
261 261 *
262 262 * @param string $context the group in which the string is registered, defaults to 'polylang'
263 263 * @param string $name a unique name for the string
264 - * @return void
265 264 */
266 265 function icl_unregister_string( $context, $name ) {
267 266 PLL_WPML_Compat::instance()->unregister_string( $context, $name );
268 267 }
@@ -283,9 +282,9 @@
283 282 * @param bool $bool optional, not used
284 283 * @param string|null $lang optional, return the translation in this language, defaults to current language
285 284 * @return string the translated string
286 285 */
287 - function icl_t( $context, $name, $string = '', &$has_translation = null, $bool = false, $lang = null ) {
286 + function icl_t( $context, $name, $string = false, &$has_translation = null, $bool = false, $lang = null ) {
288 287 return icl_translate( $context, $name, $string, false, $has_translation, $lang );
289 288 }
290 289 }
291 290
@@ -304,9 +303,9 @@
304 303 * @param bool|null $has_translation optional, not supported in Polylang
305 304 * @param string|null $lang optional, return the translation in this language, defaults to current language
306 305 * @return string the translated string
307 306 */
308 - function icl_translate( $context, $name, $string = '', $bool = false, &$has_translation = null, $lang = null ) {
307 + function icl_translate( $context, $name, $string = false, $bool = false, &$has_translation = null, $lang = null ) {
309 308 // FIXME WPML can automatically registers the string based on an option
310 309 if ( empty( $string ) ) {
311 310 $string = PLL_WPML_Compat::instance()->get_string_by_context_and_name( $context, $name );
312 311 }
@@ -325,16 +324,14 @@
325 324 *
326 325 * @return array
327 326 */
328 327 function wpml_get_copied_fields_for_post_edit() {
329 - if ( empty( $_GET['from_post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
328 + if ( empty( $_GET['from_post'] ) ) {
330 329 return array();
331 330 }
332 331
333 - $arr = array( 'original_post_id' => (int) $_GET['from_post'] ); // phpcs:ignore WordPress.Security.NonceVerification
334 -
335 332 // Don't know what WPML does but Polylang does copy all public meta keys by default
336 - foreach ( $keys = array_unique( array_keys( get_post_custom( $arr['original_post_id'] ) ) ) as $k => $meta_key ) {
333 + foreach ( $keys = array_unique( array_keys( get_post_custom( (int) $_GET['from_post'] ) ) ) as $k => $meta_key ) {
337 334 if ( is_protected_meta( $meta_key ) ) {
338 335 unset( $keys[ $k ] );
339 336 }
340 337 }
@@ -341,8 +338,9 @@
341 338
342 339 // Apply our filter and fill the expected output ( see /types/embedded/includes/fields-post.php )
343 340 /** This filter is documented in modules/sync/admin-sync.php */
344 341 $arr['fields'] = array_unique( apply_filters( 'pll_copy_post_metas', empty( $keys ) ? array() : $keys, false ) );
342 + $arr['original_post_id'] = (int) $_GET['from_post'];
345 343 return $arr;
346 344 }
347 345 }
348 346