|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Email Log Helper functions. |
|
4
|
|
|
* Some of these functions would be used the addons. |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Perform additional sanitation of emails. |
|
9
|
|
|
* |
|
10
|
|
|
* @since 1.9 |
|
11
|
|
|
* |
|
12
|
|
|
* @param string $email Email string to be sanitized. |
|
13
|
|
|
* @param bool $multiple (Optional) Should multiple emails be allowed. True by default. |
|
14
|
|
|
* |
|
15
|
|
|
* @return string Sanitized email. |
|
16
|
|
|
*/ |
|
17
|
|
|
function el_sanitize_email( $email, $multiple = true ) { |
|
18
|
|
|
$emails = explode( ',', $email ); |
|
19
|
|
|
if ( ! $multiple ) { |
|
20
|
|
|
$emails = array_slice( $emails, 0, 1 ); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
$cleaned_emails = array_map( 'el_sanitize_email_with_name', $emails ); |
|
24
|
|
|
|
|
25
|
|
|
return implode( ', ', $cleaned_emails ); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Sanitize email with name. |
|
30
|
|
|
* |
|
31
|
|
|
* @since 1.9 |
|
32
|
|
|
* |
|
33
|
|
|
* @param $string $email Email string to be sanitized. |
|
|
|
|
|
|
34
|
|
|
* |
|
35
|
|
|
* @return string Sanitized email. |
|
36
|
|
|
*/ |
|
37
|
|
|
function el_sanitize_email_with_name( $string ) { |
|
38
|
|
|
$string = trim( $string ); |
|
39
|
|
|
|
|
40
|
|
|
$bracket_pos = strpos( $string, '<' ); |
|
41
|
|
|
if ( $bracket_pos !== false ) { |
|
42
|
|
|
// Text before the bracketed email is the name. |
|
43
|
|
|
if ( $bracket_pos > 0 ) { |
|
44
|
|
|
$name = substr( $string, 0, $bracket_pos ); |
|
45
|
|
|
$name = str_replace( '"', '', $name ); |
|
46
|
|
|
$name = trim( $name ); |
|
47
|
|
|
|
|
48
|
|
|
$email = substr( $string, $bracket_pos + 1 ); |
|
49
|
|
|
$email = str_replace( '>', '', $email ); |
|
50
|
|
|
|
|
51
|
|
|
return sanitize_text_field( $name ) . ' <' . sanitize_email( $email ) . '>'; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return sanitize_email( $string ); |
|
56
|
|
|
} |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.