/** * Event editing form. * * @param int $id the event's ID. * @return string The editing view markup. * @author Nick Ciske * @since 1.0 */ public function doEventForm($id = null) { if (class_exists('TribeEventsPro')) { // venue and organizer defaults- override ECP defaults add_filter('tribe_get_single_option', array($this, 'filter_default_venue_id'), 10, 3); add_filter('tribe_get_single_option', array($this, 'filter_default_organizer_id'), 10, 3); } add_filter('tribe-post-origin', array($this, 'filterPostOrigin')); $output = ''; $show_form = true; $event = null; if ($id) { $edit = true; $tribe_event_id = $id; } else { $edit = false; $tribe_event_id = null; } if ($tribe_event_id && class_exists('TribeEventsPro') && tribe_is_recurring_event($tribe_event_id)) { $this->enqueueOutputMessage(sprintf(__('%sWarning:%s You are editing a recurring event. All changes will be applied to the entire series.', 'tribe-events-community'), '<b>', '</b>'), 'error'); } // Delete the featured image, if there was a request to do so. if (isset($_GET['action']) && $_GET['action'] == 'deleteFeaturedImage' && wp_verify_nonce($_GET['_wpnonce'], 'tribe_community_events_featured_image_delete') && current_user_can('edit_post', $tribe_event_id)) { $featured_image_id = get_post_thumbnail_id($tribe_event_id); delete_post_meta($tribe_event_id, '_thumbnail_id'); wp_delete_attachment($featured_image_id, true); } if ($edit && $tribe_event_id) { $event = get_post(intval($tribe_event_id)); global $post; $old_post = $post; $post = $event; } if ($edit && (!$tribe_event_id || !isset($event->ID))) { $this->enqueueOutputMessage(__('Event not found.', 'tribe-events-community'), 'error'); $output = $this->outputMessage(null, false); $show_form = false; } // login check if (!$this->allowAnonymousSubmissions && !is_user_logged_in() || $edit && $tribe_event_id && !is_user_logged_in()) { do_action('tribe_ce_event_submission_login_form'); $output .= $this->login_form(__('Please log in first.', 'tribe-events-community')); return $output; } // security check if ($edit && $tribe_event_id && !current_user_can('edit_post', $tribe_event_id)) { $output .= '<p>' . __('You do not have permission to edit this event.', 'tribe-events-community') . '</p>'; return $output; } $this->loadScripts = true; do_action('tribe_ce_before_event_submission_page'); $output .= '<div id="tribe-community-events" class="form">'; if ($this->allowAnonymousSubmissions || is_user_logged_in()) { $current_user = wp_get_current_user(); if (class_exists('TribeEventsPro')) { $tribe_ecp = TribeEventsPro::instance(); } $submission = $this->get_submitted_event(); if (!empty($submission)) { // show no sympathy for spammers if (!is_user_logged_in()) { $this->spam_check($submission); } $submission['ID'] = $tribe_event_id; require_once 'tribe-community-events-submission-scrubber.php'; $scrubber = new TribeCommunityEvents_SubmissionScrubber($submission); $_POST = $scrubber->scrub(); // update the event if ($tribe_event_id && $this->validate_submission_has_required_fields($_POST)) { if ($this->saveEvent($tribe_event_id)) { $this->enqueueOutputMessage(__('Event updated.', 'tribe-events-community') . $this->get_view_edit_links($tribe_event_id)); $this->enqueueOutputMessage('<a href="' . $this->getUrl('add') . '">' . __('Submit another event', 'tribe-events-community') . '</a>'); delete_transient('tribe_community_events_today_page'); //clear cache } else { $this->enqueueOutputMessage($this->get_error_message($_POST, $tribe_event_id), 'error'); } } else { // or create a new one $_POST['post_status'] = $this->defaultStatus; if ($this->validate_submission_has_required_fields($_POST)) { $tribe_event_id = $this->createEvent(); } if ($tribe_event_id) { $this->enqueueOutputMessage(__('Event submitted.', 'tribe-events-community') . $this->get_view_edit_links($tribe_event_id)); $this->enqueueOutputMessage('<a href="' . $this->getUrl('add') . '">' . __('Submit another event', 'tribe-events-community') . '</a>'); // email alerts if ($this->emailAlertsEnabled) { $this->sendEmailAlerts($tribe_event_id); } } else { $this->enqueueOutputMessage($this->get_error_message($_POST, $tribe_event_id), 'error'); //get event info from POST $event = $this->getInfoFromPost(); } } } // are we editing an event? if (isset($tribe_event_id) && $edit) { // global $post; // $event = get_post(intval($tribe_event_id)); } else { if (empty($event)) { $event = new stdClass(); } if (isset($_POST['post_title'])) { $event->post_title = $_POST['post_title']; } if (isset($_POST['post_content'])) { $event->post_content = $_POST['post_content']; } } $show_form = apply_filters('tribe_community_events_show_form', $show_form); if ($show_form) { remove_filter('the_content', 'do_shortcode', 11); //get data from $_POST and override core function add_filter('tribe_get_hour_options', array($this, 'getHours'), 10, 3); add_filter('tribe_get_minute_options', array($this, 'getMinutes'), 10, 3); add_filter('tribe_get_meridian_options', array($this, 'getMeridians'), 10, 3); //turn off upsell -- this is public after all remove_action('tribe_events_cost_table', array(TribeEvents::instance(), 'maybeShowMetaUpsell')); if (class_exists('Event_Tickets_PRO')) { // Remove the eventbrite method hooked into the event form, if it exists. remove_action('tribe_events_cost_table', array(Event_Tickets_PRO::instance(), 'eventBriteMetaBox'), 1); } if (class_exists('TribeEventsPro')) { remove_action('tribe_events_date_display', array('TribeEventsRecurrenceMeta', 'loadRecurrenceData')); add_action('tribe_events_date_display', array($this, 'loadRecurrenceData')); } do_action('tribe_ce_before_event_submission_page_template'); $edit_template = TribeEventsTemplates::getTemplateHierarchy('community/edit-event', array('disable_view_check' => true)); ob_start(); if (empty($_POST) || $this->messageType == 'error') { do_action('tribe_events_community_form', $tribe_event_id, $event, $edit_template); } else { include TribeEventsTemplates::getTemplateHierarchy('community/modules/header-links'); } $output .= ob_get_clean(); } $output .= '</div>'; } wp_reset_query(); remove_filter('tribe-post-origin', array($this, 'filterPostOrigin')); return $output; }