: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @todo: [WPML 3.3] refactor in 3.3
* @param array $attributes
//$field_prefix = 'wpml_cf_translation_preferences_option_ignore_'
function wpml_input_field_helper( $attributes = array(), $checked = false, $disabled = false ) {
$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 ) . '"';
$html_attributes[ ] = esc_attr( $attribute_value );
$output = '<!-- OK! -->';
if ( $html_attributes ) {
$output .= ' ' . join( ' ', $html_attributes );
* @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 ) . '"';
$html_attributes[ ] = esc_attr( $attribute_value );
$output = '<!-- OK! -->';
if ( $html_attributes ) {
$output .= ' ' . join( ' ', $html_attributes );
$output .= '>' . $caption . '</label>';
* @todo: [WPML 3.3] refactor in 3.3
function wpml_translation_preference_input_helper( $args, $id_prefix, $value, $caption ) {
$input_attributes = $args[ 'input_attributes' ];
$label_attributes = $args[ 'label_attributes' ];
$action = $args[ 'action' ];
$input_attributes[ 'id' ] = $id_prefix . $id;
$input_attributes[ 'value' ] = $value;
$label_attributes[ 'for' ] = $input_attributes[ 'id' ];
$output .= wpml_input_field_helper( $input_attributes, ( $value == $action ), $args[ 'disabled' ] );
$output .= wpml_label_helper( $label_attributes, $caption );
* @todo: [WPML 3.3] refactor in 3.3
* @param bool $custom_field
* @param string $default_value
* @param bool $suppress_error
function wpml_cf_translation_preferences( $id, $custom_field = false, $class = 'wpml', $ajax = false, $default_value = 'ignore', $fieldset = false, $suppress_error = false ) {
global $iclTranslationManagement;
if ( isset( $iclTranslationManagement ) ) {
$section = 'custom_fields';
$config_section = $iclTranslationManagement->get_translation_setting_name( $section );
$readonly_config_section = $iclTranslationManagement->get_readonly_translation_setting_name( $section );
$custom_field = @strval( $custom_field );
$class = @strval( $class );
<fieldset id="wpml_cf_translation_preferences_fieldset_' . $id . '" class="wpml_cf_translation_preferences_fieldset ' . $class . '-form-fieldset form-fieldset fieldset">' . '<legend>' . __( 'Translation preferences', 'sitepress' ) . '</legend>';
$actions = array( 'ignore' => 0, 'copy' => 1, 'translate' => 2, 'copy-once' => 3 );
$action = isset( $actions[ @strval( $default_value ) ] ) ? $actions[ @strval( $default_value ) ] : 0;
if ( defined( 'WPML_TM_VERSION' ) && ! empty( $iclTranslationManagement ) ) {
$custom_fields_settings = $iclTranslationManagement->settings[ $config_section ];
if ( isset( $custom_fields_settings[ $custom_field ] ) ) {
$action = intval( $custom_fields_settings[ $custom_field ] );
$custom_fields_readonly_settings = $iclTranslationManagement->settings[ $readonly_config_section ];
$custom_fields_readonly_settings = isset( $custom_fields_readonly_settings ) ? $custom_fields_readonly_settings : array();
$xml_override = in_array( $custom_field, $custom_fields_readonly_settings );
$disabled = $xml_override;
'<div style="color:Red;font-style:italic;margin: 10px 0 0 0;">'
. __( 'The translation preference for this field are being controlled by a language configuration XML file. If you want to control it manually, remove the entry from the configuration file.', 'sitepress' )
} else if ( ! $suppress_error ) {
$output .= '<span style="color:#FF0000;">' . __( "To synchronize values for translations, you need to enable WPML's Translation Management module.", 'sitepress' ) . '</span>';
} else if ( ! $suppress_error ) {
$output .= '<span style="color:#FF0000;">' . __( 'Error: Something is wrong with field value. Translation preferences can not be set.', 'sitepress' ) . '</span>';
//$disabled = !empty($disabled) ? ' readonly="readonly" disabled="disabled"' : '';
$output .= '<div class="description ' . $class . '-form-description ' . $class . '-form-description-fieldset description-fieldset">' . __( 'Choose what to do when translating content with this field:', 'sitepress' ) . '</div>';
$input_attributes = array(
'name' => 'wpml_cf_translation_preferences[' . $id . ']',
'class' => $class . '-form-radio form-radio radio',
$label_attributes = array(
'class' => $class . '-form-label ' . $class . '-form-radio-label',
'input_attributes' => $input_attributes,
'label_attributes' => $label_attributes,
$output .= wpml_translation_preference_input_helper( $args, 'wpml_cf_translation_preferences_option_ignore_', WPML_IGNORE_CUSTOM_FIELD, __( "Don't translate", 'sitepress' ) );
$output .= wpml_translation_preference_input_helper( $args, 'wpml_cf_translation_preferences_option_copy_', WPML_COPY_CUSTOM_FIELD, __( "Copy from original to translation", 'sitepress' ) );
$output .= wpml_translation_preference_input_helper( $args, 'wpml_cf_translation_preferences_option_copy_once_', WPML_COPY_ONCE_CUSTOM_FIELD, __( "Copy once", 'sitepress' ) );
$output .= wpml_translation_preference_input_helper( $args, 'wpml_cf_translation_preferences_option_translate_', WPML_TRANSLATE_CUSTOM_FIELD, __( "Translate", 'sitepress' ) );
if ( $custom_field && $ajax ) {
<div style=";margin: 5px 0 5px 0;" id="wpml_cf_translation_preferences_ajax_response_' . $id . '"></div>
<input type="button" onclick="icl_cf_translation_preferences_submit(\'' . $id . '\', jQuery(this));" style="margin-top:5px;" class="button-secondary" value="' . __( 'Apply' ) . '" name="wpml_cf_translation_preferences_submit_' . $id . '" />
<input type="hidden" name="wpml_cf_translation_preferences_data_' . $id . '" value="custom_field=' . $custom_field . '&_icl_nonce=' . wp_create_nonce( 'wpml_cf_translation_preferences_nonce' ) . '" />';
* @todo: [WPML 3.3] refactor in 3.3
* wpml_get_copied_fields_for_post_edit
* return a list of fields that are marked for copying and the
* original post id that the fields should be copied from
* This should be used to populate any custom field controls when
* a new translation is selected and the field is marked as "copy" (sync)
function wpml_get_copied_fields_for_post_edit( $fields = array() ) {
global $sitepress, $wpdb, $sitepress_settings, $pagenow;
$copied_cf = array( 'fields' => array() );
if ( defined( 'WPML_TM_VERSION' ) ) {
if ( ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
if ( isset( $_GET[ 'trid' ] ) ) {
$post_type = isset( $_GET[ 'post_type' ] ) ? $_GET[ 'post_type' ] : 'post';
$translations = $sitepress->get_element_translations( $_GET[ 'trid' ], 'post_' . $post_type );
$source_lang = isset( $_GET[ 'source_lang' ] ) ? $_GET[ 'source_lang' ] : $sitepress->get_default_language();
$lang_details = $sitepress->get_language_details( $source_lang );
} else if ( $post_id = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT ) ) {
$post_type = $wpdb->get_var( $wpdb->prepare( "SELECT post_type FROM {$wpdb->posts} WHERE ID = %d", $post_id ) );
$trid = $sitepress->get_element_trid( $post_id, 'post_' . $post_type );
$original_id = $wpdb->get_var( $wpdb->prepare( "SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE source_language_code IS NULL AND trid=%d", $trid ) );
if ( $original_id != $post_id ) {
// Only return information if this is not the source language post.
$translations = $sitepress->get_element_translations( $trid, 'post_' . $post_type );
$source_lang = $wpdb->get_var( $wpdb->prepare( "SELECT language_code FROM {$wpdb->prefix}icl_translations WHERE source_language_code IS NULL AND trid=%d", $trid ) );
$lang_details = $sitepress->get_language_details( $source_lang );
if ( $translations && isset( $source_lang ) ) {
$original_custom = get_post_custom( $translations[ $source_lang ]->element_id );
$copied_cf[ '_wpml_original_post_id' ] = $translations[ $source_lang ]->element_id;
$ccf_note = '<img src="' . ICL_PLUGIN_URL . '/res/img/alert.png" alt="Notice" width="16" height="16" style="margin-right:8px" />';
$copied_cf[ 'copy_message' ] = $ccf_note . sprintf( __( 'WPML will copy this field from %s when you save this post.', 'sitepress' ), $lang_details[ 'display_name' ] );
foreach ( (array) $sitepress_settings[ 'translation-management' ][ 'custom_fields_translation' ] as $key => $sync_opt ) {
* Added parameter $fields so except checking if field exist in DB,
* it can be checked if set in pre-defined fields.
* Noticed when testing checkbox field that does not save
* value to DB if not checked (omitted from list of copied fields).
* https://icanlocalize.basecamphq.com/projects/2461186-wpml/todo_items/169933388/comments
&& ( isset( $original_custom[ $key ] ) || in_array( $key, $fields ) )
$copied_cf[ 'fields' ][ ] = $key;
* Retrieve language information of a post by its ID
* The language information includes
* the language text direction (True for RTL, False for LTR),
* the post language translated name and native name and
* whether the current language is different to the post language (True/False)
* @param mixed $empty_value
* @see \wpml_get_active_languages_filter
* @param int $post_id Optional The post id to retrieve information of (post, page, attachment, custom) Defaults to current post ID.
* @use \SitePress::api_hooks
function wpml_get_language_information( $empty_value = null, $post_id = null ) {
if ( is_null( $post_id ) ) {
if ( empty( $post_id ) ) {
return new WP_Error( 'missing_id', __( 'Missing post ID', 'sitepress' ) );
$post = get_post( $post_id );
return new WP_Error( 'missing_post', sprintf( __( 'No such post for ID = %d', 'sitepress' ), $post_id ) );
$language = $sitepress->get_language_for_element( $post_id, 'post_' . $post->post_type );
$language_information = $sitepress->get_language_details( $language );
$current_language = $sitepress->get_current_language();
'language_code' => $language,
'locale' => $sitepress->get_locale( $language ),
'text_direction' => $sitepress->is_rtl( $language ),
'display_name' => $sitepress->get_display_language_name( $language, $current_language ),
'native_name' => isset( $language_information['display_name'] ) ? $language_information['display_name'] : '',
'different_language' => $language !== $current_language,
/** This action is documented in */
add_filter( 'wpcf_meta_box_post_type', 'wpml_wpcf_meta_box_order_defaults' );
* Add metabox definition to edit post type in Types
* @param array $boxes Meta boxes in Types.
* @return array Meta boxes in Types.
function wpml_wpcf_meta_box_order_defaults( $boxes ) {
'callback' => 'wpml_custom_post_translation_options',
'title' => __( 'Translation', 'sitepress' ),
* @todo: [WPML 3.3] refactor in 3.3
function wpml_custom_post_translation_options() {
$type_id = isset( $_GET['wpcf-post-type'] ) ? $_GET['wpcf-post-type'] : '';
$type = get_post_type_object( $type_id );
$translated = $sitepress->is_translated_post_type( $type_id );
$link = WPML_Admin_URL::multilingual_setup( 7 );
$link2 = WPML_Admin_URL::multilingual_setup( 4 );
$out .= sprintf( __( '%s is translated via WPML. %sClick here to change translation options.%s', 'sitepress' ), '<strong>' . $type->labels->singular_name . '</strong>', '<a href="' . $link . '">', '</a>' );
if ( $type->rewrite['enabled'] && class_exists( 'WPML_ST_Post_Slug_Translation_Settings' ) ) {
$settings = new WPML_ST_Post_Slug_Translation_Settings( $sitepress );
if ( $settings->is_enabled() ) {
if ( ! $settings->is_translated( $type_id ) ) {
$out .= '<ul><li>' . __( 'Slugs are currently not translated.', 'sitepress' ) . '<li></ul>';
$out .= '<ul><li>' . __( 'Slugs are currently translated. Click the link above to edit the translations.', 'sitepress' ) . '<li></ul>';
$out .= '<ul><li>' . sprintf( __( 'Slug translation is currently disabled in WPML. %sClick here to enable.%s', 'sitepress' ), '<a href="' . $link2 . '">', '</a>' ) . '</li></ul>';
$out .= sprintf( __( '%s is not translated. %sClick here to make this post type translatable.%s', 'sitepress' ), '<strong>' . $type->labels->singular_name . '</strong>', '<a href="' . $link . '">', '</a>' );
* @deprecated 3.2 use 'wpml_add_language_selector' filter instead
function icl_language_selector() {
do_action( 'wpml_add_language_selector' );
$output = ob_get_contents();
* Display the drop down language selector
* Will use the language selector settings from "Language switcher as shortcode or action"
* @use \SitePress::api_hooks
* example: do_action( 'wpml_add_language_selector' );
function wpml_add_language_selector_action() {
do_action( 'wpml_add_language_selector' );
* @deprecated 3.2 use 'wpml_footer_language_selector' filter instead
function icl_language_selector_footer() {
do_action( 'wpml_footer_language_selector' );
$output = ob_get_contents();
* Display the footer language selector
* Will use the language selector include configuration from the WPML -> Language admin screen
* @use \SitePress::api_hooks
* example: do_action('wpml_footer_language_selector');
function wpml_footer_language_selector_action() {
do_action( 'wpml_footer_language_selector' );
* Returns an HTML hidden input field with name="lang" and value of current language
* This is for theme authors, to make their themes compatible with WPML when using the search form.
* In order to make the search form work properly, they should use standard WordPress template tag get_search_form()
* In this case WPML will handle the the rest.
* If for some reasons the template function can't be used and form is created differently,
* authors must the following code between inside the form
* if (function_exists('wpml_the_language_input_field')) {
* wpml_the_language_input_field();
* @global SitePress $sitepress
* @return string|null HTML input field or null
* @deprecated 3.2 use 'wpml_add_language_form_field' action instead
function wpml_get_language_input_field() {
if ( isset( $sitepress ) ) {
return "<input type='hidden' name='lang' value='" . esc_attr( $sitepress->get_current_language() ) . "' />";
* Echoes the value returned by \wpml_get_language_input_field
* @deprecated 3.2 use 'wpml_add_language_form_field' filter instead
function wpml_the_language_input_field() {
echo wpml_get_language_input_field();
* Returns an HTML hidden input field with name="lang" and as value the current language
* In order to add a search form to your theme you would normally use the standard WordPress template tag: <code>get_search_form()</code>
* If you are making use of the default WordPress search form, you do not need to edit anything. WPML will handle the rest.
* However, there may be times when <code>get_search_form()</code> can't be used.
* If you are creating a custom search form and you need to make it WPML compatible then this action hook is what you need.
* Add the action hook inside the form:
* do_action('wpml_add_language_form_field');
* @global SitePress $sitepress
* @return string|null HTML input field or null
* @use \SitePress::api_hooks
function wpml_add_language_form_field_action() {
echo wpml_get_language_form_field();
function wpml_language_form_field_shortcode() {
return wpml_get_language_form_field();
function wpml_get_language_form_field() {
$language_form_field = '';
if ( isset( $sitepress ) ) {
$current_language = $sitepress->get_current_language();
$language_form_field = "<input type='hidden' name='lang' value='" . esc_attr( $current_language ) . "' />";
$language_form_field = apply_filters( 'wpml_language_form_input_field', $language_form_field, $current_language );
return $language_form_field;