WC_Gateway_Paypal_Helper::mask_email
Mask email address before @ keeping the full domain.
Method of the class: WC_Gateway_Paypal_Helper{}
No Hooks.
Returns
String. The masked email address or original input if invalid.
Usage
$result = WC_Gateway_Paypal_Helper::mask_email( $email );
- $email(string) (required)
- The email address to mask.
WC_Gateway_Paypal_Helper::mask_email() WC Gateway Paypal Helper::mask email code WC 10.4.3
public static function mask_email( $email ) {
if ( ! is_string( $email ) || empty( $email ) ) {
return $email;
}
$parts = explode( '@', $email, 2 );
if ( count( $parts ) !== 2 || empty( $parts[0] ) || empty( $parts[1] ) ) {
return $email;
}
list( $local, $domain ) = $parts;
if ( strlen( $local ) <= 3 ) {
$masked_local = str_repeat( '*', strlen( $local ) );
} else {
$masked_local = substr( $local, 0, 2 )
. str_repeat( '*', max( 1, strlen( $local ) - 3 ) )
. substr( $local, -1 );
}
return $masked_local . '@' . $domain;
}