get_query_var( 'be_community' ) ? false : $url ); add_filter( 'document_title_parts', static function ( array $parts ): array { $view = get_query_var( 'be_community' ); if ( in_array( $view, [ 'submit', 'mine' ], true ) ) { $parts['title'] = 'mine' === $view ? __( 'My events', 'burn-events' ) : __( 'Submit an event', 'burn-events' ); } return $parts; } ); add_action( 'template_redirect', static function (): void { if ( get_query_var( 'be_community' ) ) { nocache_headers(); } } ); add_action( 'admin_post_burn_event_submit', [ self::class, 'submit' ] ); add_action( 'admin_post_nopriv_burn_event_submit', [ self::class, 'submit' ] ); add_action( 'admin_post_burn_event_withdraw', [ self::class, 'withdraw' ] ); } public static function url( string $view ): string { return get_option( 'permalink_structure' ) ? home_url( user_trailingslashit( 'events/' . $view ) ) : add_query_arg( 'be_community', $view, home_url( '/' ) ); } private static function owned( int $id ): ?WP_Post { $post = $id && is_user_logged_in() ? get_post( $id ) : null; return $post && Events::EVENT === $post->post_type && 'trash' !== $post->post_status && (int) $post->post_author === get_current_user_id() && get_post_meta( $post->ID, '_burn_community', true ) ? $post : null; } public static function form(): string { $options = Admin::options(); $id = absint( Calendar::request( 'be_edit' ) ); $post = $id && $options['community_edit'] ? self::owned( $id ) : null; ob_start(); ?>

array_filter( [ $options['venue'] ] ), 'organizer' => array_filter( [ $options['organizer'] ] ) ]; Admin::event_fields( $post ? Events::event_data( $id ) : $defaults, true ); $terms = get_terms( [ 'taxonomy' => Events::CATEGORY, 'hide_empty' => false ] ); $selected = $post ? wp_get_post_terms( $id, Events::CATEGORY, [ 'fields' => 'ids' ] ) : []; ?>
720 || strlen( $body ) > 48000 || ! is_array( $_POST['be'] ?? null ) ) { self::fail( __( 'Enter a title, description, and event schedule.', 'burn-events' ) ); } $event = null; try { $input = wp_unslash( $_POST['be'] ); unset( $input['status'], $input['series'], $input['featured'], $input['hidden'] ); $data = Events::validate_event( $input ); if ( $post ) { $old = Events::event_data( $id ); foreach ( [ 'status', 'series', 'featured', 'hidden' ] as $field ) { $data[ $field ] = $old[ $field ]; } } $attributes = [ 'post_type' => Events::EVENT, 'post_title' => $title, 'post_content' => $body, 'post_status' => 'pending', 'comment_status' => 'closed', ]; $event = $id ? wp_update_post( wp_slash( $attributes + [ 'ID' => $id ] ), true ) : wp_insert_post( wp_slash( $attributes + [ 'post_author' => get_current_user_id() ] ), true ); if ( is_wp_error( $event ) ) { self::fail( $event->get_error_message() ); } Events::save( $event, $data ); update_post_meta( $event, '_burn_community', '1' ); $categories = array_values( array_filter( array_map( 'absint', (array) ( $_POST['event_categories'] ?? [] ) ) ) ); wp_set_object_terms( $event, $categories, Events::CATEGORY ); if ( is_user_logged_in() && UPLOAD_ERR_OK === ( $_FILES['event_image']['error'] ?? UPLOAD_ERR_NO_FILE ) ) { self::image( $event ); } } catch ( \Throwable $error ) { if ( ! $id && is_int( $event ) ) { wp_trash_post( $event ); } self::fail( $error->getMessage() ); } set_transient( $rate_key, '1', 10 ); wp_safe_redirect( add_query_arg( 'be_sent', '1', self::url( 'submit' ) ), 303 ); exit; } private static function image( int $event ): void { require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/media.php'; require_once ABSPATH . 'wp-admin/includes/image.php'; $file = media_handle_upload( 'event_image', $event, [], [ 'test_form' => false, 'mimes' => [ 'jpg|jpeg' => 'image/jpeg', 'png' => 'image/png', 'webp' => 'image/webp' ], ] ); if ( ! is_wp_error( $file ) ) { set_post_thumbnail( $event, $file ); } } public static function mine(): string { $page = max( 1, min( 1000, absint( Calendar::request( 'be_page' ) ) ) ); $list = is_user_logged_in() ? new \WP_Query( [ 'post_type' => Events::EVENT, 'post_status' => [ 'publish', 'pending', 'draft', 'future' ], 'author' => get_current_user_id(), 'posts_per_page' => 20, 'paged' => $page, 'meta_key' => '_burn_community', 'meta_value' => '1', ] ) : null; ob_start(); ?>

posts ) : ?>

add_query_arg( 'be_page', '%#%', self::url( 'mine' ) ), 'format' => '', 'total' => $list->max_num_pages, 'current' => $page ] ) ); ?>
$status, 'back_link' => true ] ); } }