Пример #1
0
 public function copy_post($post, $target)
 {
     self::$copying_post = true;
     $document = $this->get_group('post', $post->ID);
     $prefs = self::get_prefs();
     $cp_lang = $this->pllm->get_language($target);
     $cp_post = (array) $post;
     $cp_post['post_status'] = $prefs['download_post_status'] === 'SAME_AS_SOURCE' ? $post->post_status : $prefs['download_post_status'];
     // status
     unset($cp_post['ID']);
     unset($cp_post['post_name']);
     if (!isset($document->desc_array[$target])) {
         $new_post_id = wp_insert_post($cp_post, true);
         if (!is_wp_error($new_post_id)) {
             $this->pllm->set_post_language($new_post_id, $cp_lang);
             wp_set_object_terms($new_post_id, $document->term_id, 'post_translations');
             $GLOBALS['polylang']->sync->copy_post_metas($document->source, $new_post_id, $cp_lang->slug);
             Lingotek_Group_Post::copy_or_ignore_metas($post->ID, $new_post_id);
             $document->desc_array[$target] = $new_post_id;
             $document->save();
         }
     }
     self::$copying_post = false;
 }