class-twentynineteen-walker-comment.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * Custom comment walker for this theme
  4. *
  5. * @package WordPress
  6. * @subpackage Twenty_Nineteen
  7. * @since 1.0.0
  8. */
  9. /**
  10. * This class outputs custom comment walker for HTML5 friendly WordPress comment and threaded replies.
  11. *
  12. * @since 1.0.0
  13. */
  14. class TwentyNineteen_Walker_Comment extends Walker_Comment {
  15. /**
  16. * Outputs a comment in the HTML5 format.
  17. *
  18. * @see wp_list_comments()
  19. *
  20. * @param WP_Comment $comment Comment to display.
  21. * @param int $depth Depth of the current comment.
  22. * @param array $args An array of arguments.
  23. */
  24. protected function html5_comment( $comment, $depth, $args ) {
  25. $tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
  26. ?>
  27. <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?>>
  28. <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
  29. <footer class="comment-meta">
  30. <div class="comment-author vcard">
  31. <?php
  32. $comment_author_url = get_comment_author_url( $comment );
  33. $comment_author = get_comment_author( $comment );
  34. $avatar = get_avatar( $comment, $args['avatar_size'] );
  35. if ( 0 != $args['avatar_size'] ) {
  36. if ( empty( $comment_author_url ) ) {
  37. echo $avatar;
  38. } else {
  39. printf( '<a href="%s" rel="external nofollow" class="url">', $comment_author_url );
  40. echo $avatar;
  41. }
  42. }
  43. /*
  44. * Using the `check` icon instead of `check_circle`, since we can't add a
  45. * fill color to the inner check shape when in circle form.
  46. */
  47. if ( twentynineteen_is_comment_by_post_author( $comment ) ) {
  48. printf( '<span class="post-author-badge" aria-hidden="true">%s</span>', twentynineteen_get_icon_svg( 'check', 24 ) );
  49. }
  50. printf(
  51. wp_kses(
  52. /* translators: %s: Comment author link. */
  53. __( '%s <span class="screen-reader-text says">says:</span>', 'twentynineteen' ),
  54. array(
  55. 'span' => array(
  56. 'class' => array(),
  57. ),
  58. )
  59. ),
  60. '<b class="fn">' . $comment_author . '</b>'
  61. );
  62. if ( ! empty( $comment_author_url ) ) {
  63. echo '</a>';
  64. }
  65. ?>
  66. </div><!-- .comment-author -->
  67. <div class="comment-metadata">
  68. <a href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>">
  69. <?php
  70. /* translators: 1: Comment date, 2: Comment time. */
  71. $comment_timestamp = sprintf( __( '%1$s at %2$s', 'twentynineteen' ), get_comment_date( '', $comment ), get_comment_time() );
  72. ?>
  73. <time datetime="<?php comment_time( 'c' ); ?>" title="<?php echo $comment_timestamp; ?>">
  74. <?php echo $comment_timestamp; ?>
  75. </time>
  76. </a>
  77. <?php
  78. $edit_comment_icon = twentynineteen_get_icon_svg( 'edit', 16 );
  79. edit_comment_link( __( 'Edit', 'twentynineteen' ), '<span class="edit-link-sep">&mdash;</span> <span class="edit-link">' . $edit_comment_icon, '</span>' );
  80. ?>
  81. </div><!-- .comment-metadata -->
  82. <?php
  83. $commenter = wp_get_current_commenter();
  84. if ( $commenter['comment_author_email'] ) {
  85. $moderation_note = __( 'Your comment is awaiting moderation.', 'twentynineteen' );
  86. } else {
  87. $moderation_note = __( 'Your comment is awaiting moderation. This is a preview, your comment will be visible after it has been approved.', 'twentynineteen' );
  88. }
  89. ?>
  90. <?php if ( '0' == $comment->comment_approved ) : ?>
  91. <p class="comment-awaiting-moderation"><?php echo $moderation_note; ?></p>
  92. <?php endif; ?>
  93. </footer><!-- .comment-meta -->
  94. <div class="comment-content">
  95. <?php comment_text(); ?>
  96. </div><!-- .comment-content -->
  97. </article><!-- .comment-body -->
  98. <?php
  99. comment_reply_link(
  100. array_merge(
  101. $args,
  102. array(
  103. 'add_below' => 'div-comment',
  104. 'depth' => $depth,
  105. 'max_depth' => $args['max_depth'],
  106. 'before' => '<div class="comment-reply">',
  107. 'after' => '</div>',
  108. )
  109. )
  110. );
  111. ?>
  112. <?php
  113. }
  114. }