/** * Insert post and postmeta using `RSCSV_Import_Post_Helper` class. * * @param array $post * @param array $meta * @param array $terms * @param string $thumbnail The uri or path of thumbnail image. * @param bool $is_update * @return RSCSV_Import_Post_Helper */ public function save_post($post, $meta, $terms, $thumbnail, $is_update) { // Separate the post tags from $post array if (isset($post['post_tags']) && !empty($post['post_tags'])) { $post_tags = $post['post_tags']; unset($post['post_tags']); } // Special handling of attachments if (!empty($thumbnail) && $post['post_type'] == 'attachment') { $post['media_file'] = $thumbnail; $thumbnail = null; } // Add or update the post if ($is_update) { $h = RSCSV_Import_Post_Helper::getByID($post['ID']); $h->update($post); } else { $h = RSCSV_Import_Post_Helper::add($post); } // Set post tags if (isset($post_tags)) { $h->setPostTags($post_tags); } // Set meta data $h->setMeta($meta); // Set terms foreach ($terms as $key => $value) { $h->setObjectTerms($key, $value); } // Add thumbnail if ($thumbnail) { $h->addThumbnail($thumbnail); } return $h; }