Tribe__Tickets__Metabox::ajax_ticket_delete( bool $return_value = false )

Sanitizes the data for the delete ticket ajax call, and calls the child delete_ticket function.


Parameters

$return_value

(bool) (Optional) flags whether to JSON output directly or return results.

Default value: false


Top ↑

Return

(void|WP_Error|array) The results depending on $return_value param, WP_Error if something went wrong.


Top ↑

Source

File: src/Tribe/Metabox.php

	public function ajax_ticket_delete() {
		$post_id = absint( tribe_get_request_var( 'post_id', 0 ) );

		if ( ! $post_id ) {
			wp_send_json_error( esc_html__( 'Invalid parent Post', 'event-tickets' ) );
		}

		$ticket_id = absint( tribe_get_request_var( 'ticket_id', 0 ) );

		if ( ! $ticket_id ) {
			wp_send_json_error( esc_html__( 'Invalid Ticket', 'event-tickets' ) );
		}

		if ( ! $this->has_permission( $post_id, $_POST, 'remove_ticket_nonce' ) ) {
			wp_send_json_error( esc_html__( 'Failed to Delete the Ticket, Refresh the Page to try again.', 'event-tickets' ) );
		}

		$provider = tribe_tickets_get_ticket_provider( $ticket_id );

		if ( ! $provider ) {
			wp_send_json_error( esc_html__( 'Commerce Module invalid', 'event-tickets' ) );
		}

		// Pass the control to the child object
		$return = $provider->delete_ticket( $post_id, $ticket_id );

		// Successfully deleted?
		if ( $return ) {
			$return = $this->get_panels( $post_id );
			$return['notice'] = $this->notice( 'ticket-delete' );

			/**
			 * 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 );
		}

		wp_send_json_success( $return );
	}

Top ↑

Changelog

Changelog
Version Description
5.5.7 Added optional parameter to return values instead of echoing directly.
4.6.2 Introduced.