public function registerColumns() { foreach (Mappings::postTypes() as $post_type) { add_action('manage_' . $post_type . '_posts_custom_column', [__CLASS__, 'pll_before_post_column'], 8, 2); add_action('manage_' . $post_type . '_posts_custom_column', [__CLASS__, 'pll_after_post_column'], 12, 2); } add_action('load-edit.php', [__CLASS__, 'loadEdit']); }
/** * Registers the Polylang language meta box. * * @param string $post_type Post type of the post. * @param string $context Meta box context. * * @return void. */ public static function registerMetaBox($post_type, $context) { if ($context != 'side') { return; } // Allow attachments if ($post_type == 'attachment') { return; } remove_meta_box('ml_box', $post_type, $context); $post_types = Mappings::postTypes(); if (!in_array($post_type, $post_types)) { return; } $args = ['post_type' => $post_type]; add_meta_box('ml_box', __('Languages', Plugin::TEXT_DOMAIN), [__CLASS__, 'polylangMetaBoxRender'], $post_type, $context, 'high', $args); add_action('admin_enqueue_scripts', [__CLASS__, 'enqueueMetaboxStyles']); add_action('admin_enqueue_scripts', [__CLASS__, 'enqueueDatePicker']); }
public function registerNotice() { $postType = get_post_type(); if (!in_array($postType, Mappings::postTypes())) { return; } $is_master = get_post_meta(get_the_ID(), Events::TRAPP_META_MASTER, true); $has_trapp_key = get_post_meta(get_the_ID(), Events::TRAPP_META_KEY, true); if ($is_master || !$has_trapp_key) { return; } $translation_link = get_post_meta(get_the_ID(), Events::TRAPP_META_LINK, true); $link_text = sprintf('<a href="%s" target="_blank"><strong>TRAPP</strong></a>', esc_url($translation_link)); $notice = '<div id="message" class="error notice">'; $notice .= '<p>'; $notice .= sprintf('<strong>%s:</strong><br>', __('Warning', Plugin::TEXT_DOMAIN)); $notice .= sprintf(__('This is a translation found inside the TRAPP service and should get updated in %s instead.', Plugin::TEXT_DOMAIN), $link_text); $notice .= '</p>'; $notice .= '</div>'; echo $notice; }
public function isTranslation() { $postType = get_post_type(); if (!in_array($postType, Mappings::postTypes())) { return false; } $is_master = get_post_meta(get_the_ID(), Events::TRAPP_META_MASTER, true); $has_trapp_key = get_post_meta(get_the_ID(), Events::TRAPP_META_KEY, true); if (!$is_master && $has_trapp_key) { return true; } return false; }
public function getPostByTrappId($trappId = '') { if (empty($trappId)) { return false; } $args = ['post_type' => Mappings::postTypes(), 'post_status' => 'any', 'meta_key' => Events::TRAPP_META_KEY, 'meta_value' => $trappId, 'posts_per_page' => 1, 'lang' => '']; $query = new WP_Query($args); if ($query->have_posts()) { return $query->post; } return false; }
/** * Updates an exiting Trapp entry with a new revision. * * @return void. */ public function updateTrappRevision() { $service = new ServiceTranslation(); $service = $service->getById($this->trappId); if (!empty($_POST['trapp_deadline'])) { $deadline = esc_attr($_POST['trapp_deadline']); update_post_meta($this->postId, self::TRAPP_META_DEADLINE, $deadline); $deadline = new DateTime($deadline); $service->setDeadline($deadline); } if (!empty($_POST['trapp_comment'])) { $service->setComment(esc_attr($_POST['trapp_comment'])); } if (isset($_POST['trapp_start'])) { $service->setState('state-missing'); } $newFields = []; $arrayIgnore = []; $serviceFields = $service->getFields(); $fieldGroups = Mappings::getFields(get_post_type($this->post)); foreach ($fieldGroups as $fieldGroup) { foreach ($fieldGroup['fields'] as $field) { $field['group'] = $fieldGroup['title']; foreach ($serviceFields as $fieldId => $serviceField) { if ($field['label'] == $serviceField->getLabel()) { $value = Mappings::getValue($field['type'], $this->postId, $this->post, $field['args']); if (!empty($value)) { $serviceFields[$fieldId]->setValue($value); } continue 2; } elseif ($field['type'] == 'post_meta_array') { $value = Mappings::getValue($field['type'], $this->postId, $this->post, $field['args']); $label = $serviceField->getLabel(); if (is_array($value) && array_key_exists($label, $value)) { $serviceFields[$fieldId]->setValue($value[$label]); $arrayIgnore[] = $label; } } } $newFields[] = $field; } } $service->setFields($serviceFields); if (!empty($newFields)) { foreach ($newFields as $newField) { $field = Mappings::translationField($newField, $this->postId, $this->post, $arrayIgnore); if (!empty($field)) { if (is_array($field)) { foreach ($field as $singleField) { $service->addField($singleField); } } else { $service->addField($field); } } } } $post_translations = []; foreach ($service->getRelatedTranslations() as $serviceTranslation) { if ($serviceTranslation->isOriginal()) { continue; } $post_translations[] = $serviceTranslation->getLocale(); } if (!empty($_POST['trapp_tr_lang'])) { foreach ($_POST['trapp_tr_lang'] as $trapp_lang => $active) { $trapp_lang = esc_attr($trapp_lang); $trapp_lang = PLL()->model->get_language($trapp_lang); if (!$trapp_lang) { continue; } $locale = $this->filterLocale($trapp_lang->locale); if (in_array($locale, $post_translations)) { continue; } $service->addTranslatation($locale); } } $row = $service->update(); do_action('bp_trapp_after_save_post', $row, $this->post); }