Created
November 13, 2017 14:01
-
-
Save CarloMartini/cc4083b4cf3634c74a910a3ae80f44b6 to your computer and use it in GitHub Desktop.
bookin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'booking-form.php'; | |
require 'register-booking.php'; | |
require 'register-event.php'; | |
require 'booking-notification.php'; | |
require_once 'e42-booking-calendar.php'; | |
include 'ChromePhp.php'; | |
class MP_Booking { | |
public static function init() { | |
//include 'views/form.php'; | |
MP_Booking_Register::init(); | |
MP_Event_Register::init(); | |
load_plugin_textdomain('map-booking', false, basename( dirname( __FILE__ ) ).'/languages'); | |
} | |
public static function register_meta_boxes() { | |
MP_Booking_Register::register_meta_boxes(); | |
} | |
public static function submit_form() { | |
if(isset($_POST['map_booking'])) { | |
$booking_info = array ( | |
'name' => $_POST['map_first_name'] . ' ' . $_POST['map_last_name'], | |
'first_name' => $_POST['map_first_name'], | |
'last_name' => $_POST['map_last_name'], | |
'mail' => $_POST['map_mail'], | |
'language' => $_POST['map_language'], | |
'seats' => $_POST['map_number_seats'], | |
'event' => $_POST['map_show'], | |
'date' => $_POST['map_booking_day'], | |
); | |
PC::debug($booking_info, "booking_info in submit_form(): "); | |
$booking_id = self::insert_post($booking_info); | |
PC::debug($booking_id, "booking_id in submit_form(): "); | |
MP_Notification::send_request($booking_id); | |
wp_redirect($_POST['map_redirect_url']); // add a hidden input with get_permalink() | |
exit; | |
} | |
} | |
private static function insert_post($booking_info) { | |
$booking = array( | |
'post_title' => $booking_info['name'], | |
'post_type' => 'booking', | |
'post_status' => 'publish', | |
'post_date' => date('Y-m-d H:i:s', strtotime('now')), | |
'post_author' => 1, | |
); | |
PC::debug($booking_info,"booking_info in insert_post()"); | |
$booking_id = wp_insert_post($booking); | |
PC::debug($booking_id,"booking_id (NEW) in insert_post()"); | |
add_post_meta($booking_id, 'booking_first_name', $booking_info['first_name'], true); | |
add_post_meta($booking_id, 'booking_last_name', $booking_info['last_name'], true); | |
$mail = add_post_meta($booking_id, 'booking_email', $booking_info['mail'], true); | |
PC::debug($mail, "Mail META ID"); | |
add_post_meta($booking_id, 'booking_language',$booking_info['language'], true); | |
add_post_meta($booking_id, 'booking_seats', $booking_info['seats'], true); | |
add_post_meta($booking_id, 'booking_show', $booking_info['event'], true); | |
add_post_meta($booking_id, 'booking_date', $booking_info['date'], true); | |
add_post_meta($booking_id, 'booking_state', 'Richiesto', true); | |
$postCustom = get_post_custom($booking_id); | |
PC::debug($postCustom, "Custom Fields"); | |
$allMeta = get_post_meta($booking_id); | |
PC::debug($allMeta,"All Post Meta"); | |
return $booking_id; | |
} | |
} | |
add_action('init', 'MP_Booking::init'); | |
add_action('init', array('MP_Booking', 'submit_form')); | |
add_action('add_meta_boxes', 'MP_Booking_Register::register_meta_boxes'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment