self::$_instance = new self(); } return self::$_instance; } /** * Constructor */ public function __construct()
/** * Constructor. */ public function __construct() { add_action('wp', array($this, 'process')); $this->steps = (array) apply_filters('submit_event_steps', array('submit' => array('name' => __('Submit Details', 'gam-event-manager'), 'view' => array($this, 'submit'), 'handler' => array($this, 'submit_handler'), 'priority' => 10), 'preview' => array('name' => __('Preview', 'gam-event-manager'), 'view' => array($this, 'preview'), 'handler' => array($this, 'preview_handler'), 'priority' => 20), 'done' => array('name' => __('Done', 'gam-event-manager'), 'view' => array($this, 'done'), 'priority' => 30))); uasort($this->steps, array($this, 'sort_by_priority')); // Get step/event if (isset($_POST['step'])) { $this->step = is_numeric($_POST['step']) ? max(absint($_POST['step']), 0) : array_search($_POST['step'], array_keys($this->steps)); } elseif (!empty($_GET['step'])) { $this->step = is_numeric($_GET['step']) ? max(absint($_GET['step']), 0) : array_search($_GET['step'], array_keys($this->steps)); } $this->event_id = !empty($_REQUEST['event_id']) ? absint($_REQUEST['event_id']) : 0; // Allow resuming from cookie. if (!$this->event_id && !empty($_COOKIE['gam-event-manager-submitting-event-id']) && !empty($_COOKIE['gam-event-manager-submitting-event-key'])) { $event_id = absint($_COOKIE['gam-event-manager-submitting-event-id']); $event_status = get_post_status($event_id); if ('preview' === $event_status && get_post_meta($event_id, '_submitting_key', true) === $_COOKIE['gam-event-manager-submitting-event-key']) { $this->event_id = $event_id; } } // Load event details if ($this->event_id) { $event_status = get_post_status($this->event_id); if ('expired' === $event_status) { if (!event_manager_user_can_edit_event($this->event_id)) { $this->event_id = 0; $this->step = 0; } } elseif (!in_array($event_status, apply_filters('event_manager_valid_submit_event_statuses', array('preview')))) { $this->event_id = 0; $this->step = 0; } } }
/** * Handles actions on event dashboard */ public function event_dashboard_handler() { if (!empty($_REQUEST['action']) && !empty($_REQUEST['_wpnonce']) && wp_verify_nonce($_REQUEST['_wpnonce'], 'event_manager_my_event_actions')) { $action = sanitize_title($_REQUEST['action']); $event_id = absint($_REQUEST['event_id']); try { // Get Event $event = get_post($event_id); // Check ownership if (!event_manager_user_can_edit_event($event_id)) { throw new Exception(__('Invalid ID', 'gam-event-manager')); } switch ($action) { case 'mark_cancelled': // Check status if ($event->_cancelled == 1) { throw new Exception(__('This event has already been cancelled', 'gam-event-manager')); } // Update update_post_meta($event_id, '_cancelled', 1); // Message $this->event_dashboard_message = '<div class="event-manager-message">' . sprintf(__('%s has been cancelled', 'gam-event-manager'), $event->post_title) . '</div>'; break; case 'mark_not_cancelled': // Check status if ($event->_cancelled != 1) { throw new Exception(__('This event is not cancelled', 'gam-event-manager')); } // Update update_post_meta($event_id, '_cancelled', 0); // Message $this->event_dashboard_message = '<div class="event-manager-message">' . sprintf(__('%s has been marked as not cancelled', 'gam-event-manager'), $event->post_title) . '</div>'; break; case 'delete': // Trash it wp_trash_post($event_id); // Message $this->event_dashboard_message = '<div class="event-manager-message">' . sprintf(__('%s has been deleted', 'gam-event-manager'), $event->post_title) . '</div>'; break; case 'relist': // redirect to post page wp_redirect(add_query_arg(array('event_id' => absint($event_id)), event_manager_get_permalink('submit_event_form'))); break; default: do_action('event_manager_event_dashboard_do_action_' . $action); break; } do_action('event_manager_my_event_do_action', $action, $event_id); } catch (Exception $e) { $this->event_dashboard_message = '<div class="event-manager-error">' . $e->getMessage() . '</div>'; } } }
exit; } global $event_manager; ?> <form action="<?php echo esc_url($action); ?> " method="post" id="submit-event-form" class="event-manager-form" enctype="multipart/form-data"> <?php if (apply_filters('submit_event_form_show_signin', true)) { ?> <?php get_event_manager_template('account-signin.php'); ?> <?php } ?> <?php if (event_manager_user_can_post_event() || event_manager_user_can_edit_event($event_id)) { ?> <!-- Event Information Fields --> <h2 class="section-title"><?php _e('Event Details', 'gam-event-manager'); ?> </h2> <?php do_action('submit_event_form_event_fields_start'); ?> <?php foreach ($event_fields as $key => $field) { ?>