@@ -11,7 +11,7 @@ abstract class MC4WP_Dynamic_Content_Tags
11
11
/**
12
12
* @var string The escape function for replacement values.
13
13
*/
14
- protected $ escape_function = null ;
14
+ protected $ escape_function = ' esc_html ' ;
15
15
16
16
/**
17
17
* @var array Array of registered dynamic content tags
@@ -25,56 +25,56 @@ protected function register()
25
25
{
26
26
// Global tags can go here
27
27
$ this ->tags ['cookie ' ] = [
28
- 'description ' => __ ('Data from a cookie. ' , 'mailchimp-for-wp ' ),
29
- 'callback ' => [ $ this , 'get_cookie ' ],
30
- 'example ' => "cookie name='my_cookie' default='Default Value' " ,
28
+ 'description ' => __ ('Data from a cookie. ' , 'mailchimp-for-wp ' ),
29
+ 'callback ' => [ $ this , 'get_cookie ' ],
30
+ 'example ' => "cookie name='my_cookie' default='Default Value' " ,
31
31
];
32
32
33
33
$ this ->tags ['email ' ] = [
34
- 'description ' => __ ('The email address of the current visitor (if known). ' , 'mailchimp-for-wp ' ),
35
- 'callback ' => [ $ this , 'get_email ' ],
34
+ 'description ' => __ ('The email address of the current visitor (if known). ' , 'mailchimp-for-wp ' ),
35
+ 'callback ' => [ $ this , 'get_email ' ],
36
36
];
37
37
38
38
$ this ->tags ['current_url ' ] = [
39
- 'description ' => __ ('The URL of the page. ' , 'mailchimp-for-wp ' ),
40
- 'callback ' => 'mc4wp_get_request_url ' ,
39
+ 'description ' => __ ('The URL of the page. ' , 'mailchimp-for-wp ' ),
40
+ 'callback ' => 'mc4wp_get_request_url ' ,
41
41
];
42
42
43
43
$ this ->tags ['current_path ' ] = [
44
- 'description ' => __ ('The path of the page. ' , 'mailchimp-for-wp ' ),
45
- 'callback ' => 'mc4wp_get_request_path ' ,
44
+ 'description ' => __ ('The path of the page. ' , 'mailchimp-for-wp ' ),
45
+ 'callback ' => 'mc4wp_get_request_path ' ,
46
46
];
47
47
48
48
$ this ->tags ['date ' ] = [
49
- 'description ' => sprintf (__ ('The current date. Example: %s. ' , 'mailchimp-for-wp ' ), '<strong> ' . gmdate ('Y/m/d ' , time () + ( get_option ('gmt_offset ' ) * HOUR_IN_SECONDS )) . '</strong> ' ),
50
- 'replacement ' => gmdate ('Y/m/d ' , time () + ( get_option ('gmt_offset ' ) * HOUR_IN_SECONDS )),
49
+ 'description ' => sprintf (__ ('The current date. Example: %s. ' , 'mailchimp-for-wp ' ), '<strong> ' . gmdate ('Y/m/d ' , time () + ( get_option ('gmt_offset ' ) * HOUR_IN_SECONDS )) . '</strong> ' ),
50
+ 'replacement ' => gmdate ('Y/m/d ' , time () + ( get_option ('gmt_offset ' ) * HOUR_IN_SECONDS )),
51
51
];
52
52
53
53
$ this ->tags ['time ' ] = [
54
- 'description ' => sprintf (__ ('The current time. Example: %s. ' , 'mailchimp-for-wp ' ), '<strong> ' . gmdate ('H:i:s ' , time () + ( get_option ('gmt_offset ' ) * HOUR_IN_SECONDS )) . '</strong> ' ),
55
- 'replacement ' => gmdate ('H:i:s ' , time () + ( get_option ('gmt_offset ' ) * HOUR_IN_SECONDS )),
54
+ 'description ' => sprintf (__ ('The current time. Example: %s. ' , 'mailchimp-for-wp ' ), '<strong> ' . gmdate ('H:i:s ' , time () + ( get_option ('gmt_offset ' ) * HOUR_IN_SECONDS )) . '</strong> ' ),
55
+ 'replacement ' => gmdate ('H:i:s ' , time () + ( get_option ('gmt_offset ' ) * HOUR_IN_SECONDS )),
56
56
];
57
57
58
58
$ this ->tags ['language ' ] = [
59
- 'description ' => sprintf (__ ('The site \'s language. Example: %s. ' , 'mailchimp-for-wp ' ), '<strong> ' . get_locale () . '</strong> ' ),
60
- 'callback ' => 'get_locale ' ,
59
+ 'description ' => sprintf (__ ('The site \'s language. Example: %s. ' , 'mailchimp-for-wp ' ), '<strong> ' . get_locale () . '</strong> ' ),
60
+ 'callback ' => 'get_locale ' ,
61
61
];
62
62
63
63
$ this ->tags ['ip ' ] = [
64
- 'description ' => sprintf (__ ('The visitor \'s IP address. Example: %s. ' , 'mailchimp-for-wp ' ), '<strong> ' . mc4wp_get_request_ip_address () . '</strong> ' ),
65
- 'callback ' => 'mc4wp_get_request_ip_address ' ,
64
+ 'description ' => sprintf (__ ('The visitor \'s IP address. Example: %s. ' , 'mailchimp-for-wp ' ), '<strong> ' . mc4wp_get_request_ip_address () . '</strong> ' ),
65
+ 'callback ' => 'mc4wp_get_request_ip_address ' ,
66
66
];
67
67
68
68
$ this ->tags ['user ' ] = [
69
- 'description ' => __ ('The property of the currently logged-in user. ' , 'mailchimp-for-wp ' ),
70
- 'callback ' => [ $ this , 'get_user_property ' ],
71
- 'example ' => "user property='user_email' " ,
69
+ 'description ' => __ ('The property of the currently logged-in user. ' , 'mailchimp-for-wp ' ),
70
+ 'callback ' => [ $ this , 'get_user_property ' ],
71
+ 'example ' => "user property='user_email' " ,
72
72
];
73
73
74
74
$ this ->tags ['post ' ] = [
75
- 'description ' => __ ('Property of the current page or post. ' , 'mailchimp-for-wp ' ),
76
- 'callback ' => [ $ this , 'get_post_property ' ],
77
- 'example ' => "post property='ID' " ,
75
+ 'description ' => __ ('Property of the current page or post. ' , 'mailchimp-for-wp ' ),
76
+ 'callback ' => [ $ this , 'get_post_property ' ],
77
+ 'example ' => "post property='ID' " ,
78
78
];
79
79
}
80
80
@@ -118,9 +118,8 @@ protected function replace_tag(array $matches)
118
118
$ replacement = call_user_func ($ config ['callback ' ], $ attributes );
119
119
}
120
120
121
- if (is_callable ($ this ->escape_function )) {
122
- $ replacement = call_user_func ($ this ->escape_function , $ replacement );
123
- }
121
+ // escape replacement value
122
+ $ replacement = call_user_func ($ this ->escape_function , $ replacement );
124
123
125
124
return $ replacement ;
126
125
}
@@ -131,15 +130,21 @@ protected function replace_tag(array $matches)
131
130
132
131
/**
133
132
* @param string $string The string containing dynamic content tags.
134
- * @param string $escape_function Escape mode for the replacement value. Leave empty for no escaping.
133
+ * @param string $escape_function Escape mode for the replacement value.
135
134
* @return string
136
135
*/
137
- protected function replace ($ string , $ escape_function = '' )
136
+ private function replace ($ string , $ escape_function = 'esc_html ' )
138
137
{
138
+ // first, replace inside attributes
139
+ $ this ->escape_function = 'esc_attr ' ;
140
+ $ string = preg_replace_callback ('/\=[ \'"]?[^ \'"]*\{(\w+)(\ +(?:(?!\{)[^}\n])+)*\
141
+ }/ ' , [ $ this , 'replace_tag ' ], $ string );
142
+
139
143
$ this ->escape_function = $ escape_function ;
140
144
141
145
// replace strings like this: {tagname attr="value"}
142
- $ string = preg_replace_callback ('/\{(\w+)(\ +(?:(?!\{)[^}\n])+)*\}/ ' , [ $ this , 'replace_tag ' ], $ string );
146
+ $ string = preg_replace_callback ('/\{(\w+)(\ +(?:(?!\{)[^}\n])+)*\
147
+ }/ ' , [ $ this , 'replace_tag ' ], $ string );
143
148
144
149
// call again to take care of nested variables
145
150
$ string = preg_replace_callback ('/\{(\w+)(\ +(?:(?!\{)[^}\n])+)*\}/ ' , [ $ this , 'replace_tag ' ], $ string );
@@ -193,7 +198,7 @@ protected function get_cookie($args = [])
193
198
$ default = isset ($ args ['default ' ]) ? $ args ['default ' ] : '' ;
194
199
195
200
if (isset ($ _COOKIE [ $ name ])) {
196
- return esc_html ( stripslashes ( $ _COOKIE [ $ name ])) ;
201
+ return $ _COOKIE [ $ name ];
197
202
}
198
203
199
204
return $ default ;
@@ -213,7 +218,7 @@ protected function get_user_property($args = [])
213
218
$ user = wp_get_current_user ();
214
219
215
220
if ($ user instanceof WP_User && isset ($ user ->{$ property })) {
216
- return esc_html ( $ user ->{$ property }) ;
221
+ return $ user ->{$ property };
217
222
}
218
223
219
224
return $ default ;
@@ -245,7 +250,7 @@ protected function get_post_property($args = [])
245
250
protected function get_email ()
246
251
{
247
252
if (! empty ($ _REQUEST ['EMAIL ' ])) {
248
- return strip_tags ($ _REQUEST ['EMAIL ' ]);
253
+ return sanitize_email ($ _REQUEST ['EMAIL ' ]);
249
254
}
250
255
251
256
// then , try logged-in user
0 commit comments