Tribe__Tickets__Editor__REST__V1__Endpoints__Single_ticket::delete( $request )
{@inheritdoc}
Source
File: src/Tribe/Editor/REST/V1/Endpoints/Single_Ticket.php
public function delete( WP_REST_Request $request ) {
$ticket_id = $request['id'];
$ticket_data = $this->get_readable_ticket_data( $ticket_id );
if ( $ticket_data instanceof WP_Error ) {
return $ticket_data;
}
$body = $request->get_body_params();
$post_id = $body['post_id'];
$nonce_action = 'remove_ticket_nonce';
$nonce = $body[ $nonce_action ];
if ( ! $this->has_permission( $post_id, $nonce, $nonce_action ) ) {
return new WP_Error(
'forbidden',
__( 'Invalid nonce', 'event-tickets' ),
array( 'status' => 403 )
);
}
$provider = tribe_tickets_get_ticket_provider( $ticket_id );
if ( ! $provider ) {
return new WP_Error(
'bad_request',
__( 'Commerce Module invalid', 'event-tickets' ),
array( 'status' => 400 )
);
}
// Pass the control to the child object
$return = $provider->delete_ticket( $post_id, $ticket_id );
// Successfully deleted?
if ( $return ) {
/**
* Fire action when a ticket has been deleted
*
* @param int $post_id ID of parent "event" post
*/
do_action( 'tribe_tickets_ticket_deleted', $post_id );
}
$response = new WP_REST_Response( $return );
$response->set_status( 202 );
return $response;
}