From 93427e7dfea99040c1f16a20908548eee0c7aa90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rabbi=20Islam=20Rony=20=E2=9A=A1=EF=B8=8F?= <35329385+RabbiIslamRony@users.noreply.github.com> Date: Mon, 24 Aug 2026 20:20:38 +0600 Subject: [PATCH] add: support anonymous user contacts --- includes/helper-functions.php | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/includes/helper-functions.php b/includes/helper-functions.php index 57b3da23c1..8b25ee77e5 100644 --- a/includes/helper-functions.php +++ b/includes/helper-functions.php @@ -4890,6 +4890,49 @@ function directorist_is_guest_user( $user_id = 0 ) { return ( 'guest' === $user_type ); } +/** + * Get a normalized contact for a registered or anonymous user. + * + * Extensions can use the fallback values for flows that do not require a + * WordPress account, such as guest checkout or booking. + * + * @since 8.9.4 + * + * @param int|WP_User $user User ID or user object. + * @param array $fallback Optional anonymous contact data. + * @return array{id: int, email: string, name: string} Normalized contact data. + */ +function directorist_get_user_contact( $user = 0, $fallback = [] ) { + $fallback = wp_parse_args( + $fallback, + [ + 'email' => '', + 'name' => '', + ] + ); + + if ( ! $user instanceof WP_User ) { + $user = get_userdata( absint( $user ) ); + } + + $contact = [ + 'id' => $user ? (int) $user->ID : 0, + 'email' => $user ? sanitize_email( $user->user_email ) : sanitize_email( $fallback['email'] ), + 'name' => $user ? sanitize_text_field( $user->display_name ) : sanitize_text_field( $fallback['name'] ), + ]; + + /** + * Filters normalized contact data for registered and anonymous users. + * + * @since 8.9.4 + * + * @param array $contact Normalized contact data. + * @param WP_User|false $user Resolved WordPress user, or false. + * @param array $fallback Anonymous fallback values. + */ + return apply_filters( 'directorist_user_contact', $contact, $user, $fallback ); +} + function directorist_renewal_token_hash( $listing_id, $user_id ) { $token_str = 'cB0XtpVzGb180dgPi3hADW-' . $listing_id . '::' . $user_id; return wp_hash( $token_str, 'nonce' );