$post_title, 'post_type' => 'shipping_manifest', 'post_status' => 'publish', ); $manifest_id = wp_insert_post( $manifest_post ); update_post_meta( $manifest_id, '_integration', $integration ); return fs_get_manifest( $manifest_id ); } /** * @param $manifest_id * @return WPDesk_Flexible_Shipping_Manifest */ function fs_get_manifest( $manifest_id ) { $integration = get_post_meta( $manifest_id, '_integration', true ); $class_name = 'WPDesk_Flexible_Shipping_Manifest'; if ( class_exists( $class_name . '_' . $integration ) ) { $class_name = $class_name . '_' . $integration; } else { $class_name = 'WPDesk_Flexible_Shipping_Manifest_FS'; } return new $class_name( $manifest_id ); } function fs_delete_manifest( $manifest ) { $shipments_posts = get_posts( array( 'posts_per_page' => -1, 'post_type' => 'shipment', 'post_status' => 'any', 'meta_key' => '_manifest', 'meta_value' => $manifest->get_id() ) ); foreach ( $shipments_posts as $shipment_post ) { $shipment = fs_get_shipment( $shipment_post->ID ); $shipment->delete_meta( '_manifest' ); $shipment->update_status('fs-confirmed' ); $shipment->save(); } $manifest->set_meta( '_shipments', array() ); $manifest->update_status( 'trash' ); $manifest->save(); }