Tribe__Tickets__Metabox::ajax_ticket_duplicate( bool $return_value = false )

Sanitizes the data for the duplicate ticket ajax call, then duplicates the ticket and meta.


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_duplicate() {
		$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( sprintf(
				// Translators: %s: dynamic "ticket" text.
				__( 'Invalid %s', 'event-tickets' ),
				tribe_get_ticket_label_singular( 'ajax_ticket_duplicate_error' )
			) ) );
		}

		if ( ! $this->has_permission( $post_id, $_POST, 'duplicate_ticket_nonce' ) ) {
			wp_send_json_error( esc_html( sprintf(
				// Translators: %s: dynamic "ticket" text.
				__( 'Failed to duplicate the %s. Refresh the page to try again.', 'event-tickets' ),
				tribe_get_ticket_label_singular( 'ajax_ticket_duplicate_error' )
			) ) );
		}

		$provider = tribe_tickets_get_ticket_provider( $ticket_id );

		if ( empty( $provider ) || ! $provider instanceof Tribe__Tickets__Tickets ) {
			return new WP_Error(
				'bad_request',
				__( 'Commerce Module invalid', 'event-tickets' ),
				[ 'status' => 400 ]
			);
		}

		$duplicate_ticket_id = $provider->duplicate_ticket( $post_id, $ticket_id );

		// Successful?
		if ( $duplicate_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( sprintf( __( 'Failed to duplicate the %s', 'event-tickets' ), tribe_get_ticket_label_singular( 'ajax_ticket_duplicate_error' ) ) ) );
		}

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

		/**
		 * Filters the return data for ticket duplicate.
		 *
		 * @since 5.2.3
		 *
		 * @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_duplicate_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.
5.2.3. Introduced.