コード例 #1
0
 /**
  * Provide a Post object you want to add to the current batch.
  *
  * @param Batch $batch
  * @param Post  $post
  */
 private function add_post(Batch $batch, Post $post)
 {
     // Make sure the post is not already in the batch.
     foreach ($batch->get_posts() as $post_in_batch) {
         if ($post->get_id() === $post_in_batch->get_id()) {
             return;
         }
     }
     if ($post->get_type() === 'attachment') {
         $this->add_attachment($batch, $post->get_id());
     }
     // Catch issue with term ID not being set properly.
     try {
         $this->post_taxonomy_dao->get_post_taxonomy_relationships($post);
     } catch (Exception $e) {
         $this->api->add_preflight_message($batch->get_id(), $e->getMessage(), 'warning');
     }
     $post->set_meta($this->postmeta_dao->get_postmetas_by_post_id($post->get_id()));
     /*
      * Make it possible for third-party developers to modify post before it
      * is added to batch.
      */
     do_action('sme_prepare_post', $post, $batch);
     $batch->add_post($post);
     $post_meta = $post->get_meta();
     $record_count = count($post_meta);
     for ($i = 0; $i < $record_count; $i++) {
         $post_meta[$i] = $this->add_related_posts($batch, $post_meta[$i]);
     }
     $post->set_meta($post_meta);
 }