LLMS_REST_Posts_Controller::delete_item( WP_REST_Request $request )
Deletes a single llms post.
Parameters Parameters
- $request
-
(WP_REST_Request) (Required) Full details about the request.
Return Return
(WP_REST_Response|WP_Error) Response object on success, or WP_Error object on failure.
Source Source
File: libraries/lifterlms-rest/includes/abstracts/class-llms-rest-posts-controller.php
public function delete_item( $request ) { $object = $this->get_object( (int) $request['id'] ); $response = new WP_REST_Response(); $response->set_status( 204 ); if ( is_wp_error( $object ) ) { // Course not found, we don't return a 404. if ( in_array( 'llms_rest_not_found', $object->get_error_codes(), true ) ) { return $response; } return $object; } $post_type_object = get_post_type_object( $this->post_type ); $post_type_name = $post_type_object->labels->singular_name; $id = $object->get( 'id' ); $force = $this->is_delete_forced( $request ); // If we're forcing, then delete permanently. if ( $force ) { $result = wp_delete_post( $id, true ); } else { $supports_trash = $this->is_trash_supported(); // If we don't support trashing for this type, error out. if ( ! $supports_trash ) { return new WP_Error( 'llms_rest_trash_not_supported', /* translators: %1$s: post type name, %2$s: force=true */ sprintf( __( 'The %1$s does not support trashing. Set \'%2$s\' to delete.', 'lifterlms' ), $post_type_name, 'force=true' ), array( 'status' => 501 ) ); } // Otherwise, only trash if we haven't already. if ( 'trash' !== $object->get( 'status' ) ) { // (Note that internally this falls through to `wp_delete_post` if // the trash is disabled.) $result = wp_trash_post( $id ); } else { $result = true; } $request->set_param( 'context', 'edit' ); $object = $this->get_object( $id ); $response = $this->prepare_item_for_response( $object, $request ); } if ( ! $result ) { return new WP_Error( 'llms_rest_cannot_delete', /* translators: %s: post type name */ sprintf( __( 'The %s cannot be deleted.', 'lifterlms' ), $post_type_name ), array( 'status' => 500 ) ); } return $response; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
1.0.0-beta.1 | Introduced. |