public static function migrate_terms_to_items() { $update = get_option(self::UPDATED, false); if ($update) { return; } // Get all the terms $item_types = get_terms(array(SI_Estimate::LINE_ITEM_TAXONOMY), array('hide_empty' => false, 'fields' => 'all')); // convert to item PT foreach ($item_types as $item_type) { $args = array('name' => $item_type->name, 'description' => $item_type->description, 'product' => false, 'qty' => 1, 'rate' => 100, 'percentage' => 0); SI_Item::new_item($args); wp_delete_term($item_type->term_id, SI_Estimate::LINE_ITEM_TAXONOMY); } update_option(self::UPDATED, time()); }
public static function maybe_create_item() { if (!current_user_can('edit_sprout_invoices')) { self::ajax_fail('User cannot create an item!'); } $nonce = $_REQUEST['nonce']; if (!wp_verify_nonce($nonce, self::NONCE)) { self::ajax_fail('Not going to fall for it!'); } if (!isset($_REQUEST['name']) || $_REQUEST['name'] == '') { self::ajax_fail('No name given.'); } $args = array(); $args['name'] = $_REQUEST['name']; $args['product'] = isset($_REQUEST['product']) ? true : false; if (isset($_REQUEST['type'])) { $args['type'] = $_REQUEST['type']; } if (isset($_REQUEST['description'])) { $args['description'] = $_REQUEST['description']; } if (isset($_REQUEST['qty'])) { $args['qty'] = (double) $_REQUEST['qty']; } if (isset($_REQUEST['percentage'])) { $args['percentage'] = (double) $_REQUEST['percentage']; } if (isset($_REQUEST['rate'])) { $args['rate'] = (double) $_REQUEST['rate']; } if (isset($_REQUEST['sku'])) { $args['sku'] = $_REQUEST['sku']; } $id = SI_Item::new_item($args); $item = SI_Item::get_instance($id); $response = array('id' => $id, 'type' => $item->get_type(), 'desc' => stripslashes($item->get_content()), 'rate' => $item->get_default_rate(), 'qty' => $item->get_default_qty(), 'tax' => $item->get_default_percentage(), 'sku' => $item->get_default_sku(), 'title' => stripslashes($item->get_title())); wp_send_json_success($response); }