From 48fecaf6e7645143fc47ab07e9b6fb19ea29f092 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Tue, 20 May 2025 06:51:46 +0000 Subject: [PATCH] Prepend a notice to the camptix ticket form linking to tickets assigned to you. --- .../plugins/camptix/addons/require-login.php | 100 ++++++++++++++++++ .../wp-content/plugins/camptix/camptix.php | 7 +- 2 files changed, 106 insertions(+), 1 deletion(-) diff --git a/public_html/wp-content/plugins/camptix/addons/require-login.php b/public_html/wp-content/plugins/camptix/addons/require-login.php index f28d4a81d..b4089cd5c 100644 --- a/public_html/wp-content/plugins/camptix/addons/require-login.php +++ b/public_html/wp-content/plugins/camptix/addons/require-login.php @@ -186,6 +186,45 @@ public function ticket_form_message() { ) ); } + // Remind the logged in user about their tickets. + if ( is_user_logged_in() && ! $this->user_is_editing_ticket() && empty( $_REQUEST['tix_action'] ) ) { + $user_tickets = $this->get_tickets_of_user( wp_get_current_user() ); + + $ticket_links = []; + foreach ( $user_tickets as $ticket ) { + $ticket_link = sprintf( + '%s (%s). %s.', // "Name (Ticket Type). Edit.". + esc_html( $camptix->format_name_string( "%first% %last%", $ticket->tix_first_name, $ticket->tix_last_name ) ), + esc_html( get_the_title( $ticket->tix_ticket_id ) ), + sprintf( + '%s', + esc_url( $camptix->get_edit_attendee_link( $ticket->ID, $ticket->tix_edit_token ) ), + __( 'Edit information', 'wordcamporg' ) + ), + ); + + if ( $this->get_unconfirmed_tickets_purchased_with( $ticket ) ) { + $ticket_link .= sprintf( + '', + sprintf( + __( 'One or more tickets are unconfirmed. View tickets.', 'wordcamporg' ), + esc_url( $camptix->get_access_tickets_link( $ticket->tix_access_token ) ) + ) + ); + } + + $ticket_links[] = $ticket_link; + } + + if ( $ticket_links ) { + $camptix->info( apply_filters( + 'camptix_require_login_your_tickets_message', + '

' . __( 'The following tickets are assigned to you:', 'wordcamporg' ) . '

' . + '' + ) ); + } + } + // Inform a user registering multiple attendees that other attendees will enter their own info if ( isset( $_REQUEST['tix_action'], $_REQUEST['tix_tickets_selected'] ) ) { if ( 'attendee_info' == $_REQUEST['tix_action'] && $this->registering_multiple_attendees( $_REQUEST['tix_tickets_selected'] ) ) { @@ -998,6 +1037,67 @@ protected function get_ticket_of_user( WP_User $user ) { return $ticket ? reset( $ticket ) : false; } + + /** + * Retrieve any tickets associated with the given user. + * + * @param WP_User $user The user object for whom to retrieve the tickets. + * @return array An array of ticket post objects. + */ + protected function get_tickets_of_user( WP_User $user ) { + if ( empty( $user->user_login ) ) { + return []; + } + + return get_posts( array( + 'posts_per_page' => -1, + 'post_type' => 'tix_attendee', + 'post_status' => 'publish', + 'meta_query' => array( + array( + 'key' => 'tix_username', + 'value' => $user->user_login, + ), + 'relation' => 'OR', + array( + 'key' => 'tix_email', + 'value' => $user->user_email, + ), + ), + ) ); + } + + /** + * Retrieve any unconfirmed tickets associated with the given ticket. + * + * @param WP_Post $ticket The ticket post object. + * @return array An array of unconfirmed ticket post objects. + */ + protected function get_unconfirmed_tickets_purchased_with( WP_Post $ticket ) { + $unconfirmed_tickets = get_posts( array( + 'posts_per_page' => -1, + 'post_type' => 'tix_attendee', + 'post_status' => 'publish', + 'post_not_in' => array( $ticket->ID ), + 'meta_query' => array( + 'relation' => 'AND', + array( + 'key' => 'tix_payment_token', + 'value' => $ticket->tix_payment_token, + ), + array( + 'key' => 'tix_username', + 'value' => self::UNCONFIRMED_USERNAME, + ), + array( + 'key' => 'tix_receipt_email', + 'value' => $ticket->tix_email, // May differ from the user email. + ), + ), + ) ); + + return $unconfirmed_tickets; + } } // CampTix_Require_Login camptix_register_addon( 'CampTix_Require_Login' ); diff --git a/public_html/wp-content/plugins/camptix/camptix.php b/public_html/wp-content/plugins/camptix/camptix.php index f3121a05c..c7c06036f 100644 --- a/public_html/wp-content/plugins/camptix/camptix.php +++ b/public_html/wp-content/plugins/camptix/camptix.php @@ -8173,7 +8173,12 @@ function do_notices() { $printed = array(); $allowed_html = array_merge( - array( 'p' => array( 'id' => true ) ), + array( + 'p' => array( 'id' => true ), + 'ul' => true, + 'ol' => true, + 'li' => true, + ), wp_kses_allowed_html( 'data' ) );