Tribe__Tickets__Metabox::ajax_ticket_add( bool $return_value = false )

Sanitizes the data for the new/edit ticket ajax call, and calls the child save_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_add() {
		$post_id = absint( tribe_get_request_var( 'post_id', 0 ) );

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

		/**
		 * This is needed because a provider can implement a dynamic set of fields.
		 * Each provider is responsible for sanitizing these values.
		 */
		$data = wp_parse_args( tribe_get_request_var( array( 'data' ), array() ), array() );

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

		if ( ! isset( $data['ticket_provider'] ) || ! $this->module_is_valid( $data['ticket_provider'] ) ) {
			wp_send_json_error( esc_html__( 'Commerce Provider invalid', 'event-tickets' ) );
		}

		// Get the Provider
		$module = call_user_func( array( $data['ticket_provider'], 'get_instance' ) );

		// Do the actual adding
		$ticket_id = $module->ticket_add( $post_id, $data );

		// Successful?
		if ( $ticket_id ) {
			/**
			 * Fire action when a ticket has been added
			 *
			 * @param int $post_id ID of parent "event" post
			 */
			do_action( 'tribe_tickets_ticket_added', $post_id );
		} else {
			wp_send_json_error( esc_html__( 'Failed to Add the Ticket', 'event-tickets' ) );
		}

		$return = $this->get_panels( $post_id );
		$return['notice'] = $this->notice( 'ticket-add' );

		/**
		 * Filters the return data for ticket add
		 *
		 * @param array $return Array of data to return to the ajax call
		 * @param int $post_id ID of parent "event" post
		 */
		$return = apply_filters( 'event_tickets_ajax_ticket_add_data', $return, $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
4.10.9 Introduced.