/** * * @global WPDB $wpdb * @global array $sitepress_settings * @param string $option_name * @param string $language * @param string $new_value * @param int|bool $status * @param int $translator_id * @param int $rec_level * @return boolean|mixed */ function icl_update_string_translation($option_name, $language, $new_value = null, $status = false, $translator_id = null, $rec_level = 0) { global $wpdb, $WPML_String_Translation; if (!is_array($new_value)) { $new_value = (array) $new_value; } $updated = array(); foreach ($new_value as $index => $value) { if (is_array($value)) { $name = "[" . $option_name . "][" . $index . "]"; $result = icl_update_string_translation($name, $language, $value, $status, $translator_id, $rec_level + 1); $updated[] = array_sum(explode(",", $result)); } else { if (is_string($index)) { if ($rec_level == 0) { $name = "[" . $option_name . "]" . $index; } else { $name = $option_name . $index; } } else { $name = $option_name; } $select_original_string = "SELECT * FROM {$wpdb->prefix}icl_strings WHERE name = %s AND language = %s"; $original_string = $wpdb->get_row($wpdb->prepare($select_original_string, $name, $WPML_String_Translation->get_strings_language())); if (!$original_string || !isset($original_string->id) || !is_numeric($original_string->id)) { continue; } $updated[] = icl_add_string_translation($original_string->id, $language, $value, $status, $translator_id); } } if (array_sum($updated) > 0) { return join(",", $updated); } else { return false; } }
function pre_update_option_settings($option, $value, $old_value) { global $sitepress, $sitepress_settings; $current_language = $sitepress->get_current_language(); $strings_language = $sitepress_settings['st']['strings_language']; if ($current_language == $strings_language) { return $value; } WPML_Config::load_config_run(); $result = icl_update_string_translation($option, $current_language, $value, ICL_STRING_TRANSLATION_COMPLETE); if ($result) { // returning old_value in place of value will stop update_option() processing. // do not remove it! return $old_value; } return $value; }
/** * Updates the WPML string register for a single field. * * @since 2.0.9.7 * @param string $context * @param string $field * @param string $value * @param bool $update_string If false then the translation will only be * registered but not updated. */ protected static function wpml_update_field($context, $field, $value, $update_string = true) { global $sitepress, $sitepress_settings; if (empty($sitepress) || empty($sitepress_settings)) { return false; } if (!function_exists('icl_t')) { return false; } if (!icl_st_is_registered_string($context, $field)) { // Register the field if it does not exist. icl_register_string($context, $field, $value, false); $active_languages = $sitepress->get_active_languages(); foreach ($active_languages as $lang => $data) { icl_update_string_translation($field, $lang, $value, ICL_STRING_TRANSLATION_COMPLETE); } $default_language = !empty($sitepress_settings['st']['strings_language']) ? $sitepress_settings['st']['strings_language'] : $sitepress->get_default_language(); icl_update_string_translation($field, $default_language, $value, ICL_STRING_TRANSLATION_COMPLETE); } else { if ($update_string) { // Add translation. if (defined('DOING_AJAX')) { $current_language = $sitepress->get_language_cookie(); } else { $current_language = $sitepress->get_current_language(); } icl_update_string_translation($field, $current_language, $value, ICL_STRING_TRANSLATION_COMPLETE); } } }
function pre_update_option_settings($option, $value, $old_value) { global $sitepress, $sitepress_settings, $switched; if (!$switched || $switched && wpml_get_setting_filter(false, 'setup_complete')) { $current_language = $sitepress->get_current_language(); $strings_language = $sitepress_settings['st']['strings_language']; if ($current_language == $strings_language) { return $value; } WPML_Config::load_config_run(); $result = icl_update_string_translation($option, $current_language, $value, ICL_TM_COMPLETE); if ($result) { // returning old_value in place of value will stop update_option() processing. // do not remove it! return $old_value; } } return $value; }
/** * Filter that implements theme options translation to default language before saving them to DB. * * @param assoc $option_value * @param assoc $old_option_value * @return assoc */ public function filter_option_update($option_value, $old_option_value) { $default_language = $this->getDefaultLang(); $current_language = $this->getLang(); $page_settings = $this->page_id_settings_for_translation; if ($page_settings) { $languages_list = apply_filters('wpml_active_languages', null, ''); foreach ($page_settings as $setting_key) { $new_value = !empty($option_value[$setting_key]) ? $option_value[$setting_key] : null; // $old_value = ! empty( $old_option_value[ $setting_key ] ) ? $old_option_value[ $setting_key ] : null; if ($new_value) { foreach ($languages_list as $ln_code => $ln_details) { //if ( $default_language != $ln_code ) { $tr_value = apply_filters('wpml_object_id', $new_value, 'page', true, $ln_code); icl_update_string_translation($this->getWpmlStringName($setting_key), $ln_code, $tr_value, ICL_TM_COMPLETE, $translator_id = null, $rec_level = 0); } //icl_update_string_translation( $this->getWpmlStringName( $setting_key ), $current_language, $new_value, ICL_TM_COMPLETE, $translator_id = null, $rec_level = 0 ); $option_value[$setting_key] = apply_filters('wpml_object_id', $new_value, 'page', true, $default_language); } } } if ($this->getDefaultLang() != $this->getLang()) { $settings_list = $this->settings_for_translation; if ($settings_list) { foreach ($settings_list as $setting_key) { $value = isset($option_value[$setting_key]) ? $option_value[$setting_key] : ''; icl_update_string_translation($this->getWpmlStringName($setting_key), $current_language, $value, ICL_TM_COMPLETE, $translator_id = null, $rec_level = 0); $option_value[$setting_key] = $old_option_value[$setting_key]; } } } $option_value['_ts'] = time(); return $option_value; }