Ejemplo n.º 1
0
 /**
  * Validates the send_to_trapp request.
  *
  * @return void.
  */
 public function editSavePost()
 {
     if (!isset($_POST['send_to_trapp'])) {
         return;
     }
     // Exclude auto-draft
     if (get_post_status($this->postId) == 'auto-draft') {
         return;
     }
     // Only specific post types
     $post_type = get_post_type($this->postId);
     $post_types = Mappings::postTypes();
     if (!in_array($post_type, $post_types)) {
         return;
     }
     /**
      * Fired once a post with a TRAPP action has been saved.
      *
      * Specific to the saved post type.
      *
      * @param int    $postId Post ID.
      * @param object $post   WP_Post object of the saved post.
      */
     do_action('bp_save_trapp_' . $post_type, $this->postId, $this->post);
     /**
      * Fired once a post with a TRAPP action has been saved.
      *
      * @param int    $postId Post ID.
      * @param object $post   WP_Post object of the saved post.
      */
     do_action('bp_save_trapp', $this->postId, $this->post);
 }
Ejemplo n.º 2
0
 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']);
 }
Ejemplo n.º 3
0
 /**
  * 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']);
 }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 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;
 }