@@ -366,7 +366,7 @@ public static function handle_create( $object, $user_id ) {
366366 'comment_post_ID ' => $ comment_post_id ,
367367 'comment_author ' => \esc_attr ( $ meta ['name ' ] ),
368368 'comment_author_url ' => \esc_url_raw ( $ object ['actor ' ] ),
369- 'comment_content ' => \wp_filter_kses ( $ object ['object ' ]['content ' ] ),
369+ 'comment_content ' => addslashes ( \wp_kses ( $ object ['object ' ]['content ' ], ' pre_comment_content ' ) ),
370370 'comment_type ' => 'comment ' ,
371371 'comment_author_email ' => '' ,
372372 'comment_parent ' => 0 ,
@@ -391,8 +391,11 @@ function() {
391391 }
392392 );
393393
394+ \add_filter ( 'wp_kses_allowed_html ' , array ( self ::class, 'allowed_comment_html ' ), 10 , 2 );
395+
394396 $ state = \wp_new_comment ( $ commentdata , true );
395397
398+ \remove_filter ( 'wp_kses_allowed_html ' , array ( self ::class, 'allowed_comment_html ' ) );
396399 \remove_filter ( 'pre_option_require_name_email ' , '__return_false ' );
397400
398401 // re-add flood control
@@ -483,4 +486,29 @@ public static function is_activity_public( $data ) {
483486
484487 return in_array ( 'https://www.w3.org/ns/activitystreams#Public ' , $ recipients , true );
485488 }
489+
490+ /**
491+ * Adds line breaks to the list of allowed comment tags.
492+ *
493+ * @param array $allowedtags Allowed HTML tags.
494+ * @param string $context Context.
495+ * @return array Filtered tag list.
496+ */
497+ public static function allowed_comment_html ( $ allowedtags , $ context = '' ) {
498+ if ( 'pre_comment_content ' !== $ context ) {
499+ // Do nothing.
500+ return $ allowedtags ;
501+ }
502+
503+ // Add `p` and `br` to the list of allowed tags.
504+ if ( ! array_key_exists ( 'br ' , $ allowedtags ) ) {
505+ $ allowedtags ['br ' ] = array ();
506+ }
507+
508+ if ( ! array_key_exists ( 'p ' , $ allowedtags ) ) {
509+ $ allowedtags ['p ' ] = array ();
510+ }
511+
512+ return $ allowedtags ;
513+ }
486514}
0 commit comments