get_current_language();
return $sitepress->language_url( $current_language );
}
/**
* Get the home url in the current language
* To be used in place of get_option('home')
* Note: Good code will make use of get_home_url() or home_url() which apply filters natively.
* In this case there is no need to replace anything.
*
* @return string
* @since 3.2
* @uses \SitePress::api_hooks
*/
function wpml_get_home_url_filter() {
global $sitepress;
$current_language = $sitepress->get_current_language();
return $sitepress->language_url( $current_language );
}
/**
* @since unknown
* @deprecated 3.2 use 'wpml_active_languages' filter instead.
*
* @param string $a
*
* @return mixed
*/
function icl_get_languages( $a = '' ) {
if ( $a ) {
parse_str( $a, $args );
} else {
$args = '';
}
global $sitepress;
$langs = $sitepress->get_ls_languages( $args );
return $langs;
}
/**
* Get a list of the active languages
* Usually used to create custom language switchers
*
* @param mixed $empty_value This is normally the value the filter will be modifying.
* We are not filtering anything here therefore the NULL value
* This for the filter function to actually receive the full argument list:
* apply_filters( 'wpml_active_languages', '', $args)
* @param array|string $args {
* Optional A string of arguments to filter the language output
*
* @type bool $skip_missing How to treat languages with no translations. 0 | Skip language or 1 | Link to home of language for missing translations.
* @type string $link_empty_to Works in conjunction with skip_missing = 0 and allows using custom links for the languages that do not have translations
* for the current element. {%lang} can be used as placeholder for the language code. Empty by default.
* @type string $orderby Accepts id|code|name Defaults to custom.
* The custom order can be defined in the WordPress admin under WPML > Languages > Language Switcher Options
* @type string $order Accepts asc|desc
* }
* @return array
* @since 3.2
*
* @uses \SitePress::api_hooks
*/
function wpml_get_active_languages_filter( $empty_value, $args = '' ) {
global $sitepress;
$args = wp_parse_args( $args );
return $sitepress->get_ls_languages( $args );
}
/**
* @param string $native_name
* @param bool $translated_name
* @param bool $lang_native_hidden
* @param bool $lang_translated_hidden
*
* @return string
* @deprecated 3.2 use 'wpml_display_language_names' filter instead.
*
* @since unknown
*/
function icl_disp_language( $native_name, $translated_name = false, $lang_native_hidden = false, $lang_translated_hidden = false ) {
$language_switcher = new SitePressLanguageSwitcher();
return $language_switcher->language_display( $native_name, $translated_name, ! $lang_native_hidden, ! $lang_translated_hidden );
}
/**
* @param mixed $empty_value
*
* @param string $native_name Required The language native name
* @param string|bool $translated_name Required The language translated name Defaults to FALSE
* @param bool $lang_native_hidden Optional, default is FALSE 0|false or 1|true Whether to hide the language native name or not.
* @param bool $lang_translated_hidden Optional, default is FALSE 0|false or 1|true Whether to hide the language translated name or not.
*
* @return string HTML content
* @deprecated since 3.6.0 / See new Language Switcher API with use of Twig templates
*
* Get the native or translated language name or both
* Checks if native_language_name and translated_language_name are different.
* If so, it returns them both, otherwise, it returns only one.
* Usually used in custom language switchers
* @since 3.2
*
* @see \wpml_get_active_languages_filter
*
* @uses \SitePress::api_hooks
*/
function wpml_display_language_names_filter( $empty_value, $native_name, $translated_name = false, $lang_native_hidden = false, $lang_translated_hidden = false ) {
$language_switcher = new SitePressLanguageSwitcher();
return $language_switcher->language_display( $native_name, $translated_name, ! $lang_native_hidden, ! $lang_translated_hidden );
}
/**
* @param int $element_id
* @param string $element_type
* @param string $link_text
* @param array $optional_parameters
* @param string $anchor
* @param bool $echo
* @param bool $return_original_if_missing
*
* @return string
* @since unknown
* @deprecated 3.2 use 'wpml_element_link' filter instead.
*
*/
function icl_link_to_element(
$element_id,
$element_type = 'post',
$link_text = '',
$optional_parameters = array(),
$anchor = '',
$echo = true,
$return_original_if_missing = true
) {
return wpml_link_to_element_filter(
$element_id,
$element_type,
$link_text,
$optional_parameters,
$anchor,
$echo,
$return_original_if_missing
);
}
/**
* Get the link to an element in the current language
* Produces localized links for WordPress elements (post types and taxonomy terms)
*
* @param int $element_id Required The ID of the post type (post, page) or taxonomy term (tag or category) to link to.
* @param string $element_type Optional The type of element to link to. Can be 'post', 'page', 'tag' or 'category'. Defaults to 'post'
* @param string $link_text Optional The link text. Defaults to the element's name.
* @param array $optional_parameters Optional Arguments for the link.
* @param string $anchor Optional Anchor for the link.
* @param bool $echo Optional 0|false to return or 1|true to echo the localized link. Defaults to true.
* @param bool $return_original_if_missing Optional, default is TRUE If set to true it will always return a value (the original value, if translation is missing)
*
* @return string HTML content
* @since 3.2
*
* @uses \SitePress::api_hooks
*/
function wpml_link_to_element_filter(
$element_id, $element_type = 'post', $link_text = '', $optional_parameters = array(), $anchor = '', $echo = true, $return_original_if_missing = true
) {
global $sitepress, $wpdb, $wp_post_types, $wp_taxonomies;
if ( $element_type == 'tag' ) {
$element_type = 'post_tag';
}
if ( $element_type == 'page' ) {
$element_type = 'post';
}
$post_types = array_keys( (array) $wp_post_types );
$taxonomies = array_keys( (array) $wp_taxonomies );
if ( in_array( $element_type, $taxonomies ) ) {
$element_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id= %d AND taxonomy=%s", $element_id, $element_type ) );
} elseif ( in_array( $element_type, $post_types ) ) {
$element_type = 'post';
}
if ( ! $element_id ) {
return '';
}
if ( in_array( $element_type, $taxonomies ) ) {
$icl_element_type = 'tax_' . $element_type;
} elseif ( in_array( $element_type, $post_types ) ) {
$icl_element_type = 'post_' . $wpdb->get_var(
$wpdb->prepare(
"SELECT post_type
FROM {$wpdb->posts}
WHERE ID = %d",
$element_id
)
);
} else {
return '';
}
$trid = $sitepress->get_element_trid( $element_id, $icl_element_type );
$translations = $sitepress->get_element_translations( $trid, $icl_element_type );
// current language is ICL_LANGUAGE_CODE
if ( isset( $translations[ ICL_LANGUAGE_CODE ] ) ) {
if ( $element_type == 'post' ) {
$url = get_permalink( $translations[ ICL_LANGUAGE_CODE ]->element_id );
$title = $translations[ ICL_LANGUAGE_CODE ]->post_title;
} elseif ( $element_type == 'post_tag' ) {
list( $term_id, $title ) = $wpdb->get_row( $wpdb->prepare( "SELECT t.term_id, t.name FROM {$wpdb->term_taxonomy} tx JOIN {$wpdb->terms} t ON t.term_id = tx.term_id WHERE tx.term_taxonomy_id = %d AND tx.taxonomy='post_tag'", $translations[ ICL_LANGUAGE_CODE ]->element_id ), ARRAY_N );
$url = get_tag_link( $term_id );
$title = apply_filters( 'single_cat_title', $title );
} elseif ( $element_type == 'category' ) {
list( $term_id, $title ) = $wpdb->get_row( $wpdb->prepare( "SELECT t.term_id, t.name FROM {$wpdb->term_taxonomy} tx JOIN {$wpdb->terms} t ON t.term_id = tx.term_id WHERE tx.term_taxonomy_id = %d AND tx.taxonomy='category'", $translations[ ICL_LANGUAGE_CODE ]->element_id ), ARRAY_N );
$url = get_category_link( $term_id );
$title = apply_filters( 'single_cat_title', $title );
} else {
list( $term_id, $title ) = $wpdb->get_row( $wpdb->prepare( "SELECT t.term_id, t.name FROM {$wpdb->term_taxonomy} tx JOIN {$wpdb->terms} t ON t.term_id = tx.term_id WHERE tx.term_taxonomy_id = %d AND tx.taxonomy=%s", $translations[ ICL_LANGUAGE_CODE ]->element_id, $element_type ), ARRAY_N );
$url = get_term_link( $term_id, $element_type );
$title = apply_filters( 'single_cat_title', $title );
}
} else {
if ( ! $return_original_if_missing ) {
if ( $echo ) {
echo '';
}
return '';
}
if ( $element_type == 'post' ) {
$url = get_permalink( $element_id );
$title = get_the_title( $element_id );
} elseif ( $element_type == 'post_tag' ) {
$url = get_tag_link( $element_id );
$my_tag = &get_term( $element_id, 'post_tag', OBJECT, 'display' );
$title = apply_filters( 'single_tag_title', $my_tag->name );
} elseif ( $element_type == 'category' ) {
$url = get_category_link( $element_id );
$my_cat = &get_term( $element_id, 'category', OBJECT, 'display' );
$title = apply_filters( 'single_cat_title', $my_cat->name );
} else {
$url = get_term_link( (int) $element_id, $element_type );
$my_cat = &get_term( $element_id, $element_type, OBJECT, 'display' );
$title = apply_filters( 'single_cat_title', $my_cat->name );
}
}
if ( ! $url || is_wp_error( $url ) ) {
return '';
}
if ( ! empty( $optional_parameters ) ) {
$url_glue = false === strpos( $url, '?' ) ? '?' : '&';
$url .= $url_glue . http_build_query( $optional_parameters );
}
if ( $anchor ) {
$url .= '#' . $anchor;
}
$link = '';
if ( $link_text ) {
$link .= esc_html( $link_text );
} else {
$link .= esc_html( $title );
}
$link .= '';
if ( $echo ) {
echo $link;
}
return $link;
}
/**
* @param int $element_id
* @param string $element_type
* @param bool $return_original_if_missing
* @param null|string $ulanguage_code
*
* @return null|int
* @deprecated 3.2 use 'wpml_object_id' filter instead.
*
* @since unknown
*/
function icl_object_id( $element_id, $element_type = 'post', $return_original_if_missing = false, $ulanguage_code = null ) {
return wpml_object_id_filter( $element_id, $element_type, $return_original_if_missing, $ulanguage_code );
}
/**
* @since 3.1.6
* @deprecated @since 3.2: use 'wpml_object_id' with the same arguments
* @uses \SitePress::api_hooks
*/
add_filter( 'translate_object_id', 'icl_object_id', 10, 4 );
/**
* Get the element in the current language
*
* @param int $element_id Use term_id for taxonomies, post_id for posts
* @param string $element_type Use post, page, {custom post type name}, nav_menu, nav_menu_item, category, tag, etc.
* You can also pass 'any', to let WPML guess the type, but this will only work for posts.
* @param bool $return_original_if_missing Optional, default is FALSE. If set to true it will always return a value (the original value, if translation is missing).
* @param string|NULL $language_code Optional, default is NULL. If missing, it will use the current language.
* If set to a language code, it will return a translation for that language code or
* the original if the translation is missing and $return_original_if_missing is set to TRUE.
*
* @return int|NULL
* @since 3.2
*
* @uses \SitePress::api_hooks
*/
function wpml_object_id_filter( $element_id, $element_type = 'post', $return_original_if_missing = false, $language_code = null ) {
global $sitepress;
return $sitepress->get_object_id( $element_id, $element_type, $return_original_if_missing, $language_code );
}
/**
* @param string $lang_code
* @param bool $display_code
*
* @return string
* @deprecated 3.2 use 'wpml_translated_language_name' filter instead
*
* @since unknown
*/
function icl_get_display_language_name( $lang_code, $display_code = false ) {
global $sitepress;
return $sitepress->get_display_language_name( $lang_code, $display_code );
}
/**
* Returns the translated name of a language in another language.
* The languages involved do not need to be active.
*
* @param mixed $empty_value
*
* @param string $lang_code The language name will be for this language. Accepts a 2-letter code e.g. en
* @param string|bool $display_code The language name will display translated in this language. Accepts a 2-letter code e.g. de.
* If set to false it will return the translated name in the current language. Default is FALSE.
*
* @return string The language translated name
* @see \wpml_get_active_languages_filter
*
* @since 3.2
*
* @uses \SitePress::api_hooks
*/
function wpml_translated_language_name_filter( $empty_value, $lang_code, $display_code = false ) {
global $sitepress;
return $sitepress->get_display_language_name( $lang_code, $display_code );
}
/**
* @since unknown
* @deprecated 3.2 use 'wpml_current_language' filter instead.
*/
function icl_get_current_language() {
return apply_filters( 'wpml_current_language', '' );
}
/**
* Get the current language
*
* @since 3.2
* @deprecated Use apply_filters('wpml_current_language', '');
* Example: $my_current_lang = apply_filters('wpml_current_language', '');
*/
function wpml_get_current_language_filter() {
return wpml_get_current_language();
}
/**
* @since unknown
* @deprecated 3.2 use 'wpml_default_language' filter instead
*/
function icl_get_default_language() {
global $sitepress;
return $sitepress->get_default_language();
}
/**
* Get the default language
*
* @param mixed $empty_value
*
* @return string
* @see \wpml_get_active_languages_filter
* @uses \SitePress::api_hooks
* @since 3.2
*
*/
function wpml_get_default_language_filter( $empty_value ) {
return wpml_get_default_language();
}
/**
* Returns the default language
*
* @since 1.3
* @return string
*/
function wpml_get_default_language() {
global $sitepress;
return $sitepress->get_default_language();
}
/**
* Get current language
*
* @since 1.3
* @return string
*/
function wpml_get_current_language() {
return apply_filters( 'wpml_current_language', '' );
}
/**
* @param string $folder
*
* @return bool
*/
function icl_tf_determine_mo_folder( $folder ) {
global $sitepress;
$mo_file_search = new WPML_MO_File_Search( $sitepress );
return $mo_file_search->determine_mo_folder( $folder );
}
/**
* @todo: [WPML 3.3] refactor in 3.3
*
* @param array $attributes
* @param bool $checked
* @param bool $disabled
*
* @return string
*/
// $field_prefix = 'wpml_cf_translation_preferences_option_ignore_'
function wpml_input_field_helper( $attributes = array(), $checked = false, $disabled = false ) {
if ( $disabled ) {
$attributes['readonly'] = 'readonly';
$attributes['disabled'] = 'disabled';
}
if ( $checked && array_key_exists( 'type', $attributes ) && in_array( $attributes['type'], array( 'checkbox', 'radio' ) ) ) {
$attributes['checked'] = 'checked';
}
$html_attributes = array();
if ( is_array( $attributes ) ) {
foreach ( $attributes as $attribute => $attribute_value ) {
if ( $attribute != 'custom' ) {
$html_attributes[] = strip_tags( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
} else {
$html_attributes[] = esc_attr( $attribute_value );
}
}
}
$output = '';
$output .= ' $attributes
* @param string $caption
*
* @return string
* @todo: [WPML 3.3] refactor in 3.3
*
*/
function wpml_label_helper( $attributes, $caption ) {
$html_attributes = array();
if ( is_array( $attributes ) ) {
foreach ( $attributes as $attribute => $attribute_value ) {
if ( $attribute != 'custom' ) {
$html_attributes[] = strip_tags( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
} else {
$html_attributes[] = esc_attr( $attribute_value );
}
}
}
$output = '';
$output .= '