web/app/plugins/sitepress-multilingual-cms/inc/translation-management/translation-management.class.php
// when the translated post was created, we have the job_id and need to update the job
when the translated post was created, we have the job_id and need to update the job
when the translated post was created we have the job_id and need to update the job
function save_job_fields_from_post($job_id, $post){
        global $wpdb, $sitepress;
        $data['complete'] = 1;
        $data['job_id'] = $job_id;        
        $job = $this->get_translation_job($job_id,1);
        if(is_array($job->elements))
        foreach($job->elements as $element){
            $field_data = '';
            switch($element->field_type){
                case 'title':
                    $field_data = $this->encode_field_data($post->post_title, $element->field_format);
                    break;
                case 'body':
                    $field_data = $this->encode_field_data($post->post_content, $element->field_format);
                    break;
                case 'excerpt':
                    $field_data = $this->encode_field_data($post->post_excerpt, $element->field_format);
                    break;                           
                default:
                    if(false !== strpos($element->field_type, 'field-') && !empty($this->settings['custom_fields_translation'])){                                
                        $cf_name = preg_replace('#^field-#', '', $element->field_type);
                        if(isset($this->settings['custom_fields_translation'][$cf_name])){
                            if($this->settings['custom_fields_translation'][$cf_name] == 1){ 
                                $field_data = get_post_meta($original_post->ID, $cf_name, 1);               
                                if(is_scalar($field_data))
                                $field_data = $this->encode_field_data($field_data, $element->field_format);                             
                                else $field_data = '';
                            }elseif($this->settings['custom_fields_translation'][$cf_name] == 2){ 
                                $field_data = get_post_meta($post->ID, $cf_name, 1);             
                                if(is_scalar($field_data))
                                $field_data = $this->encode_field_data($field_data, $element->field_format);                             
                                else $field_data = '';
                            }
                        }
                    }else{
                        if(in_array($element->field_type, $sitepress->get_translatable_taxonomies(true, $post->post_type))){                            
                            $ids = array();
                            foreach($job->elements as $je){
                                if($je->field_type == $element->field_type .'_ids' ){
                                    $ids = explode(',', $je->field_data);
                                }
                            }
                            $translated_tax_names = array();
                            foreach($ids as $id){
                                $translated_tax_id = icl_object_id($id, $element->field_type,false,$job->language_code);
                                if($translated_tax_id){
                                    $translated_tax_names[] = $wpdb->get_var($wpdb->prepare("
                                        SELECT t.name FROM {$wpdb->terms} t JOIN {$wpdb->term_taxonomy} x ON t.term_id = x.term_id
                                        WHERE x.term_taxonomy_id = %d
                                    ", $translated_tax_id));
                                }
                            }
                            $field_data = $this->encode_field_data($translated_tax_names, $element->field_format);
                        }
                    }
            }            
            $wpdb->update($wpdb->prefix.'icl_translate', 
                array('field_data_translated'=>$field_data, 'field_finished'=>1), 
                array('tid'=>$element->tid)
            );
        }   
        $this->mark_job_done($job_id);                
    }
function save_job_fields_from_post ( $ job_id , $ post ) { global $ wpdb , $ sitepress ; $ data [ 'complete' ] = 1 ; $ data [ 'job_id' ] = $ job_id ; $ job = $ this -> get_translation_job ( $ job_id , 1 ) ; if ( is_array ( $ job -> elements ) ) foreach ( $ job -> elements as $ element ) { $ field_data = '' ; switch ( $ element -> field_type ) { case 'title' : $ field_data = $ this -> encode_field_data ( $ post -> post_title , $ element -> field_format ) ; break ; case 'body' : $ field_data = $ this -> encode_field_data ( $ post -> post_content , $ element -> field_format ) ; break ; case 'excerpt' : $ field_data = $ this -> encode_field_data ( $ post -> post_excerpt , $ element -> field_format ) ; break ; default : if ( false !== strpos ( $ element -> field_type , 'field-' ) && ! empty ( $ this -> settings [ 'custom_fields_translation' ] ) ) { $ cf_name = preg_replace ( '#^field-#' , '' , $ element -> field_type ) ; if ( isset ( $ this -> settings [ 'custom_fields_translation' ] [ $ cf_name ] ) ) { if ( $ this -> settings [ 'custom_fields_translation' ] [ $ cf_name ] == 1 ) { $ field_data = get_post_meta ( $ original_post -> ID , $ cf_name , 1 ) ; if ( is_scalar ( $ field_data ) ) $ field_data = $ this -> encode_field_data ( $ field_data , $ element -> field_format ) ; else $ field_data = '' ; } elseif ( $ this -> settings [ 'custom_fields_translation' ] [ $ cf_name ] == 2 ) { $ field_data = get_post_meta ( $ post -> ID , $ cf_name , 1 ) ; if ( is_scalar ( $ field_data ) ) $ field_data = $ this -> encode_field_data ( $ field_data , $ element -> field_format ) ; else $ field_data = '' ; } } } else { if ( in_array ( $ element -> field_type , $ sitepress -> get_translatable_taxonomies ( true , $ post -> post_type ) ) ) { $ ids = array ( ) ; foreach ( $ job -> elements as $ je ) { if ( $ je -> field_type == $ element -> field_type . '_ids' ) { $ ids = explode ( ',' , $ je -> field_data ) ; } } $ translated_tax_names = array ( ) ; foreach ( $ ids as $ id ) { $ translated_tax_id = icl_object_id ( $ id , $ element -> field_type , false , $ job -> language_code ) ; if ( $ translated_tax_id ) { $ translated_tax_names [ ] = $ wpdb -> get_var ( $ wpdb -> prepare ( " 
                                        SELECT t.name FROM  { $ wpdb -> terms }  t JOIN  { $ wpdb -> term_taxonomy }  x ON t.term_id = x.term_id
                                        WHERE x.term_taxonomy_id = %d
                                     " , $ translated_tax_id ) ) ; } } $ field_data = $ this -> encode_field_data ( $ translated_tax_names , $ element -> field_format ) ; } } } $ wpdb -> update ( $ wpdb -> prefix . 'icl_translate' , array ( 'field_data_translated' => $ field_data , 'field_finished' => 1 ) , array ( 'tid' => $ element -> tid ) ) ; } $ this -> mark_job_done ( $ job_id ) ; }
when the translated post was created, we have the job_id and need to update the job
when the translated post was created we have the job_id and need to update the job
//copy // translate