Tribe__Events__Community__Main::doOrganizerForm( int $organizer_id )
The front-end “edit organizer” form.
Contents
Parameters
- $organizer_id
-
(int) (Required) The organizer's ID.
Return
(string) The form.
Source
File: src/Tribe/Main.php
public function doOrganizerForm( $organizer_id ) {
$valid = false;
$organizer_id = intval( $organizer_id );
add_filter( 'tribe-post-origin', array( $this, 'filterPostOrigin' ) );
// Some preliminary checks to ensure editing the organizer is allowed.
if ( ! $organizer_id ) {
return '<p>' . esc_html__( 'Organizer not found.', 'tribe-events-community' ) . '</p>';
}
if ( Tribe__Events__Main::ORGANIZER_POST_TYPE !== get_post_type( $organizer_id ) ) {
return '<p>' . esc_html__( 'Only an Organizer can be edited on this page.', 'tribe-events-community' ) . '</p>';
}
if ( ! is_user_logged_in() ) {
return $this->login_form( esc_html__( 'Please log in to edit this organizer', 'tribe-events-community' ) );
}
if ( ! current_user_can( 'edit_post', $organizer_id ) ) {
return '<p>' . esc_html__( 'You do not have permission to edit this organizer.', 'tribe-events-community' ) . '</p>';
}
/**
* Filter Community Events Required Organizer Fields
*
* @param array of fields to validate - Organizer, Phone, Website, Email
*/
$required_organizer_fields = apply_filters( 'tribe_events_community_required_organizer_fields', array() );
// Begin the actual edit-organizer form now that user is confirmed to be allowed to be here.
$this->loadScripts = true;
$output = '<div id="tribe-community-events" class="form organizer">';
if ( Tribe__Utils__Array::get( $_POST, 'community-event', false ) ) {
if ( ! check_admin_referer( 'ecp_organizer_submission' ) ) {
$this->enqueueOutputMessage( esc_html__( 'There was a problem updating this organizer, please try again.', 'tribe-events-community' ), 'error' );
}
if ( ! isset( $_POST[ 'post_title' ] ) ) {
$this->enqueueOutputMessage( esc_html__( 'Organizer name cannot be blank.', 'tribe-events-community' ), 'error' );
}
$_POST['ID'] = $organizer_id;
$scrubber = new Tribe__Events__Community__Organizer_Submission_Scrubber( $_POST );
$_POST = $scrubber->scrub();
$invalid_fields = array();
$has_all_required_fields = true;
foreach ( $required_organizer_fields as $field ) {
// This array of required fields is shared with the submission form, on which the existence of an Organizer is not a given.
// Here on the edit-organizer form, though, it *is* a given, so we can skip checking the parent 'Organizer' field to prevent unnecessary messages about it.
if ( 'Organizer' === $field ) {
continue;
}
$required_field = Tribe__Utils__Array::get( $_POST, array( 'organizer', $field ), '' );
if ( empty( $required_field ) ) {
$this->enqueueOutputMessage( sprintf( esc_html__( '%1$s required', '"{Field name} required" text for error message above edit-organizer form in Community Events.', 'tribe-events-community' ), $field ), 'error' );
$has_all_required_fields = false;
}
}
remove_action( 'save_post_'.Tribe__Events__Main::ORGANIZER_POST_TYPE, array( Tribe__Events__Main::instance(), 'save_organizer_data' ), 16, 2 );
if ( $has_all_required_fields ) {
wp_update_post( array(
'post_title' => $_POST[ 'post_title' ],
'ID' => $organizer_id,
'post_content' => $_POST[ 'post_content' ],
) );
Tribe__Events__API::updateOrganizer( $organizer_id, $_POST['organizer'] );
$this->enqueueOutputMessage( esc_html__( 'Organizer updated.', 'tribe-events-community' ) );
}
}
global $post;
$post = get_post( $organizer_id );
ob_start();
include Tribe__Events__Templates::getTemplateHierarchy( 'community/edit-organizer' );
$output .= ob_get_clean();
$output .= '</div>';
remove_filter( 'tribe-post-origin', array( $this, 'filterPostOrigin' ) );
return $output;
}
Changelog
| Version | Description |
|---|---|
| 1.0 | Introduced. |