| @@ -1,5 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * @package Polylang | |
| 4 | + */ | |
| 2 | 5 | |
| 3 | 6 | /** |
| 4 | 7 | * Compatibility with WPML legacy API |
| 5 | 8 | * Deprecated since WPML 3.2 and no more documented |
| @@ -55,14 +58,10 @@ | ||
| 55 | 58 | $arr = array(); |
| 56 | 59 | |
| 57 | 60 | // NB: When 'skip_missing' is false, WPML returns all languages even if there is no content |
| 58 | 61 | $languages = PLL()->model->get_languages_list( array( 'hide_empty' => $args['skip_missing'] ) ); |
| 62 | + $languages = wp_list_sort( $languages, $orderby, $order ); // Since WP 4.7 | |
| 59 | 63 | |
| 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 | - | |
| 65 | 64 | foreach ( $languages as $lang ) { |
| 66 | 65 | // We can find a translation only on frontend once the global $wp_query object has been instantiated |
| 67 | 66 | if ( method_exists( PLL()->links, 'get_translation_url' ) && ! empty( $GLOBALS['wp_query'] ) ) { |
| 68 | 67 | $url = PLL()->links->get_translation_url( $lang ); |
| @@ -79,9 +78,9 @@ | ||
| 79 | 78 | 'native_name' => $lang->name, |
| 80 | 79 | 'missing' => empty( $url ) ? 1 : 0, |
| 81 | 80 | 'translated_name' => '', // Does not exist in Polylang |
| 82 | 81 | 'language_code' => $lang->slug, |
| 83 | - 'country_flag_url' => $lang->flag_url, | |
| 82 | + 'country_flag_url' => $lang->get_display_flag_url(), | |
| 84 | 83 | 'url' => ! empty( $url ) ? $url : |
| 85 | 84 | ( empty( $args['link_empty_to'] ) ? PLL()->links->get_home_url( $lang ) : |
| 86 | 85 | str_replace( '{$lang}', $lang->slug, $args['link_empty_to'] ) ), |
| 87 | 86 | ); |
| @@ -128,9 +127,9 @@ | ||
| 128 | 127 | $text = get_the_title( $id ); |
| 129 | 128 | } |
| 130 | 129 | } elseif ( taxonomy_exists( $type ) ) { |
| 131 | 130 | $link = get_term_link( $id, $type ); |
| 132 | - if ( empty( $text ) && ( $term = get_term( $id, $type ) ) && ! empty( $term ) && ! is_wp_error( $term ) ) { | |
| 131 | + if ( empty( $text ) && ( $term = get_term( $id, $type ) ) && $term instanceof WP_Term ) { | |
| 133 | 132 | $text = $term->name; |
| 134 | 133 | } |
| 135 | 134 | } |
| 136 | 135 | |
| @@ -167,9 +166,9 @@ | ||
| 167 | 166 | * @param bool $return_original_if_missing Optional, true if Polylang should return the original id if the translation is missing, defaults to false |
| 168 | 167 | * @param string $lang Optional, language code, defaults to current language |
| 169 | 168 | * @return int|null The object id of the translation, null if the translation is missing and $return_original_if_missing set to false |
| 170 | 169 | */ |
| 171 | - function icl_object_id( $id, $type = 'post', $return_original_if_missing = false, $lang = false ) { | |
| 170 | + function icl_object_id( $id, $type = 'post', $return_original_if_missing = false, $lang = '' ) { | |
| 172 | 171 | $lang = $lang ? $lang : pll_current_language(); |
| 173 | 172 | |
| 174 | 173 | if ( 'nav_menu' === $type ) { |
| 175 | 174 | $theme = get_option( 'stylesheet' ); |
| @@ -210,9 +209,9 @@ | ||
| 210 | 209 | /** |
| 211 | 210 | * Undocumented function used by the theme Maya |
| 212 | 211 | * returns the post language |
| 213 | 212 | * |
| 214 | - * @see original WPML code at https://wpml.org/forums/topic/canonical-urls-for-wpml-duplicated-posts/#post-52198 | |
| 213 | + * @see https://wpml.org/forums/topic/canonical-urls-for-wpml-duplicated-posts/#post-52198 for the original WPML code | |
| 215 | 214 | * |
| 216 | 215 | * @since 1.8 |
| 217 | 216 | * |
| 218 | 217 | * @param null $empty optional, not used |
| @@ -239,17 +238,18 @@ | ||
| 239 | 238 | if ( ! function_exists( 'icl_register_string' ) ) { |
| 240 | 239 | /** |
| 241 | 240 | * Registers a string for translation in the "strings translation" panel |
| 242 | 241 | * |
| 242 | + * The 4th and 5th parameters $allow_empty_value and $source_lang are not used by Polylang. | |
| 243 | + * | |
| 243 | 244 | * @since 0.9.3 |
| 244 | 245 | * |
| 245 | 246 | * @param string $context the group in which the string is registered, defaults to 'polylang' |
| 246 | 247 | * @param string $name a unique name for the string |
| 247 | 248 | * @param string $string the string to register |
| 248 | - * @param bool $allow_empty_value not used | |
| 249 | - * @param string $source_lang not used by Polylang | |
| 249 | + * @return void | |
| 250 | 250 | */ |
| 251 | - function icl_register_string( $context, $name, $string, $allow_empty_value = false, $source_lang = '' ) { | |
| 251 | + function icl_register_string( $context, $name, $string ) { | |
| 252 | 252 | PLL_WPML_Compat::instance()->register_string( $context, $name, $string ); |
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | |
| @@ -260,8 +260,9 @@ | ||
| 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 | |
| 264 | 265 | */ |
| 265 | 266 | function icl_unregister_string( $context, $name ) { |
| 266 | 267 | PLL_WPML_Compat::instance()->unregister_string( $context, $name ); |
| 267 | 268 | } |
| @@ -282,9 +283,9 @@ | ||
| 282 | 283 | * @param bool $bool optional, not used |
| 283 | 284 | * @param string|null $lang optional, return the translation in this language, defaults to current language |
| 284 | 285 | * @return string the translated string |
| 285 | 286 | */ |
| 286 | - function icl_t( $context, $name, $string = false, &$has_translation = null, $bool = false, $lang = null ) { | |
| 287 | + function icl_t( $context, $name, $string = '', &$has_translation = null, $bool = false, $lang = null ) { | |
| 287 | 288 | return icl_translate( $context, $name, $string, false, $has_translation, $lang ); |
| 288 | 289 | } |
| 289 | 290 | } |
| 290 | 291 | |
| @@ -303,9 +304,9 @@ | ||
| 303 | 304 | * @param bool|null $has_translation optional, not supported in Polylang |
| 304 | 305 | * @param string|null $lang optional, return the translation in this language, defaults to current language |
| 305 | 306 | * @return string the translated string |
| 306 | 307 | */ |
| 307 | - function icl_translate( $context, $name, $string = false, $bool = false, &$has_translation = null, $lang = null ) { | |
| 308 | + function icl_translate( $context, $name, $string = '', $bool = false, &$has_translation = null, $lang = null ) { | |
| 308 | 309 | // FIXME WPML can automatically registers the string based on an option |
| 309 | 310 | if ( empty( $string ) ) { |
| 310 | 311 | $string = PLL_WPML_Compat::instance()->get_string_by_context_and_name( $context, $name ); |
| 311 | 312 | } |