Tribe__Tickets__Admin__Move_Tickets::move_tickets_request()
Listens for and handles requests to reassign tickets from one ticket type to another.
Source
File: src/Tribe/Admin/Move_Tickets.php
public function move_tickets_request() {
if ( ! wp_verify_nonce( $_POST['check'], 'move_tickets' ) ) {
wp_send_json_error();
}
$args = wp_parse_args( $_POST, array(
'ticket_ids' => '',
'target_type_id' => '',
'src_post_id' => '',
'target_post_id' => '',
) );
$src_post_id = absint( $args['src_post_id' ] );
$ticket_ids = array_map( 'intval', (array) $args['ticket_ids' ] );
$target_type_id = absint( $args['target_type_id'] );
$target_post_id = absint( $args['target_post_id'] );
if ( ! $ticket_ids || ! $target_type_id ) {
wp_send_json_error( array(
'message' => __( 'Tickets could not be moved: valid ticket IDs or a destination ID were not provided.', 'event-tickets' ),
) );
}
$moved_tickets = $this->move_tickets( $ticket_ids, $target_type_id, $src_post_id, $target_post_id );
if ( ! $moved_tickets ) {
wp_send_json_error( array(
'message' => __( 'Tickets could not be moved: there was an unexpected failure during reassignment.', 'event-tickets' ),
) );
}
$remove_tickets = ( $src_post_id != $target_post_id ) ? $ticket_ids : null;
// Include details of the new ticket type the tickets were reassigned to
$moved_to = sprintf(
_x( 'assigned to %s', 'moved tickets success message fragment', 'event-tickets' ),
'<a href="' . esc_url( get_admin_url( null, '/post.php?post=' . $target_type_id . '&action=edit' ) ) . '" target="_blank">' . get_the_title( $target_type_id ) . '</a>'
);
// If that ticket type is hosted by a different event post, prepend details of that also
if ( $src_post_id !== $target_post_id ) {
$moved_to = sprintf(
_x( 'moved to %s and', 'moved tickets success message fragment', 'event-tickets' ),
'<a href="' . esc_url( get_admin_url( null, '/post.php?post=' . $target_post_id . '&action=edit' ) ) . '" target="_blank">' . get_the_title( $target_post_id ) . '</a>'
) . ' ' . $moved_to;
}
wp_send_json_success( array(
'message' => sprintf(
_n(
'%1$d attendee for %2$s was successfully %3$s. By default, we adjust capacity and stock, however, we recommend reviewing each as needed to ensure numbers are correct. This attendee will receive an email notifying them of the change.',
'%1$d attendees for %2$s were successfully %3$s. By default, we adjust capacity and stock, however, we recommend reviewing each as needed to ensure numbers are correct. These attendees will receive an email notifying them of the change.',
$moved_tickets,
'event-tickets'
),
$moved_tickets,
'<a href="' . esc_url( get_admin_url( null, '/post.php?post=' . $src_post_id . '&action=edit' ) ) . '" target="_blank">' . get_the_title( $src_post_id ) . '</a>',
$moved_to
),
'remove_tickets' => $remove_tickets,
) );
}
Changelog
| Version | Description |
|---|---|
| 4.10.9 | Introduced. |