walker-comment.php
118 lines
| 1 | <?php |
| 2 | |
| 3 | class Kubio_Walker_Comment extends Walker_Comment { |
| 4 | |
| 5 | private function printAvatar( $comment, $depth, $args ) { |
| 6 | if ( 0 != $args['avatar_size'] ) { |
| 7 | echo get_avatar( $comment, $args['avatar_size'] ); |
| 8 | } |
| 9 | } |
| 10 | |
| 11 | private function printAuthor( $comment, $depth, $args ) { |
| 12 | $comment_author = get_comment_author_link( $comment ); |
| 13 | |
| 14 | if ( '0' == $comment->comment_approved ) { |
| 15 | $comment_author = get_comment_author( $comment ); |
| 16 | } |
| 17 | |
| 18 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 19 | printf( '<b class="fn">%s</b>', $comment_author ); |
| 20 | } |
| 21 | |
| 22 | private function printMetadata( $comment, $depth, $args ) { |
| 23 | printf( |
| 24 | '<a href="%s"><time datetime="%s">%s</time></a>', |
| 25 | esc_url( get_comment_link( $comment, $args ) ), |
| 26 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 27 | get_comment_time( 'c' ), |
| 28 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 29 | sprintf( |
| 30 | /* translators: 1: Comment date, 2: Comment time. */ |
| 31 | esc_html__( '%1$s at %2$s', 'kubio' ), |
| 32 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 33 | get_comment_date( '', $comment ), |
| 34 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 35 | get_comment_time() |
| 36 | ) |
| 37 | ); |
| 38 | |
| 39 | edit_comment_link( __( 'Edit', 'kubio' ), ' <span class="edit-link">', '</span>' ); |
| 40 | |
| 41 | $commenter = wp_get_current_commenter(); |
| 42 | if ( $commenter['comment_author_email'] ) { |
| 43 | $moderation_note = __( 'Your comment is awaiting moderation.', 'kubio' ); |
| 44 | } else { |
| 45 | $moderation_note = __( |
| 46 | 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.', |
| 47 | 'kubio' |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | if ( '0' == $comment->comment_approved ) : ?> |
| 52 | <em class="comment-awaiting-moderation"><?php echo esc_html( $moderation_note ); ?></em> |
| 53 | <?php |
| 54 | endif; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Outputs a comment in the HTML5 format. |
| 59 | * |
| 60 | * @since 3.6.0 |
| 61 | * |
| 62 | * @see wp_list_comments() |
| 63 | * |
| 64 | * @param WP_Comment $comment Comment to display. |
| 65 | * @param int $depth Depth of the current comment. |
| 66 | * @param array $args An array of arguments. |
| 67 | */ |
| 68 | protected function html5_comment( $comment, $depth, $args ) { |
| 69 | $tag = 'div' === $args['style'] ? 'div' : 'li'; |
| 70 | |
| 71 | $commenter = wp_get_current_commenter(); |
| 72 | $show_pending_links = ! empty( $commenter['comment_author'] ); |
| 73 | |
| 74 | // phpcs:disable |
| 75 | ?> |
| 76 | <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?>> |
| 77 | <article id="div-comment-<?php comment_ID(); ?>" class="comment-body"> |
| 78 | <footer class="comment-meta"> |
| 79 | <div class="comment-author vcard"> |
| 80 | <?php $this->printAvatar( $comment, $depth, $args ); ?> |
| 81 | <div> |
| 82 | <div> |
| 83 | <?php $this->printAuthor( $comment, $depth, $args ); ?> |
| 84 | </div> |
| 85 | <div class="comment-metadata "> |
| 86 | <?php $this->printMetadata( $comment, $depth, $args ); ?> |
| 87 | </div> |
| 88 | </div> |
| 89 | </div> |
| 90 | </footer><!-- .comment-meta --> |
| 91 | |
| 92 | <div class="comment-content"> |
| 93 | <?php comment_text(); ?> |
| 94 | </div><!-- .comment-content --> |
| 95 | |
| 96 | <?php |
| 97 | if ( '1' == $comment->comment_approved || $show_pending_links ) { |
| 98 | comment_reply_link( |
| 99 | array_merge( |
| 100 | $args, |
| 101 | array( |
| 102 | 'add_below' => 'div-comment', |
| 103 | 'depth' => $depth, |
| 104 | 'max_depth' => $args['max_depth'], |
| 105 | 'before' => '<div class="reply">', |
| 106 | 'after' => '</div>', |
| 107 | ) |
| 108 | ) |
| 109 | ); |
| 110 | } |
| 111 | ?> |
| 112 | </article><!-- .comment-body --> |
| 113 | <?php |
| 114 | |
| 115 | // phpcs:enable |
| 116 | } |
| 117 | } |
| 118 |