Last active
August 16, 2025 06:23
-
-
Save chikaibeneme/3c22953fd417b8865a2dc112e3a3e502 to your computer and use it in GitHub Desktop.
Hide attendee information for the Event Tickets Plus APP.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php //* Do NOT include the opening php tag | |
| add_filter( | |
| 'rest_request_after_callbacks', | |
| 'tec_tickets_maybe_hide_attendee_information_for_app', | |
| 10, | |
| 3 | |
| ); | |
| /** | |
| * Maybe hide information for the ET+ APP. | |
| * | |
| * @param WP_REST_Response|WP_HTTP_Response|WP_Error|mixed $response Result to send to the client. | |
| * Usually a WP_REST_Response or WP_Error. | |
| * @param array $handler Route handler used for the request. | |
| * @param WP_REST_Request $request Request used to generate the response. | |
| * | |
| * @return WP_REST_Response|WP_HTTP_Response|WP_Error|mixed $response Result to send to the client. | |
| * Usually a WP_REST_Response or WP_Error. | |
| */ | |
| function tec_tickets_maybe_hide_attendee_information_for_app( $response, array $handler, \WP_REST_Request $request ) { | |
| if ( empty( $request->get_header( 'App-version' ) ) ) { | |
| return $response; | |
| } | |
| if ( '/tribe/tickets/v1/attendees' === $request->get_route() ) { | |
| // Hide the attendee information from the attendee endpoint. | |
| $response = tec_tickets_hide_attendee_information_attendee_endpoint( $response, $handler, $request ); | |
| } | |
| if ( '/tribe/tickets/v1/qr' === $request->get_route() ) { | |
| // Update QR response, hiding the attendee information but preserving check-in status | |
| $response = tec_tickets_hide_attendee_information_qr_endpoint( $response, $handler, $request ); | |
| } | |
| if ( '/tribe/events/v1/events' === $request->get_route() ) { | |
| // Hide events from other organizers for the APP | |
| $response = tec_tickets_hide_events_for_app( $response, $handler, $request ); | |
| } | |
| return $response; | |
| } | |
| /** | |
| * Hide the attendee information from the attendees endpoint. | |
| * | |
| * @param WP_REST_Response|WP_HTTP_Response|WP_Error|mixed $response Result to send to the client. | |
| * Usually a WP_REST_Response or WP_Error. | |
| * @param array $handler Route handler used for the request. | |
| * @param WP_REST_Request $request Request used to generate the response. | |
| * | |
| * @return WP_REST_Response|WP_HTTP_Response|WP_Error|mixed $response Result to send to the client. | |
| * Usually a WP_REST_Response or WP_Error. | |
| */ | |
| function tec_tickets_hide_attendee_information_attendee_endpoint( $response, array $handler, \WP_REST_Request $request ) { | |
| if ( empty( $response->data['attendees'] ) ) { | |
| return $response; | |
| } | |
| foreach ( $response->data['attendees'] as &$attendee ) { | |
| $attendee['title'] = 'Hidden Name'; | |
| $attendee['email'] = 'email@domain.com'; | |
| $attendee['payment']['currency'] = ''; | |
| $attendee['payment']['date'] = ''; | |
| $attendee['payment']['price'] = 'Unavailable'; | |
| $attendee['information'] = []; | |
| $attendee['information']['Information'] = 'The attendee information is private. For more information please contact the site administrator.'; | |
| } | |
| return $response; | |
| } | |
| /** | |
| * Hide the attendee information from the QR endpoint while preserving check-in status. | |
| * | |
| * @param WP_REST_Response|WP_HTTP_Response|WP_Error|mixed $response Result to send to the client. | |
| * Usually a WP_REST_Response or WP_Error. | |
| * @param array $handler Route handler used for the request. | |
| * @param WP_REST_Request $request Request used to generate the response. | |
| * | |
| * @return WP_REST_Response|WP_HTTP_Response|WP_Error|mixed $response Result to send to the client. | |
| * Usually a WP_REST_Response or WP_Error. | |
| */ | |
| function tec_tickets_hide_attendee_information_qr_endpoint( $response, array $handler, \WP_REST_Request $request ) { | |
| if ( empty( $response->data['attendee'] ) ) { | |
| return $response; | |
| } | |
| // Only hide specific personal information fields, leave everything else intact | |
| $response->data['attendee']['title'] = 'Hidden Name'; | |
| $response->data['attendee']['email'] = 'email@domain.com'; | |
| // Clear payment information if it exists | |
| if ( isset( $response->data['attendee']['payment'] ) ) { | |
| $response->data['attendee']['payment']['currency'] = ''; | |
| $response->data['attendee']['payment']['date'] = ''; | |
| $response->data['attendee']['payment']['price'] = 'Unavailable'; | |
| } | |
| // Clear custom information if it exists | |
| if ( isset( $response->data['attendee']['information'] ) ) { | |
| $response->data['attendee']['information'] = []; | |
| $response->data['attendee']['information']['Information'] = 'The attendee information is private. For more information please contact the site administrator.'; | |
| } | |
| return $response; | |
| } | |
| /** | |
| * Hide events from other organizers for the APP. | |
| * | |
| * @param WP_REST_Response|WP_HTTP_Response|WP_Error|mixed $response Result to send to the client. | |
| * Usually a WP_REST_Response or WP_Error. | |
| * @param array $handler Route handler used for the request. | |
| * @param WP_REST_Request $request Request used to generate the response. | |
| * | |
| * @return WP_REST_Response|WP_HTTP_Response|WP_Error|mixed $response Result to send to the client. | |
| * Usually a WP_REST_Response or WP_Error. | |
| */ | |
| function tec_tickets_hide_events_for_app( $response, array $handler, \WP_REST_Request $request ) { | |
| // Get the current user ID | |
| $current_user_id = get_current_user_id(); | |
| if ( empty( $current_user_id ) ) { | |
| // If no user is logged in, hide all events | |
| $response->data['events'] = []; | |
| return $response; | |
| } | |
| if ( empty( $response->data['events'] ) ) { | |
| return $response; | |
| } | |
| // Filter events to only show those created by the current user | |
| $filtered_events = []; | |
| foreach ( $response->data['events'] as $event ) { | |
| // Check if the current user is the author of the event | |
| if ( isset( $event['author'] ) && $event['author'] == $current_user_id ) { | |
| $filtered_events[] = $event; | |
| } | |
| } | |
| $response->data['events'] = $filtered_events; | |
| return $response; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment