public function res_admin_update_booking_callback() { // Check if user is logged in or die Resource_Booking_Ajax_Common::check_if_user_logged_in_or_die(); // Check if user is a labmanager or die Resource_Booking_Ajax_Common::check_if_labmanager_or_die(); // If here, user is labmanager (hopefully) $booking_id = isset($_POST['id']) ? intval($_POST['id'], 10) : 0; $resource_id = isset($_POST['resource_id']) ? intval($_POST['resource_id'], 10) : 0; $start = isset($_POST['start']) ? $_POST['start'] : null; $end = isset($_POST['end']) ? $_POST['end'] : null; //Check if resource exists $resource_info = Resource_Booking_Ajax_Common::get_resource_info_or_die($this->rb_db, $resource_id, "array"); // Check if valid dates && valid interval Resource_Booking_Ajax_Common::check_if_valid_start_end_i_u_d_or_die($start, $end, $resource_info); // Check if it doesn't overlap any booking or die Resource_Booking_Ajax_Common::check_if_not_overlapping_or_die($this->rb_db, $resource_id, $booking_id, $start, $end); // Validation done - good to update data // Update the reservation $booking = $this->rb_db->update_booking($booking_id, $resource_id, null, $start, $end); if (false === $booking) { // And die wp_send_json_error(array("message" => "Could not update the reservation!")); } else { $response = new stdClass(); $response->success = true; $response->booking = array("id" => $booking->id, "resource_id" => $booking->resource_id, "user_id" => $booking->user_id, "username" => esc_html($booking->username), "start" => $booking->start, "end" => $booking->end, "details" => esc_html($booking->details), "personal" => true); echo json_encode($response); wp_die(); // this is required to terminate immediately and return a proper response } }