/** * Deletes the category from the database via the cnTerm class. * * @return bool The success or error message. */ public function delete() { $default = get_option('cn_default_category'); if ($this->id == $default) { cnMessage::set('error', 'category_delete_default'); return FALSE; } $result = cnTerm::delete($this->id, 'category'); if (is_wp_error($result)) { cnMessage::set('error', $result->get_error_message()); return FALSE; } else { cnMessage::set('success', 'category_deleted'); return TRUE; } }
/** * Remove a term from the database. * * If the term contains children terms, the children terms will be updated * to the deleted term parent. * * @deprecated 8.1.6 Use {@see cnTerm::delete()} instead. * @see cnTerm::delete() * * @param int $id Term ID. * @param int $id Term parent ID. * @param string $taxonomy Taxonomy name. * * @return bool */ public function deleteTerm($id, $parent, $taxonomy) { $result = cnTerm::delete($id, $taxonomy); return $result; }
/** * Delete a single term from a taxonomy * * @since 8.5.26 * * @param WP_REST_Request $request Full details about the request * * @return WP_REST_Response|WP_Error */ public function delete_item($request) { $force = isset($request['force']) ? (bool) $request['force'] : FALSE; // We don't support trashing for this type, error out if (!$force) { return new WP_Error('rest_trash_not_supported', __('Resource does not support trashing.', 'connections'), array('status' => 501)); } $term = cnTerm::get((int) $request['id'], $this->taxonomy); $request->set_param('context', 'view'); $response = $this->prepare_item_for_response($term, $request); $retval = cnTerm::delete($term->term_id, $term->taxonomy); if (!$retval) { return new WP_Error('rest_cannot_delete', __('The resource cannot be deleted.', 'connections'), array('status' => 500)); } /** * Fires after a single term is deleted via the REST API. * * @param WP_Term $term The deleted term. * @param WP_REST_Response $response The response data. * @param WP_REST_Request $request The request sent to the API. */ do_action("cn_rest_delete_{$this->taxonomy}", $term, $response, $request); return $response; }
/** * Deletes the category from the database via the cnTerm class. * * @return bool The success or error message. */ public function delete() { // @todo Add option for user to set the default category, which should not be able to be deleted. //$defaults['default'] = get_option( 'cn_default_category' ); // Temporarily hard code the default category to the Uncategorized category // and ensure it can not be deleted. This should be removed when the default // category can be set by the user. $default_category = cnTerm::getBy('slug', 'uncategorized', 'category'); $defaults['default'] = $default_category->term_id; // Do not change the default category. // This should be able to be removed after the user configurable default category is implemented. if ($this->id == $default_category->term_id) { cnMessage::set('error', 'category_delete_uncategorized'); return FALSE; } $result = cnTerm::delete($this->id, 'category'); if (is_wp_error($result)) { cnMessage::set('error', $result->get_error_message()); return FALSE; } else { cnMessage::set('success', 'category_deleted'); return TRUE; } }