true ) ); if ( $post && 'auto-draft' !== $post->post_status && RSVP::enabled( $post->ID ) ) { add_meta_box( 'evw-attendees', __( 'RSVPs', 'eventwright' ), array( __CLASS__, 'attendees_box' ), Post_Types::EVENT, 'side', 'default' ); } add_meta_box( 'evw-venue', __( 'Venue details', 'eventwright' ), array( __CLASS__, 'venue_box' ), Post_Types::VENUE, 'normal', 'high' ); add_meta_box( 'evw-organizer', __( 'Organizer details', 'eventwright' ), array( __CLASS__, 'organizer_box' ), Post_Types::ORGANIZER, 'normal', 'high' ); } /** * Text input row. * * @param string $name Field name. * @param string $label Label. * @param string $value Value. * @param string $type Input type. * @param string $extra Extra attributes (already escaped). */ private static function input_row( $name, $label, $value, $type = 'text', $extra = '' ) { $id = 'evw-' . str_replace( '_', '-', $name ); echo '


'; echo '

'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $extra is a fixed string from this class. } /** * Event box (classic editor only; the block editor uses the sidebar panel). * * @param \WP_Post $post Post. */ public static function event_box( $post ) { wp_nonce_field( 'evwr_save_event', '_evwr_event_nonce' ); $m = function ( $k ) use ( $post ) { return get_post_meta( $post->ID, $k, true ); }; $start = (string) $m( '_evwr_start' ); $end = (string) $m( '_evwr_end' ); $all_day = (bool) $m( '_evwr_all_day' ); $tz = (string) $m( '_evwr_timezone' ); $rule = Recurrence::get_rule( $post->ID ); $venues = get_posts( array( 'post_type' => Post_Types::VENUE, 'post_status' => array( 'publish', 'draft', 'private' ), 'posts_per_page' => 500, 'orderby' => 'title', 'order' => 'ASC', ) ); $orgs = get_posts( array( 'post_type' => Post_Types::ORGANIZER, 'post_status' => array( 'publish', 'draft', 'private' ), 'posts_per_page' => 500, 'orderby' => 'title', 'order' => 'ASC', ) ); $org_ids = array_map( 'intval', (array) $m( '_evwr_organizer_ids' ) ); ?>








$s, 'end' => gmdate( 'Y-m-d H:i:s', strtotime( $s . ' UTC' ) + max( 0, $tf ) ), ); } } $exdates = array_filter( array_map( 'trim', preg_split( '/[\r\n]+/', isset( $in['exdates'] ) ? (string) $in['exdates'] : '' ) ) ); $rule = array( 'freq' => $g( 'freq', 'none' ), 'interval' => $g( 'interval', 1 ), 'byday' => (array) $g( 'byday', array() ), 'monthly' => $g( 'monthly', 'day' ), 'nth' => $g( 'nth', 1 ), 'nth_day' => $g( 'nth_day', 'MO' ), 'end' => $g( 'end', 'never' ), 'until' => $g( 'until' ), 'count' => $g( 'count', 0 ), 'rdates' => $rdates, 'exdates' => $exdates, ); update_post_meta( $post_id, '_evwr_recurrence', Recurrence::sanitize_json( $rule ) ); update_post_meta( $post_id, '_evwr_rsvp_enabled', (bool) $g( 'rsvp_enabled' ) ); update_post_meta( $post_id, '_evwr_rsvp_waitlist', (bool) $g( 'rsvp_waitlist' ) ); update_post_meta( $post_id, '_evwr_rsvp_capacity', absint( $g( 'rsvp_capacity', 0 ) ) ); update_post_meta( $post_id, '_evwr_rsvp_max_per', absint( $g( 'rsvp_max_per', 10 ) ) ); update_post_meta( $post_id, '_evwr_rsvp_closes', $g( 'rsvp_closes' ) ); Occurrences::sync( $post_id ); } /** * Find a venue/organizer by exact title or create it. * * @param string $type Post type. * @param string $title Title. * @return int */ public static function find_or_create( $type, $title ) { $found = get_posts( array( 'post_type' => $type, 'post_status' => array( 'publish', 'draft', 'private' ), 'title' => $title, 'posts_per_page' => 1, 'fields' => 'ids', ) ); if ( $found ) { return (int) $found[0]; } $id = wp_insert_post( wp_slash( array( 'post_type' => $type, 'post_status' => 'publish', 'post_title' => $title, ) ) ); return is_wp_error( $id ) ? 0 : (int) $id; } /** * RSVP summary box. * * @param \WP_Post $post Post. */ public static function attendees_box( $post ) { if ( ! RSVP::enabled( $post->ID ) ) { echo '

' . esc_html__( 'RSVP is off for this event. Turn it on in the event settings.', 'eventwright' ) . '

'; return; } $occ = Occurrences::pick( $post->ID ); $going = RSVP::going_count( $post->ID, RSVP::occurrence_key( $post->ID, $occ ) ); $cap = (int) get_post_meta( $post->ID, '_evwr_rsvp_capacity', true ); echo '

' . esc_html( $cap /* translators: 1: people going, 2: capacity */ ? sprintf( __( '%1$d of %2$d places taken', 'eventwright' ), $going, $cap ) /* translators: %d: people going */ : sprintf( _n( '%d person going', '%d people going', $going, 'eventwright' ), $going ) ) . ''; if ( $occ && Recurrence::is_recurring( $post->ID ) ) { echo '
' . esc_html( /* translators: %s: date */ sprintf( __( 'For %s', 'eventwright' ), eventwright_format_local( eventwright_date_format(), $occ['start_local'] ) ) ) . ''; } echo '

' . esc_html__( 'See attendees', 'eventwright' ) . ' '; echo '' . esc_html__( 'Export CSV', 'eventwright' ) . '

'; } /** * Venue box. * * @param \WP_Post $post Post. */ public static function venue_box( $post ) { wp_nonce_field( 'evwr_save_venue', '_evwr_venue_nonce' ); $fields = array( 'address' => __( 'Street address', 'eventwright' ), 'city' => __( 'City', 'eventwright' ), 'state' => __( 'State / province', 'eventwright' ), 'zip' => __( 'Postal code', 'eventwright' ), 'country' => __( 'Country', 'eventwright' ), 'phone' => __( 'Phone', 'eventwright' ), 'website' => __( 'Website', 'eventwright' ), 'lat' => __( 'Latitude (optional, for exact map pins)', 'eventwright' ), 'lng' => __( 'Longitude (optional)', 'eventwright' ), ); echo '
'; foreach ( $fields as $key => $label ) { $val = get_post_meta( $post->ID, '_evwr_' . $key, true ); if ( in_array( $key, array( 'lat', 'lng' ), true ) && ! (float) $val ) { $val = ''; } self::input_row( $key, $label, (string) $val, 'website' === $key ? 'url' : 'text' ); } echo '
'; echo '

'; echo '

' . esc_html__( 'When you click the button, the address is sent to OpenStreetMap\'s Nominatim service to look up its coordinates. Nothing is sent otherwise.', 'eventwright' ) . '

'; } /** * Save the venue box. * * @param int $post_id Post. * @param \WP_Post $post Post. */ public static function save_venue( $post_id, $post ) { if ( ! isset( $_POST['_evwr_venue_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_evwr_venue_nonce'] ) ), 'evwr_save_venue' ) || ! current_user_can( 'edit_post', $post_id ) ) { return; } $in = isset( $_POST['evw'] ) && is_array( $_POST['evw'] ) ? wp_unslash( $_POST['evw'] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitised per key. foreach ( array( 'address', 'city', 'state', 'zip', 'country', 'phone', 'website', 'lat', 'lng' ) as $key ) { $val = isset( $in[ $key ] ) ? ( 'website' === $key ? esc_url_raw( $in[ $key ] ) : sanitize_text_field( $in[ $key ] ) ) : ''; update_post_meta( $post_id, '_evwr_' . $key, $val ); } } /** * Organizer box. * * @param \WP_Post $post Post. */ public static function organizer_box( $post ) { wp_nonce_field( 'evwr_save_organizer', '_evwr_organizer_nonce' ); echo '
'; self::input_row( 'phone', __( 'Phone', 'eventwright' ), (string) get_post_meta( $post->ID, '_evwr_phone', true ) ); self::input_row( 'email', __( 'Email (also used as reply-to for RSVP emails)', 'eventwright' ), (string) get_post_meta( $post->ID, '_evwr_email', true ), 'email' ); self::input_row( 'website', __( 'Website', 'eventwright' ), (string) get_post_meta( $post->ID, '_evwr_website', true ), 'url' ); echo '
'; } /** * Save the organizer box. * * @param int $post_id Post. * @param \WP_Post $post Post. */ public static function save_organizer( $post_id, $post ) { if ( ! isset( $_POST['_evwr_organizer_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_evwr_organizer_nonce'] ) ), 'evwr_save_organizer' ) || ! current_user_can( 'edit_post', $post_id ) ) { return; } $in = isset( $_POST['evw'] ) && is_array( $_POST['evw'] ) ? wp_unslash( $_POST['evw'] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitised per key. update_post_meta( $post_id, '_evwr_phone', isset( $in['phone'] ) ? sanitize_text_field( $in['phone'] ) : '' ); update_post_meta( $post_id, '_evwr_email', isset( $in['email'] ) ? sanitize_email( $in['email'] ) : '' ); update_post_meta( $post_id, '_evwr_website', isset( $in['website'] ) ? esc_url_raw( $in['website'] ) : '' ); } }