1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
<?php // phpcs:ignoreFile
namespace AutomateWoo;
/** * Functions for email click tracking and unsubscribes * * @class Emails */ class Emails {
/** * Support for custom from name and from email per template by using an array * * custom_template => [ * template_name * from_name * from_email * ] * * @var array */ static $templates = [ 'default' => 'WooCommerce Default', 'plain' => 'None', ];
/** * Get the from name for outgoing emails. * * @param string|bool $template_id * @return string */ static function get_from_name( $template_id = false ) {
$from_name = false;
if ( $template_id ) { // check if template has a custom name $template = self::get_template( $template_id );
if ( is_array( $template ) && isset( $template['from_name'] ) ) { $from_name = $template['from_name']; } }
if ( ! $from_name ) { $from_name = AW()->options()->email_from_name; }
if ( ! $from_name ) { $from_name = get_option( 'woocommerce_email_from_name' ); }
$from_name = apply_filters( 'automatewoo/mailer/from_name', $from_name, $template_id ); return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES ); }
/** * Get the from address for outgoing emails. * @param string|bool $template_id * @return string */ static function get_from_address( $template_id = false ) {
$from_email = false;
if ( $template_id ) { // check if template has a custom from email $template = self::get_template( $template_id );
if ( is_array( $template ) && isset( $template['from_email'] ) ) { $from_email = $template['from_email']; } }
if ( ! $from_email ) { $from_email = AW()->options()->email_from_address; }
if ( ! $from_email ) { $from_email = get_option( 'woocommerce_email_from_address' ); }
$from_address = apply_filters( 'automatewoo/mailer/from_address', $from_email, $template_id ); return sanitize_email( $from_address ); }
/** * @param $template_id * @return bool|string|array */ static function get_template( $template_id ) {
if ( ! $template_id ) return false;
$templates = self::get_email_templates( false ); return isset( $templates[ $template_id ] ) ? $templates[ $template_id ] : false; }
/** * @param bool $names_only : whether to include extra template data or just id => name * @return array */ static function get_email_templates( $names_only = true ) {
$templates = apply_filters( 'automatewoo_email_templates', self::$templates );
if ( ! $names_only ) return $templates;
$flat_templates = [];
foreach ( $templates as $template_id => $template_data ) { $flat_templates[$template_id] = is_array( $template_data ) ? $template_data['template_name'] : $template_data; }
return $flat_templates; }
/** * Parse email recipients and special args in the string * * Arg format is like so: [email protected] --notracking --other-param * * @param string $recipient_string * @return array */ static function parse_recipients_string( $recipient_string ) { $items = [];
foreach( explode(',', $recipient_string ) as $recipient ) { $recipient = Clean::string( $recipient ); $recipient_parts = explode( ' ', $recipient );
if ( is_email( $recipient_parts[0] ) ) { $email = Clean::email( $recipient_parts[0] ); unset( $recipient_parts[0] ); } else { continue; }
$params = []; foreach ( $recipient_parts as $recipient_part ) { if ( strpos( $recipient_part, '--' ) === 0 ) { $params[ substr( $recipient_part, 2 ) ] = true; } }
$params = wp_parse_args( $params, [ 'notracking' => false ]);
$items[ $email ] = $params; }
return $items; }
/** * @param $input * @param bool $remove_invalid * @return array */ static function parse_multi_email_field( $input, $remove_invalid = true ) {
$emails = [];
$input = preg_replace( '/\s/u', '', $input ); // remove whitespace $input = explode(',', $input );
foreach ( $input as $email ) { if ( ! $remove_invalid || is_email( $email ) ) { $emails[] = Clean::email( $email ); } }
return $emails; }
}
|