/**
  * Responds to ajax requests to access the ticket history.
  */
 public function supply_history()
 {
     if (!wp_verify_nonce(@$_POST['check'], 'view-ticket-history-' . @$_POST['ticket_id'])) {
         return;
     }
     $html = '<table>';
     $history = Tribe__Post_History::load($_POST['ticket_id']);
     foreach ($history->get_entries() as $entry) {
         $html .= '<tr> <td>' . esc_html($entry->datetime) . '</td> <td>' . $entry->message . '</td> </tr>';
     }
     $html .= '</table>';
     if (!$history->has_entries()) {
         $html = '<p>' . esc_html__('No history available', 'event-tickets') . '</p>';
     }
     wp_send_json_success(array('html' => $html));
 }
 /**
  * When a ticket type is moved, the tickets need to move with it. This callback takes
  * care of that process.
  *
  * @see Tribe__Tickets__Admin__Move_Ticket_Types::move_ticket_type()
  *
  * @param int $ticket_type_id
  * @param int $destination_post_id
  * @param int $src_post_id
  * @param int $instigator_id
  */
 public function move_all_tickets_for_type($ticket_type_id, $destination_post_id, $src_post_id, $instigator_id)
 {
     foreach (Tribe__Tickets__Tickets::get_event_attendees($src_post_id) as $issued_ticket) {
         // We're only interested in tickets of the specified type
         if ((int) $ticket_type_id !== (int) $issued_ticket['product_id']) {
             continue;
         }
         if (!class_exists($issued_ticket['provider'])) {
             continue;
         }
         $issued_ticket_id = $issued_ticket['attendee_id'];
         // Move the ticket to the destination post
         $event_key = constant($issued_ticket['provider'] . '::ATTENDEE_EVENT_KEY');
         update_post_meta($issued_ticket_id, $event_key, $destination_post_id);
         // Maintain an audit trail
         $history_message = sprintf(__('This ticket was moved to %1$s from %2$s', 'event-tickets'), '<a href="' . esc_url(get_the_permalink($destination_post_id)) . '" target="_blank">' . get_the_title($destination_post_id) . '</a>', '<a href="' . esc_url(get_the_permalink($src_post_id)) . '" target="_blank">' . get_the_title($src_post_id) . '</a>');
         $history_data = array('src_event_id' => $src_post_id, 'tgt_event_id' => $destination_post_id);
         Tribe__Post_History::load($issued_ticket_id)->add_entry($history_message, $history_data);
     }
 }