Tribe__Events__Community__Main::doEventForm( int $id = null, boolean $shortcode = false )
Event editing form.
Contents
Parameters
- $id
-
(int) (Optional) the event's ID.
Default value: null
- $shortcode
-
(boolean) (Optional) .
Default value: false
Return
(string) The editing view markup.
Source
File: src/Tribe/Main.php
public function doEventForm( $id = null, $shortcode = false ) {
/**
* Allow the user to add content or functions above the submission page.
*
* @since 1.0
*
* @param int $id The event's ID.
*/
do_action( 'tribe_community_before_event_page', $id );
// Get various forms of the word "Event".
$events_label_singular = tribe_get_event_label_singular();
$events_label_plural = tribe_get_event_label_plural();
$events_label_singular_lowercase = tribe_get_event_label_singular_lowercase();
$output = '';
$show_form = true;
$event = null;
if ( $id ) {
$edit = true;
$tribe_event_id = $id = intval( $id );
} else {
$edit = false;
$tribe_event_id = null;
}
if ( $tribe_event_id && class_exists( 'Tribe__Events__Pro__Main' ) && tribe_is_recurring_event( $tribe_event_id ) ) {
$this->enqueueOutputMessage( sprintf( __( '%sWarning:%s You are editing a recurring %s. All changes will be applied to the entire series.', 'tribe-events-community' ), '<b>', '</b>', $events_label_singular_lowercase ), 'error' );
}
if ( $edit && $tribe_event_id ) {
$event = get_post( intval( $tribe_event_id ) );
}
// TODO: Not entirely sure this check is necessary. -- jbrinley
if ( $edit && ( ! $tribe_event_id || ! isset( $event->ID ) ) ) {
$this->enqueueOutputMessage( sprintf( __( '%s not found.', 'tribe-events-community' ), $events_label_singular ), '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>' . sprintf( __( 'You do not have permission to edit this %s.', 'tribe-events-community' ), $events_label_singular_lowercase ) . '</p>';
return $output;
}
// file upload check
if ( $this->max_file_size_exceeded() ) {
$this->enqueueOutputMessage( sprintf( __( 'The file you attempted to upload exceeded the maximum file size of %1$s.', 'tribe-events-community' ), size_format( $this->max_file_size_allowed() ) ), 'error' );
}
$this->loadScripts = true;
/**
* Allow the user to add content or functions above the submission form.
*
* @since 1.0
*/
do_action( 'tribe_ce_before_event_submission_page' );
$output .= '<div id="tribe-community-events" class="tribe-community-events form">';
if ( $this->allowAnonymousSubmissions || is_user_logged_in() ) {
$errors = array();
$submission = $this->get_submitted_event();
if ( ! empty( $submission ) ) {
if ( isset( $submission['post_ID'] ) ) {
$tribe_event_id = absint( $submission['post_ID'] );
}//end if
$handler = new Tribe__Events__Community__Submission_Handler( $submission, $tribe_event_id );
if ( $handler->validate() ) {
add_filter( 'tribe-post-origin', array( $this, 'filterPostOrigin' ) );
// Modify submit url only on the shortcode submission view.
if ( ! empty( $submission['community-shortcode-type'] ) && 'submission_form' === $submission['community-shortcode-type'] ) {
// Modify the default submission $link on Community Events form.
add_filter( 'tribe_events_community_submission_url', [ tribe( 'community.shortcodes' ), 'custom_nav_link' ] );
}
$tribe_event_id = $handler->save();
remove_filter( 'tribe-post-origin', array( $this, 'filterPostOrigin' ) );
delete_transient( 'tribe_community_events_today_page' ); //clear cache
if ( $tribe_event_id ) {
// email alerts
if ( $this->emailAlertsEnabled ) {
$this->sendEmailAlerts( $tribe_event_id );
}
} else {
// This is only to prevent bad images
$event = $this->create_event_object_from_submission( $handler->get_submission() );
}
} else {
$event = $this->create_event_object_from_submission( $handler->get_submission() );
$errors = $handler->get_invalid_fields();
}
$messages = $handler->get_messages();
$has_errors = in_array( 'error', wp_list_pluck( $messages, 'type' ) );
foreach ( $messages as $m ) {
if ( $has_errors && 'error' !== $m->type ) {
continue;
}
$this->enqueueOutputMessage( $m->message, $m->type );
}
}
if ( isset( $tribe_event_id ) && $edit ) {
$event = get_post( intval( $tribe_event_id ) );
} elseif ( empty( $event ) ) {
$event = new stdClass();
}
$GLOBALS['post'] = $event;
/**
* Allow the user to override the default "show form" logic.
*
* @since 1.0
*
* @param bool $show_form
*/
$show_form = apply_filters( 'tribe_community_events_show_form', $show_form );
if ( $show_form ) {
$tec_template = tribe_get_option( 'tribeEventsTemplate' );
if ( ! empty( $tec_template ) ) {
ob_start();
tribe_events_before_html();
$output .= ob_get_clean();
}
/**
* Allow the user to add content or functions right before the submission template is loaded.
*
* @since 1.0
*/
do_action( 'tribe_ce_before_event_submission_page_template' );
if ( empty( $submission ) || $this->messageType == 'error' ) {
$required = $this->required_fields_for_submission();
$this->event_form()->set_event( $event );
$this->event_form()->set_required_fields( $required );
$this->event_form()->set_error_fields( $errors );
$output .= $this->event_form()->render();
} else {
ob_start();
include Tribe__Events__Templates::getTemplateHierarchy( 'community/modules/header-links' );
if ( $shortcode ) {
$this->outputMessage();
}
$output .= ob_get_clean();
}
if ( ! empty( $tec_template ) ) {
ob_start();
tribe_events_after_html();
$output .= ob_get_clean();
}
}
}
$output .= '</div>';
wp_reset_query();
return $output;
}
Changelog
| Version | Description |
|---|---|
| 1.0 | Introduced. |