/** * 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); }
/** * Creates a new Trapp revision. * * @return void. */ public function createTrappRevision() { if (empty($_POST['trapp_tr_lang']) && !$this->hasPostTranslations()) { return; } if (empty($_POST['trapp_deadline'])) { return; } $service = new ServiceTranslation(); $deadline = esc_attr($_POST['trapp_deadline']); // Save Deadline add_post_meta($this->postId, self::TRAPP_META_DEADLINE, $deadline); $deadline = new DateTime($deadline); $service->setDeadline($deadline); $service->setLocale($this->getPostLocale()); $service->setTitle($this->post->post_title); $service->setUpdateEndpointUri($this->getUpdateEndpoint()); if (!empty($_POST['trapp_comment'])) { $service->setComment(esc_attr($_POST['trapp_comment'])); } if (isset($_POST['trapp_start'])) { $service->setState('state-missing'); } $fieldGroups = Mappings::getFields(get_post_type($this->post)); foreach ($fieldGroups as $fieldGroup) { foreach ($fieldGroup['fields'] as $field) { $field['group'] = $fieldGroup['title']; $field = Mappings::translationField($field, $this->postId, $this->post); if (!empty($field)) { if (is_array($field)) { foreach ($field as $singleField) { $service->addField($singleField); } } else { $service->addField($field); } } } } if (!empty($_POST['trapp_tr_lang'])) { $languages = $_POST['trapp_tr_lang']; } else { $languages = $this->getPostTranslations(); } $languages = array_keys($languages); foreach ($languages as $trapp_lang) { $trapp_lang = esc_attr($trapp_lang); $trapp_lang = PLL()->model->get_language($trapp_lang); if (!$trapp_lang) { continue; } $locale = $this->filterLocale($trapp_lang->locale); $service->addTranslatation($locale); } $row = $service->save(); // Save Trapp ID add_post_meta($this->postId, self::TRAPP_META_KEY, $row->getId()); // This is the first saved post and therefore master add_post_meta($this->postId, self::TRAPP_META_MASTER, 1); do_action('bp_trapp_after_save_post', $row, $this->post); }