public function deleteCategory($id) { $db = $this->db; $deleted = new ProductCategory(); $deleted->delete($db, $id); }
/** * Handles loading, saving and deleting categories in a workflow context * * @author Jonathan Davis * @since 1.0 * @return void **/ public function workflow() { $defaults = array('action' => false, 'selected' => array(), 'page' => false, 'id' => false, 'save' => false, 'next' => false, '_wpnonce' => false); $args = array_merge($defaults, $_REQUEST); extract($args, EXTR_SKIP); if (!defined('WP_ADMIN') || $page != $this->page()) { return false; } $adminurl = admin_url('admin.php'); add_screen_option('per_page', array('label' => __('Categories Per Page', 'Shopp'), 'default' => 20, 'option' => 'edit_' . ProductCategory::$taxon . '_per_page')); if ('delete' == $action && wp_verify_nonce($_wpnonce, 'shopp_categories_manager')) { if (!empty($id)) { $selected = array($id); } $total = count($selected); foreach ($selected as $selection) { $DeletedCategory = new ProductCategory($selection); $deleted = $DeletedCategory->name; $DeletedCategory->delete(); } if (1 == $total) { $this->notice(Shopp::__('Deleted %s category.', "<strong>{$deleted}</strong>")); } else { $this->notice(Shopp::__('Deleted %s categories.', "<strong>{$total}</strong>")); } $reset = array('selected' => null, 'action' => null, 'id' => null, '_wpnonce' => null); $redirect = add_query_arg(array_merge($_GET, $reset), $adminurl); Shopp::redirect($redirect); exit; } if ($id && 'new' != $id) { $Category = new ProductCategory($id); } else { $Category = new ProductCategory(); } $meta = array('specs', 'priceranges', 'options', 'prices'); foreach ($meta as $prop) { if (!isset($Category->{$prop})) { $Category->{$prop} = array(); } } if ($save) { $this->save($Category); // Workflow handler if (isset($_REQUEST['settings']) && isset($_REQUEST['settings']['workflow'])) { $workflow = $_REQUEST['settings']['workflow']; $working = array_search($id, $this->worklist); switch ($workflow) { case 'close': $next = 'close'; break; case 'new': $next = 'new'; break; case 'next': $key = $working + 1; break; case 'previous': $key = $working - 1; break; } if (isset($key)) { $next = isset($this->worklist[$key]) ? $this->worklist[$key] : 'close'; } } if ($next) { if ('new' == $next) { $Category = new ProductCategory(); } else { $Category = new ProductCategory($next); } } else { if (empty($id)) { $id = $Category->id; } $Category = new ProductCategory($id); } } ShoppCollection($Category); }
/** * Remove a product category by id * * @api * @since 1.2 * * @param int $id (required) The category id * @return bool true on success, false on failure **/ function shopp_rmv_product_category($id = false) { if (!$id) { shopp_debug(__FUNCTION__ . " failed: Category id required."); return false; } $Category = new ProductCategory($id); if (empty($Category->id)) { return false; } return $Category->delete(); }