@@ -77,8 +77,22 @@ public static function update_comment( $activity ) {
77
77
}
78
78
79
79
// Found a local comment id.
80
- $ commentdata ['comment_author ' ] = self ::replace_custom_emoji ( $ meta ['name ' ] ? $ meta ['name ' ] : $ meta ['preferredUsername ' ], $ meta );
81
- $ commentdata ['comment_content ' ] = \addslashes ( self ::replace_custom_emoji ( $ activity ['object ' ]['content ' ], $ activity ['object ' ] ) );
80
+ $ commentdata ['comment_author ' ] = \esc_attr ( $ meta ['name ' ] ? $ meta ['name ' ] : $ meta ['preferredUsername ' ] );
81
+ $ commentdata ['comment_content ' ] = \addslashes ( $ activity ['object ' ]['content ' ] );
82
+
83
+ add_filter (
84
+ 'pre_comment_author_name ' ,
85
+ function ( $ comment_author ) use ( $ meta ) {
86
+ return self ::replace_custom_emoji ( $ comment_author , $ meta );
87
+ }
88
+ );
89
+ add_filter (
90
+ 'pre_comment_content ' ,
91
+ function ( $ comment_content ) use ( $ activity ) {
92
+ return self ::replace_custom_emoji ( $ comment_content , $ activity ['object ' ] );
93
+ },
94
+ 20
95
+ );
82
96
83
97
return self ::persist ( $ commentdata , self ::UPDATE );
84
98
}
@@ -209,22 +223,14 @@ public static function allowed_comment_html( $allowed_tags, $context = '' ) {
209
223
}
210
224
211
225
// Add `p` and `br` to the list of allowed tags.
212
- if ( ! isset ( $ allowed_tags [ 'br ' ] ) ) {
226
+ if ( ! array_key_exists ( 'br ' , $ allowed_tags ) ) {
213
227
$ allowed_tags ['br ' ] = array ();
214
228
}
215
229
216
- if ( ! isset ( $ allowed_tags [ 'p ' ] ) ) {
230
+ if ( ! array_key_exists ( 'p ' , $ allowed_tags ) ) {
217
231
$ allowed_tags ['p ' ] = array ();
218
232
}
219
233
220
- if ( ! isset ( $ allowed_tags ['img ' ] ) ) {
221
- $ allowed_tags ['img ' ] = array (
222
- 'src ' => array (),
223
- 'alt ' => array (),
224
- 'class ' => array (),
225
- );
226
- }
227
-
228
234
return $ allowed_tags ;
229
235
}
230
236
@@ -265,9 +271,9 @@ public static function activity_to_comment( $activity ) {
265
271
}
266
272
267
273
$ commentdata = array (
268
- 'comment_author ' => self :: replace_custom_emoji ( $ comment_author, $ actor ),
274
+ 'comment_author ' => \esc_attr ( $ comment_author ),
269
275
'comment_author_url ' => \esc_url_raw ( $ url ),
270
- 'comment_content ' => self :: replace_custom_emoji ( $ comment_content, $ activity [ ' object ' ] ) ,
276
+ 'comment_content ' => $ comment_content ,
271
277
'comment_type ' => 'comment ' ,
272
278
'comment_author_email ' => '' ,
273
279
'comment_meta ' => array (
@@ -284,6 +290,20 @@ public static function activity_to_comment( $activity ) {
284
290
$ commentdata ['comment_meta ' ]['source_url ' ] = \esc_url_raw ( object_to_uri ( $ activity ['object ' ]['url ' ] ) );
285
291
}
286
292
293
+ add_filter (
294
+ 'pre_comment_author_name ' ,
295
+ function ( $ comment_author ) use ( $ actor ) {
296
+ return self ::replace_custom_emoji ( $ comment_author , $ actor );
297
+ }
298
+ );
299
+ add_filter (
300
+ 'pre_comment_content ' ,
301
+ function ( $ comment_content ) use ( $ activity ) {
302
+ return self ::replace_custom_emoji ( $ comment_content , $ activity ['object ' ] );
303
+ },
304
+ 20
305
+ );
306
+
287
307
return $ commentdata ;
288
308
}
289
309
0 commit comments