Automattic\WooCommerce\Internal\Email
EmailLogger::redact_emails
Replace any email addresses in a log message fragment with [redacted_email].
PHPMailer / SMTP error strings frequently embed the recipient address (e.g. "SMTP Error: Could not send to [email protected]"). Without redaction, the address would be written into the log message and — when the database log handler is active — surface in WC > Status > Logs to anyone with manage_woocommerce, defeating the username/guest resolution applied to the recipient context field.
Mirrors the regex used by RemoteLogger::redact_user_data() so the privacy posture stays consistent across loggers.
Method of the class: EmailLogger{}
No Hooks.
Returns
String. The fragment with any email addresses replaced.
Usage
// private - for code of main (parent) class only $result = $this->redact_emails( $message ): string;
- $message(string) (required)
- The message fragment to scrub.
EmailLogger::redact_emails() EmailLogger::redact emails code WC 10.9.1
private function redact_emails( string $message ): string {
return (string) preg_replace( '/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/', '[redacted_email]', $message );
}