Automattic\WooCommerce\Internal\Logging
RemoteLogger::redact_user_data
Redact potential user data from the content.
Method of the class: RemoteLogger{}
No Hooks.
Returns
String. The redacted message.
Usage
// private - for code of main (parent) class only $result = $this->redact_user_data( $content );
- $content(string) (required)
- The content to redact.
RemoteLogger::redact_user_data() RemoteLogger::redact user data code WC 10.5.0
private function redact_user_data( $content ) {
// Redact email addresses.
$content = preg_replace( '/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/', '[redacted_email]', $content );
// Redact potential IP addresses.
$content = preg_replace( '/\b(?:\d{1,3}\.){3}\d{1,3}\b/', '[redacted_ip]', $content );
// Redact potential credit card numbers.
$content = preg_replace( '/(\d{4}[- ]?){3}\d{4}/', '[redacted_credit_card]', $content );
// API key redaction patterns.
$api_patterns = array(
'/\b[A-Za-z0-9]{32,40}\b/', // Generic API key.
'/\b[0-9a-f]{32}\b/i', // 32 hex characters.
'/\b(?:[A-Z0-9]{4}-){3,7}[A-Z0-9]{4}\b/i', // Segmented API key (e.g., XXXX-XXXX-XXXX-XXXX).
'/\bsk_[A-Za-z0-9]{24,}\b/i', // Stripe keys (starts with sk_).
);
foreach ( $api_patterns as $pattern ) {
$content = preg_replace( $pattern, '[redacted_api_key]', $content );
}
/**
* Redact potential phone numbers.
*
* This will match patterns like:
* +1 (123) 456 7890 (with parentheses around area code)
* +44-123-4567-890 (with area code, no parentheses)
* 1234567890 (10 consecutive digits, no area code)
* (123) 456-7890 (area code in parentheses, groups)
* +91 12345 67890 (international format with space)
*/
$content = preg_replace(
'/(?:(?:\+?\d{1,3}[-\s]?)?\(?\d{3}\)?[-\s]?\d{3}[-\s]?\d{4}|\b\d{10,11}\b)/',
'[redacted_phone]',
$content
);
return $content;
}