/** * Save the File to the database with a given $zip_id * * @param File $file File model object * @param int $zip_id ID of the zip parent * @return int|WP_Error post_id on success, WP_Error on failure * @since 0.5.0 */ public function by_file_and_zip_id($file, $zip_id) { $data = array('post_title' => $file->get_slug(), 'post_content' => $file->get_code(), 'post_status' => get_post_status($zip_id), 'post_parent' => $zip_id); if ($file->get_ID()) { $data['ID'] = $file->get_ID(); } if ($file->get_language() !== null) { $data['tax_input'] = array('wpgp_language' => $file->get_language()->get_slug()); } $result = $this->by_array($data); if (is_wp_error($result)) { return $result; } $post_id = $result; unset($result); return $post_id; }
/** * Creates an API model object by a FileModel * * @param FileModel $file * @return stdClass FileModel API object * @since 0.5.0 */ public function by_file(FileModel $file) { $api = new stdClass(); $api->slug = $file->get_slug(); $api->code = $file->get_code(); $api->ID = $file->get_ID(); $api->language = $file->get_language()->get_slug(); return $api; }