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
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 | if ( ! $this ->check_delete_permission( $object ) ) { return llms_rest_authorization_required_error( sprintf( // Translators: %s = The post type name. __( 'Sorry, you are not allowed to delete %s as this user.' , 'lifterlms' ), get_post_type_object( $this ->post_type )->labels->name ) ); } return true; } /** * Deletes a single llms post. * * @since 1.0.0-beta.1 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */ 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.) |
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
1.0.0-beta.1 | Introduced. |