event_id); if (!$event || !class_exists('AIEO_Event_CPT') || $event->post_type !== AIEO_Event_CPT::POST_TYPE || $event->post_status === 'trash') { self::render_invalid(); } $closed = self::is_closed((int) $event->ID); $just = ''; if (!$closed && isset($_SERVER['REQUEST_METHOD']) && strtoupper((string) $_SERVER['REQUEST_METHOD']) === 'POST' && isset($_POST['aieo_rsvp_do'], $_POST['_wpnonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_wpnonce'])), self::NONCE_PREFIX . $token) ) { $do = sanitize_key(wp_unslash($_POST['aieo_rsvp_do'])); if (in_array($do, array('confirm', 'decline'), true)) { AIEO_Event_Participants::set_status_by_token($token, ($do === 'confirm') ? 'confirmed' : 'declined'); $p = AIEO_Event_Participants::get_by_token($token); $just = ($do === 'confirm') ? 'confirmed' : 'declined'; } } self::render_page($p, $event, $closed, $just); } private static function is_closed($event_id) { $deadline = (string) get_post_meta($event_id, AIEO_Event_CPT::META_RSVP_DEADLINE, true); if ($deadline === '') { return false; } return current_time('mysql') > $deadline; } private static function greeting($p) { $sal = trim((string) $p->salutation); if ($sal !== '') { return $sal; } $name = trim(trim((string) $p->title) . ' ' . trim((string) $p->first_name) . ' ' . trim((string) $p->last_name)); if ($name !== '') { return sprintf(__('Dear %s', 'ai-eshop-optimizer'), $name); } return __('Hello', 'ai-eshop-optimizer'); } private static function status_line($status) { if ($status === 'confirmed') { return __('Your current response: attending.', 'ai-eshop-optimizer'); } if ($status === 'declined') { return __('Your current response: not attending.', 'ai-eshop-optimizer'); } return __('You have not responded yet.', 'ai-eshop-optimizer'); } private static function render_invalid() { status_header(404); self::shell( __('Invitation not found', 'ai-eshop-optimizer'), '
' . esc_html__('This RSVP link is invalid or has expired. Please use the exact link from your invitation email, or contact us.', 'ai-eshop-optimizer') . '
' ); } private static function render_page($p, $event, $closed, $just) { status_header(200); $title = get_the_title($event); $start = AIEO_Event_CPT::fmt_dt(get_post_meta($event->ID, AIEO_Event_CPT::META_START, true)); $location = (string) get_post_meta($event->ID, AIEO_Event_CPT::META_LOCATION, true); $status = (string) $p->rsvp_status; $permalink = get_permalink($event); ob_start(); echo '' . esc_html(self::greeting($p)) . '
'; echo '' . esc_html__('The RSVP period for this event has closed.', 'ai-eshop-optimizer') . '
'; echo '' . esc_html(self::status_line($status)) . '
'; } else { echo '' . esc_html__('Will you attend?', 'ai-eshop-optimizer') . '
'; $nonce = wp_create_nonce(self::NONCE_PREFIX . strtolower((string) $p->rsvp_token)); echo ''; if ($status !== 'invited') { echo '' . esc_html(self::status_line($status)) . ' ' . esc_html__('You can change your response above.', 'ai-eshop-optimizer') . '
'; } } if ($permalink) { echo '' . esc_html__('View event details', 'ai-eshop-optimizer') . ' →
'; } self::shell($title !== '' ? $title : __('Event RSVP', 'ai-eshop-optimizer'), ob_get_clean()); } private static function shell($title, $body_html) { $site = get_bloginfo('name'); header('Content-Type: text/html; charset=utf-8'); ?> >