class-varia-walker-comment.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * Custom comment walker for this theme
  4. *
  5. * @package WordPress
  6. * @subpackage Varia
  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_link = get_comment_author_link( $comment );
  33. $comment_author_url = get_comment_author_url( $comment );
  34. $comment_author = get_comment_author( $comment );
  35. $avatar = get_avatar( $comment, $args['avatar_size'] );
  36. if ( 0 != $args['avatar_size'] ) {
  37. if ( empty( $comment_author_url ) ) {
  38. echo $avatar;
  39. } else {
  40. printf( '<a href="%s" rel="external nofollow" class="url">', $comment_author_url );
  41. echo $avatar;
  42. }
  43. }
  44. /*
  45. * Using the `check` icon instead of `check_circle`, since we can't add a
  46. * fill color to the inner check shape when in circle form.
  47. */
  48. if ( varia_is_comment_by_post_author( $comment ) ) {
  49. printf( '<span class="post-author-badge" aria-hidden="true">%s</span>', varia_get_icon_svg( 'check', 24 ) );
  50. }
  51. /*
  52. * Using the `check` icon instead of `check_circle`, since we can't add a
  53. * fill color to the inner check shape when in circle form.
  54. */
  55. if ( varia_is_comment_by_post_author( $comment ) ) {
  56. printf( '<span class="post-author-badge" aria-hidden="true">%s</span>', varia_get_icon_svg( 'check', 24 ) );
  57. }
  58. printf(
  59. /* translators: %s: comment author link */
  60. wp_kses(
  61. __( '%s <span class="screen-reader-text says">says:</span>', 'varia' ),
  62. array(
  63. 'span' => array(
  64. 'class' => array(),
  65. ),
  66. )
  67. ),
  68. '<b class="fn">' . get_comment_author_link( $comment ) . '</b>'
  69. );
  70. if ( ! empty( $comment_author_url ) ) {
  71. echo '</a>';
  72. }
  73. ?>
  74. </div><!-- .comment-author -->
  75. <div class="comment-metadata">
  76. <a href="<?php echo esc_url( get_comment_link( $comment, $args ) ); ?>">
  77. <?php
  78. /* translators: 1: comment date, 2: comment time */
  79. $comment_timestamp = sprintf( __( '%1$s at %2$s', 'varia' ), get_comment_date( '', $comment ), get_comment_time() );
  80. ?>
  81. <time datetime="<?php comment_time( 'c' ); ?>" title="<?php echo $comment_timestamp; ?>">
  82. <?php echo $comment_timestamp; ?>
  83. </time>
  84. </a>
  85. <?php
  86. $edit_comment_icon = varia_get_icon_svg( 'edit', 16 );
  87. edit_comment_link( __( 'Edit', 'varia' ), '<span class="edit-link-sep">&mdash;</span> <span class="edit-link">' . $edit_comment_icon, '</span>' );
  88. ?>
  89. </div><!-- .comment-metadata -->
  90. <?php if ( '0' == $comment->comment_approved ) : ?>
  91. <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'varia' ); ?></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. }