Automattic\WooCommerce\Internal\Email

EmailLogger::resolve_recipientprivateWC 1.0

Resolve a recipient email string to an identifier safe for logging.

Each address is mapped to the corresponding WordPress username when an account exists, or to the string 'guest' for addresses with no associated account. This avoids storing plain email addresses in logs while still giving support teams a useful identifier for troubleshooting.

Method of the class: EmailLogger{}

No Hooks.

Returns

String. Comma-separated usernames or 'guest' labels.

Usage

// private - for code of main (parent) class only
$result = $this->resolve_recipient( $recipient ): string;
$recipient(string) (required)
Comma-separated recipient email string from WC_Email::get_recipient().

EmailLogger::resolve_recipient() code WC 10.9.1

private function resolve_recipient( string $recipient ): string {
	if ( '' === $recipient ) {
		return 'guest';
	}

	$labels = array_map(
		function ( string $email ): string {
			$user = get_user_by( 'email', trim( $email ) );
			return $user instanceof WP_User ? $user->user_login : 'guest';
		},
		explode( ',', $recipient )
	);

	return implode( ', ', $labels );
}