@@ -181,7 +181,11 @@ public function start_el( &$output, $comment, $depth = 0, $args = array(), $id =
181181 return ;
182182 }
183183
184- if ( ( 'pingback ' == $ comment ->comment_type || 'trackback ' == $ comment ->comment_type ) && $ args ['short_ping ' ] ) {
184+ if ( 'comment ' === $ comment ->comment_type ) {
185+ add_filter ( 'comment_text ' , array ( $ this , 'filter_comment_text ' ), 40 , 2 );
186+ }
187+
188+ if ( ( 'pingback ' === $ comment ->comment_type || 'trackback ' === $ comment ->comment_type ) && $ args ['short_ping ' ] ) {
185189 ob_start ();
186190 $ this ->ping ( $ comment , $ depth , $ args );
187191 $ output .= ob_get_clean ();
@@ -194,6 +198,10 @@ public function start_el( &$output, $comment, $depth = 0, $args = array(), $id =
194198 $ this ->comment ( $ comment , $ depth , $ args );
195199 $ output .= ob_get_clean ();
196200 }
201+
202+ if ( 'comment ' === $ comment ->comment_type ) {
203+ remove_filter ( 'comment_text ' , array ( $ this , 'filter_comment_text ' ), 40 , 2 );
204+ }
197205 }
198206
199207 /**
@@ -244,6 +252,29 @@ protected function ping( $comment, $depth, $args ) {
244252 <?php
245253 }
246254
255+ /**
256+ * Filters the comment text.
257+ *
258+ * Removes links from the pending comment's text if the commenter did not consent
259+ * to the comment cookies.
260+ *
261+ * @since 5.4.2
262+ *
263+ * @param string $comment_text Text of the current comment.
264+ * @param WP_Comment|null $comment The comment object. Null if not found.
265+ * @return string Filtered text of the current comment.
266+ */
267+ public function filter_comment_text ( $ comment_text , $ comment ) {
268+ $ commenter = wp_get_current_commenter ();
269+ $ show_pending_links = ! empty ( $ commenter ['comment_author ' ] );
270+
271+ if ( $ comment && '0 ' == $ comment ->comment_approved && ! $ show_pending_links ) {
272+ $ comment_text = wp_kses ( $ comment_text , array () );
273+ }
274+
275+ return $ comment_text ;
276+ }
277+
247278 /**
248279 * Outputs a single comment.
249280 *
@@ -264,13 +295,14 @@ protected function comment( $comment, $depth, $args ) {
264295 $ add_below = 'div-comment ' ;
265296 }
266297
267- $ commenter = wp_get_current_commenter ();
298+ $ commenter = wp_get_current_commenter ();
299+ $ show_pending_links = isset ( $ commenter ['comment_author ' ] ) && $ commenter ['comment_author ' ];
300+
268301 if ( $ commenter ['comment_author_email ' ] ) {
269302 $ moderation_note = __ ( 'Your comment is awaiting moderation. ' );
270303 } else {
271304 $ moderation_note = __ ( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved. ' );
272305 }
273-
274306 ?>
275307 <<?php echo $ tag ; ?> <?php comment_class ( $ this ->has_children ? 'parent ' : '' , $ comment ); ?> id="comment-<?php comment_ID (); ?> ">
276308 <?php if ( 'div ' != $ args ['style ' ] ) : ?>
@@ -279,14 +311,21 @@ protected function comment( $comment, $depth, $args ) {
279311 <div class="comment-author vcard">
280312 <?php
281313 if ( 0 != $ args ['avatar_size ' ] ) {
282- echo get_avatar ( $ comment , $ args ['avatar_size ' ] );}
314+ echo get_avatar ( $ comment , $ args ['avatar_size ' ] );
315+ }
283316 ?>
284317 <?php
285- printf (
286- /* translators: %s: Comment author link. */
287- __ ( '%s <span class="says">says:</span> ' ),
288- sprintf ( '<cite class="fn">%s</cite> ' , get_comment_author_link ( $ comment ) )
289- );
318+ $ comment_author = get_comment_author_link ( $ comment );
319+
320+ if ( '0 ' == $ comment ->comment_approved && ! $ show_pending_links ) {
321+ $ comment_author = get_comment_author ( $ comment );
322+ }
323+
324+ printf (
325+ /* translators: %s: Comment author link. */
326+ __ ( '%s <span class="says">says:</span> ' ),
327+ sprintf ( '<cite class="fn">%s</cite> ' , $ comment_author )
328+ );
290329 ?>
291330 </div>
292331 <?php if ( '0 ' == $ comment ->comment_approved ) : ?>
@@ -354,13 +393,14 @@ protected function comment( $comment, $depth, $args ) {
354393 protected function html5_comment ( $ comment , $ depth , $ args ) {
355394 $ tag = ( 'div ' === $ args ['style ' ] ) ? 'div ' : 'li ' ;
356395
357- $ commenter = wp_get_current_commenter ();
396+ $ commenter = wp_get_current_commenter ();
397+ $ show_pending_links = ! empty ( $ commenter ['comment_author ' ] );
398+
358399 if ( $ commenter ['comment_author_email ' ] ) {
359400 $ moderation_note = __ ( 'Your comment is awaiting moderation. ' );
360401 } else {
361402 $ moderation_note = __ ( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved. ' );
362403 }
363-
364404 ?>
365405 <<?php echo $ tag ; ?> id="comment-<?php comment_ID (); ?> " <?php comment_class ( $ this ->has_children ? 'parent ' : '' , $ comment ); ?> >
366406 <article id="div-comment-<?php comment_ID (); ?> " class="comment-body">
@@ -372,11 +412,17 @@ protected function html5_comment( $comment, $depth, $args ) {
372412 }
373413 ?>
374414 <?php
375- printf (
376- /* translators: %s: Comment author link. */
377- __ ( '%s <span class="says">says:</span> ' ),
378- sprintf ( '<b class="fn">%s</b> ' , get_comment_author_link ( $ comment ) )
379- );
415+ $ comment_author = get_comment_author_link ( $ comment );
416+
417+ if ( '0 ' == $ comment ->comment_approved && ! $ show_pending_links ) {
418+ $ comment_author = get_comment_author ( $ comment );
419+ }
420+
421+ printf (
422+ /* translators: %s: Comment author link. */
423+ __ ( '%s <span class="says">says:</span> ' ),
424+ sprintf ( '<b class="fn">%s</b> ' , $ comment_author )
425+ );
380426 ?>
381427 </div><!-- .comment-author -->
382428
@@ -402,18 +448,20 @@ protected function html5_comment( $comment, $depth, $args ) {
402448 </div><!-- .comment-content -->
403449
404450 <?php
405- comment_reply_link (
406- array_merge (
407- $ args ,
408- array (
409- 'add_below ' => 'div-comment ' ,
410- 'depth ' => $ depth ,
411- 'max_depth ' => $ args ['max_depth ' ],
412- 'before ' => '<div class="reply"> ' ,
413- 'after ' => '</div> ' ,
451+ if ( '1 ' == $ comment ->comment_approved || $ show_pending_links ) {
452+ comment_reply_link (
453+ array_merge (
454+ $ args ,
455+ array (
456+ 'add_below ' => 'div-comment ' ,
457+ 'depth ' => $ depth ,
458+ 'max_depth ' => $ args ['max_depth ' ],
459+ 'before ' => '<div class="reply"> ' ,
460+ 'after ' => '</div> ' ,
461+ )
414462 )
415- )
416- );
463+ );
464+ }
417465 ?>
418466 </article><!-- .comment-body -->
419467 <?php
0 commit comments