Esempio n. 1
0
 function set_attachment_fields_to_save($post, $attachment)
 {
     global $wpdb;
     if (isset($attachment['attachment_post_language'])) {
         if ($attachment['attachment_post_language'] != '' && $attachment['attachment_post_language'] != 'undefined') {
             wp_set_object_terms($post['ID'], $attachment['attachment_post_language'], TAXONAME);
         } else {
             wp_delete_object_term_relationships($post['ID'], TAXONAME);
         }
     }
     $clone = $post;
     unset($clone['ID']);
     if (isset($attachment['create_clone_attachment_with_language']) && $attachment['create_clone_attachment_with_language'] != 'undefined') {
         $clone['post_title'] = sprintf(__('Translate in %2$s: %1$s', 'xili-language'), $clone['post_title'], $attachment['create_clone_attachment_with_language']);
         if ($clone['post_content']) {
             $clone['post_content'] = sprintf(__('Translate: %1$s', 'xili-language'), $clone['post_content']);
         }
         if ($clone['post_excerpt']) {
             $clone['post_excerpt'] = sprintf(__('Translate: %1$s', 'xili-language'), $clone['post_excerpt']);
         }
         $parent_id = $post['xl_post_parent'];
         // 2.8.4.2 hidden input
         $linked_parent_id = xl_get_linked_post_in($parent_id, $attachment['create_clone_attachment_with_language']);
         $clone['post_parent'] = $linked_parent_id;
         // 0 if unknown linked id of parent in assigned language
         $clone['guid'] = $post['attachment_url'];
         // 2.18.1 - the URI of media and not URI of attachment itself
         // now clones
         $cloned_attachment_id = wp_insert_post($clone);
         // clone post_meta
         $data = get_post_meta($post['ID'], '_wp_attachment_metadata', true);
         $data_file = get_post_meta($post['ID'], '_wp_attached_file', true);
         $data_alt = get_post_meta($post['ID'], '_wp_attachment_image_alt', true);
         update_post_meta($cloned_attachment_id, '_wp_attachment_metadata', $data);
         update_post_meta($cloned_attachment_id, '_wp_attached_file', $data_file);
         if ('' != $data_alt) {
             update_post_meta($cloned_attachment_id, '_wp_attachment_image_alt', sprintf(__('Translate: %1$s', 'xili-language'), $data_alt));
         }
         // set language and links of cloned of current
         update_post_meta($cloned_attachment_id, QUETAG . '-' . $attachment['attachment_post_language'], $post['ID']);
         wp_set_object_terms($cloned_attachment_id, $attachment['create_clone_attachment_with_language'], TAXONAME);
         // get already linked of cloned
         $already_linked = array();
         if ($meta_values = $wpdb->get_results($wpdb->prepare("SELECT meta_value, meta_key FROM {$wpdb->postmeta} WHERE meta_key LIKE %s AND post_id = %d", QUETAG . '-' . '%', $post['ID']))) {
             foreach ($meta_values as $key_val) {
                 update_post_meta($key_val->meta_value, QUETAG . '-' . $attachment['create_clone_attachment_with_language'], $cloned_attachment_id);
                 $slug = str_replace(QUETAG . '-', '', $key_val->meta_key);
                 $already_linked[$slug] = $key_val->meta_value;
             }
         }
         // set links of current to cloned
         update_post_meta((int) $post['ID'], QUETAG . '-' . $attachment['create_clone_attachment_with_language'], $cloned_attachment_id);
         if ($already_linked != array()) {
             foreach ($already_linked as $key => $id) {
                 update_post_meta($post['ID'], QUETAG . '-' . $key, $id);
                 if ($key != $attachment['create_clone_attachment_with_language']) {
                     update_post_meta($cloned_attachment_id, QUETAG . '-' . $key, $id);
                 }
             }
         }
     }
     return $post;
 }
Esempio n. 2
0
 /**
  * featured image
  *
  * @since 2.12
  */
 function propagate_thumbnail_id($from_post_ID, $post_ID)
 {
     $thumbnail_id = get_post_meta($from_post_ID, '_thumbnail_id', true);
     if ($thumbnail_id) {
         $to_lang = get_cur_language($post_ID);
         $translated_value = xl_get_linked_post_in($thumbnail_id, $to_lang);
         $value = $translated_value != 0 ? $translated_value : $thumbnail_id;
         // a translation exist ( title / alt / ...)
         update_post_meta($post_ID, '_thumbnail_id', $value);
     }
 }