1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Defaults; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Helpers\Arr; |
6
|
|
|
|
7
|
|
|
class EmailDefaults extends DefaultsAbstract |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* The keys that should be mapped to other keys. |
11
|
|
|
* Keys are mapped before the values are normalized and sanitized. |
12
|
|
|
* Note: Mapped keys should not be included in the defaults! |
13
|
|
|
*/ |
14
|
|
|
public array $mapped = [ |
15
|
|
|
'to' => 'recipients', |
16
|
1 |
|
]; |
17
|
|
|
|
18
|
1 |
|
/** |
19
|
1 |
|
* The values that should be sanitized. |
20
|
1 |
|
* This is done after $casts and before $enums. |
21
|
1 |
|
*/ |
22
|
1 |
|
public array $sanitize = [ |
23
|
1 |
|
'after' => 'text-post', |
24
|
1 |
|
'attachments' => 'array-consolidate', |
25
|
1 |
|
'before' => 'text-post', |
26
|
1 |
|
'message' => 'text-post', |
27
|
1 |
|
'recipients' => 'array-string', |
28
|
1 |
|
'subject' => 'text', |
29
|
1 |
|
'template-tags' => 'array-consolidate', |
30
|
1 |
|
]; |
31
|
1 |
|
|
32
|
|
|
protected function defaults(): array |
33
|
|
|
{ |
34
|
|
|
return [ |
35
|
|
|
'after' => '', |
36
|
|
|
'attachments' => [], |
37
|
1 |
|
'bcc' => '', |
38
|
|
|
'before' => '', |
39
|
1 |
|
'cc' => '', |
40
|
1 |
|
'from' => '', |
41
|
1 |
|
'message' => '', |
42
|
1 |
|
'recipients' => [], |
43
|
|
|
'reply-to' => '', |
44
|
1 |
|
'subject' => '', |
45
|
1 |
|
'template' => 'default', |
46
|
|
|
'template-tags' => [], |
47
|
1 |
|
]; |
48
|
1 |
|
} |
49
|
|
|
|
50
|
1 |
|
/** |
51
|
|
|
* Finalize provided values, this always runs last. |
52
|
|
|
*/ |
53
|
|
|
protected function finalize(array $values = []): array |
54
|
|
|
{ |
55
|
|
|
$values['recipients'] = Arr::removeEmptyValues($values['recipients']); |
56
|
|
|
return $values; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Normalize provided values, this always runs first. |
61
|
|
|
*/ |
62
|
|
|
protected function normalize(array $values = []): array |
63
|
|
|
{ |
64
|
|
|
if (empty($values['from'])) { |
65
|
|
|
$email = sanitize_email(glsr_get_option('general.notification_from', null, 'string')); |
66
|
|
|
if (empty($email)) { |
67
|
|
|
$email = get_bloginfo('admin_email'); |
68
|
|
|
} |
69
|
|
|
$from = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES); |
70
|
|
|
$values['from'] = sprintf('%s <%s>', $from, $email); |
71
|
|
|
} |
72
|
|
|
if (empty($values['reply-to'])) { |
73
|
|
|
$values['reply-to'] = $values['from']; |
74
|
|
|
} |
75
|
|
|
return parent::normalize($values); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|