icl_get_languages

The Polylang icl get languages function.

Description

icl_get_languages( (string) $args = '' ); 

Parameters (1)

0. $args — Optional. (string) => ''
The args.

Usage

  1. if ( !function_exists( 'icl_get_languages' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'polylang/modules/wpml/wpml-legacy-api.php'; 
  3.  
  4. // The args. 
  5. $args = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = icl_get_languages($args); 
  9.  

Defined (1)

The function is defined in the following location(s).

/modules/wpml/wpml-legacy-api.php  
  1. function icl_get_languages( $args = '' ) { 
  2. $args = wp_parse_args( $args, array( 'skip_missing' => 0, 'orderby' => 'id', 'order' => 'ASC' ) ); 
  3. $orderby = ( isset( $args['orderby'] ) && 'code' == $args['orderby'] ) ? 'slug' : ( isset( $args['orderby'] ) && 'name' == $args['orderby'] ? 'name' : 'id' ); 
  4. $order = ( ! empty( $args['order'] ) && 'desc' == $args['order'] ) ? 'DESC' : 'ASC'; 
  5.  
  6. $arr = array(); 
  7.  
  8. foreach ( PLL()->model->get_languages_list( array( 'hide_empty' => true, 'orderby' => $orderby, 'order' => $order ) ) as $lang ) { 
  9. // We can find a translation only on frontend 
  10. if ( method_exists( PLL()->links, 'get_translation_url' ) ) { 
  11. $url = PLL()->links->get_translation_url( $lang ); 
  12.  
  13. // It seems that WPML does not bother of skip_missing parameter on admin side and before the $wp_query object has been filled 
  14. if ( empty( $url ) && ! empty( $args['skip_missing'] ) && ! is_admin() && did_action( 'parse_query' ) ) { 
  15. continue; 
  16.  
  17. $arr[ $lang->slug ] = array( 
  18. 'id' => $lang->term_id,  
  19. 'active' => isset( PLL()->curlang->slug ) && PLL()->curlang->slug == $lang->slug ? 1 : 0,  
  20. 'native_name' => $lang->name,  
  21. 'missing' => empty( $url ) ? 1 : 0,  
  22. 'translated_name' => '', // Does not exist in Polylang 
  23. 'language_code' => $lang->slug,  
  24. 'country_flag_url' => $lang->flag_url,  
  25. 'url' => ! empty( $url ) ? $url : 
  26. ( empty( $args['link_empty_to'] ) ? PLL()->links->get_home_url( $lang ) : 
  27. str_replace( '{$lang}', $lang->slug, $args['link_empty_to'] ) ),  
  28. ); 
  29. return $arr;