: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @deprecated 3.2 use 'wpml_element_translation_type' filter instead
function wpml_get_translation_type( $id, $type = 'post' ) {
$translation_type = WPML_ELEMENT_IS_NOT_TRANSLATED;
$translation_type = wpml_post_has_translations( $id );
//TODO: [WPML 3.3] handle other element types (e.g. taxonomies, strings, etc.)
return $translation_type;
* Accepts the ID and type of an element and returns its translation type.
* Values will be one of these:
* WPML_ELEMENT_IS_NOT_TRANSLATED = 0
* WPML_ELEMENT_IS_TRANSLATED = 1
* WPML_ELEMENT_IS_DUPLICATED = 2
* WPML_ELEMENT_IS_A_DUPLICATE = 3
* @param mixed $empty_value
* @see \wpml_get_active_languages_filter
* @param int $element_id The element id to retrieve the information of. Use term_id for taxonomies, post_id for posts
* @param string $element_type Can be a post type: post, page, attachment, nav_menu_item, {custom post key}
* or taxonomy: category, post_tag, nav_menu {custom taxonomy key}
* @use \SitePress::api_hooks
function wpml_get_element_translation_type_filter( $empty_value, $element_id, $element_type ) {
$translation_type = WPML_ELEMENT_IS_NOT_TRANSLATED;
$element_has_translations = apply_filters( 'wpml_element_has_translations', null, $element_id, $element_type );
$element_is_master = apply_filters( 'wpml_master_post_from_duplicate', $element_id );
$element_is_duplicate = apply_filters( 'wpml_post_duplicates', $element_id );
if ( $element_has_translations ) {
$translation_type = WPML_ELEMENT_IS_TRANSLATED;
if ( $element_is_master ) {
$translation_type = WPML_ELEMENT_IS_A_DUPLICATE;
} elseif ( $element_is_duplicate ) {
$translation_type = WPML_ELEMENT_IS_DUPLICATED;
return $translation_type;
* Accepts the ID of a post and returns its translation type.
* Values will be one of these:
* WPML_ELEMENT_IS_NOT_TRANSLATED = 0
* WPML_ELEMENT_IS_TRANSLATED = 1
* WPML_ELEMENT_IS_DUPLICATED = 2
* WPML_ELEMENT_IS_A_DUPLICATE = 3
* @param int $post_id The ID of the post from which to get translation information
* @internal param string $post_type
* @deprecated 3.2 use 'wpml_element_translation_type' filter instead
function wpml_get_post_translation_type( $post_id ) {
$translation_type = WPML_ELEMENT_IS_NOT_TRANSLATED;
$post_type = get_post_type( $post_id );
if ( wpml_post_has_translations( $post_id, $post_type ) ) {
$translation_type = WPML_ELEMENT_IS_TRANSLATED;
if ( wpml_get_master_post_from_duplicate( $post_id ) ) {
$translation_type = WPML_ELEMENT_IS_A_DUPLICATE;
} elseif ( wpml_get_post_duplicates( $post_id ) ) {
$translation_type = WPML_ELEMENT_IS_DUPLICATED;
return $translation_type;
* @param string $post_type
* @deprecated 3.2 use 'wpml_element_has_translations' filter instead
function wpml_post_has_translations( $post_id, $post_type = 'post' ) {
$has_translations = false;
if ( isset( $sitepress ) ) {
$trid = $sitepress->get_element_trid( $post_id, 'post_' . $post_type );
$translations = $sitepress->get_element_translations( $trid );
if ( $translations && count( $translations ) > 1 ) {
$has_translations = true;
return $has_translations;
* Checks if an element has translations
* A translation can be a manual translation or a duplication.
* @param mixed $empty_value
* @see \wpml_get_active_languages_filter
* @param int $element_id Use term_id for taxonomies, post_id for posts
* @param string $element_type Can be a post type: post, page, attachment, nav_menu_item, {custom post key}
* or taxonomy: category, post_tag, nav_menu {custom taxonomy key}
* @use \SitePress::api_hooks
function wpml_element_has_translations_filter( $empty_value, $element_id, $element_type = 'post' ) {
$has_translations = false;
if ( isset( $sitepress ) ) {
$wpml_element_type = apply_filters( 'wpml_element_type', $element_type );
if ( strpos( $wpml_element_type, 'tax_' ) === 0 ) {
/** @var WPML_Term_Translation $wpml_term_translations*/
global $wpml_term_translations;
$element_id = $wpml_term_translations->adjust_ttid_for_term_id( $element_id );
$trid = $sitepress->get_element_trid( $element_id, $wpml_element_type );
$translations = apply_filters( 'wpml_get_element_translations_filter', '', $trid, $wpml_element_type );
if ( $translations && count( $translations ) > 1 ) {
$has_translations = true;
return $has_translations;
function wpml_get_content_translations_filter( $empty, $post_id, $content_type = 'post' ) {
if ( isset( $sitepress ) ) {
$wpml_element_type = apply_filters( 'wpml_element_type', $content_type );
$trid = $sitepress->get_element_trid( $post_id, $wpml_element_type );
$translations = apply_filters( 'wpml_get_element_translations', null, $trid, $wpml_element_type );
* @deprecated 3.2 use 'wpml_master_post_from_duplicate' filter instead
function wpml_get_master_post_from_duplicate( $post_id ) {
return get_post_meta( $post_id, '_icl_lang_duplicate_of', true );
* Get the original post from the duplicated post
* @param int $post_id The duplicated post ID
* @return int or empty string if there is nothing to return
* @use \SitePress::api_hooks
function wpml_get_master_post_from_duplicate_filter( $post_id ) {
return get_post_meta( $post_id, '_icl_lang_duplicate_of', true );
* @deprecated 3.2 use 'wpml_post_duplicates' filter instead
function wpml_get_post_duplicates( $master_post_id ) {
if ( isset( $sitepress ) ) {
return $sitepress->get_duplicates( $master_post_id );
* Get the duplicated post ids
* Will return an associative array with language codes as indexes and post_ids as values
* @param int $master_post_id The original post id from which duplicates exist
* @use \SitePress::api_hooks
function wpml_get_post_duplicates_filter( $master_post_id ) {
if ( isset( $sitepress ) ) {
return $sitepress->get_duplicates( $master_post_id );
* Filters a WordPress element by adding the WPML prefix 'post_', 'tax_', or nothing for 'comment' as used in icl_translations db table
* @param string $element_type Accepts comment, post, page, attachment, nav_menu_item, {custom post key},
* nav_menu, category, post_tag, {custom taxonomy key}
* @use \SitePress::api_hooks
function wpml_element_type_filter( $element_type ) {
global $wp_post_types, $wp_taxonomies;
$post_types = array_keys( (array) $wp_post_types );
$taxonomies = array_keys( (array) $wp_taxonomies );
if ( in_array( $element_type, $taxonomies ) ) {
$wpml_element_type = 'tax_' . $element_type;
} elseif ( in_array( $element_type, $post_types ) ) {
$wpml_element_type = 'post_' . $element_type;
$wpml_element_type = $element_type;
return $wpml_element_type;
* Retrieves language information for a translatable element
* Checks icl_translations db table and returns an object with the element's
* trid, source language code and language code
* @param mixed $element_object A WordPress object. Defaults to null
* Required An array of arguments to be used
* @type int $element_id Use term_taxonomy_id for taxonomies, post_id for posts
* @type string $element_type Can be a post type: post, page, attachment, nav_menu_item, {custom post key}
* or taxonomy: category, post_tag, nav_menu {custom taxonomy key}
* @use \SitePress::api_hooks
function wpml_element_language_details_filter($element_object = null, $args) {
$element_type = apply_filters( 'wpml_element_type', $args[ 'element_type' ] );
$element_object = $sitepress->get_element_language_details( $args[ 'element_id' ], $element_type );
* Retrieves the language code for a translatable element
* Checks icl_translations db table and returns the element's language code
* @param mixed $language_code A 2-letter language code. Defaults to null
* Required An array of arguments to be used
* @type int $element_id Use term_taxonomy_id for taxonomies, post_id for posts
* @type string $element_type Can be a post type: post, page, attachment, nav_menu_item, {custom post key}
* or taxonomy: category, post_tag, nav_menu {custom taxonomy key}
* @use \SitePress::api_hooks
function wpml_element_language_code_filter($language_code = null, $args) {
$element_type = apply_filters( 'wpml_element_type', $args[ 'element_type' ] );
$language_code = $sitepress->get_language_for_element( $args[ 'element_id' ], $element_type );
* Retrieves the elements without translations
* Queries the database and returns an array with ids
* @param array $element_ids An array of element ids. Defaults to an empty array
* Required An array of arguments to be used
* @type string $target_language The target language code
* @type string $source_language The source language code
* @type string $element_type Can be a post type: post, page, attachment, nav_menu_item, {custom post key}
* or taxonomy: category, post_tag, nav_menu {custom taxonomy key}
* @use \SitePress::api_hooks
function wpml_elements_without_translations_filter($element_ids = array(), $args) {
$element_type = apply_filters( 'wpml_element_type', $args[ 'element_type' ] );
$element_ids = $sitepress->get_elements_without_translations( $element_type, $args[ 'target_language' ], $args[ 'source_language' ] );
* @deprecated Use the filter hook `wpml_permalink` instead
* Filters a WordPress permalink and converts it to a language specific permalink based on plugin settings
* @param string $url The WordPress generated url to filter
* @param null|string $language_code if null, it falls back to default language for root page,
* or current language in all other cases.
function wpml_permalink_filter( $url, $language_code = null ) {
return apply_filters( 'wpml_permalink', $url, $language_code );
* Switches WPML's query language
* @type null|string $language_code The language code to switch to
* If set to null it restores the original language
* If set to 'all' it will query content from all active languages
* @use \SitePress::api_hooks
function wpml_switch_language_action($language_code = null) {
$sitepress->switch_lang( $language_code, true );