/** * Translate the plugin settings before they are saved to DB. * * @since 1.0.1.0 * * @param array $obj The serialized data collection. * @param MS_Model_Membership $model The source object. * @return array The serialized data collection. */ public function serialize_membership($data, $model) { if ($this->current_lang == $this->default_lang) { return $data; } // Save the translated values before resetting the model. $tr_name = $data['name']; $tr_description = $data['description']; // Reset the values to Default language. $data['name'] = $model->reset_field('name'); $data['description'] = $model->reset_field('description'); // Store translations via WPML. if (function_exists('icl_add_string_translation')) { $string_name = 'ms-mem-name-' . $model->id; do_action('wpml_register_single_string', self::CONTEXT, $string_name, $data['name']); $string_id = icl_get_string_id($data['name'], self::CONTEXT, $string_name); if ($string_id) { icl_add_string_translation($string_id, $this->current_lang, $tr_name, ICL_TM_COMPLETE); } $string_name = 'ms-mem-description-' . $model->id; do_action('wpml_register_single_string', self::CONTEXT, $string_name, $data['description']); $string_id = icl_get_string_id($data['description'], self::CONTEXT, $string_name); if ($string_id) { icl_add_string_translation($string_id, $this->current_lang, $tr_description, ICL_TM_COMPLETE); } } return $data; }