コード例 #1
0
 public function addRevision(TranslationRevision $revision)
 {
     $this->row->revisions[] = $revision->toArray();
     return $this;
 }
コード例 #2
0
ファイル: Events.php プロジェクト: phh/wp-trapp
 /**
  * Creates a new Trapp revision.
  *
  * @return void.
  */
 public function createTrappRevision()
 {
     global $polylang;
     if (empty($_POST['trapp_tr_lang'])) {
         return;
     }
     if (empty($_POST['trapp_deadline'])) {
         return;
     }
     $translation = new ServiceTranslation();
     // TODO Use posted date
     $deadline = esc_attr($_POST['trapp_deadline']);
     $deadline = new DateTime($deadline);
     $translation->setDeadline($deadline);
     $translation->setLocale($this->getPostLocale());
     $translation->setTitle($this->post->post_title);
     // Create new revision
     $revision = new TranslationRevision();
     if (isset($_POST['trapp_start'])) {
         $translation->setState('state-missing');
     }
     if (!empty($_POST['trapp_comment'])) {
         $translation->setComment(esc_attr($_POST['trapp_comment']));
     }
     $post_group = apply_filters('bp_trapp_post_group', 'Post', $this->postId, $this->post);
     $title = new TranslationField('Title', $this->post->post_title);
     $title->setGroup($post_group);
     $revision->addField($title);
     $post_name = new TranslationField('Name/Slug', $this->post->post_name);
     $post_name->setGroup($post_group);
     $revision->addField($post_name);
     $content = new TranslationField('Body', $this->post->post_content);
     $content->setGroup($post_group);
     $revision->addField($content);
     $translation->addRevision($revision);
     foreach ($_POST['trapp_tr_lang'] as $trapp_lang => $active) {
         $trapp_lang = esc_attr($trapp_lang);
         $trapp_lang = $polylang->model->get_language($trapp_lang);
         if (!$trapp_lang) {
             continue;
         }
         $locale = $this->filterLocale($trapp_lang->locale);
         $translation->addLanguage($locale);
     }
     $translation->save();
     // Get row data after data
     $row = $translation->getRow();
     // Save index search id
     add_post_meta($this->postId, self::TRAPP_META_KEY, $row->id);
     do_action('bp_trapp_after_save_post', $row, $this->post);
 }