angelovcom.net

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class-twentytwenty-walker-comment.php (4799B)


      1 <?php
      2 /**
      3  * Custom comment walker for this theme.
      4  *
      5  * @package WordPress
      6  * @subpackage Twenty_Twenty
      7  * @since Twenty Twenty 1.0
      8  */
      9 
     10 if ( ! class_exists( 'TwentyTwenty_Walker_Comment' ) ) {
     11 	/**
     12 	 * CUSTOM COMMENT WALKER
     13 	 * A custom walker for comments, based on the walker in Twenty Nineteen.
     14 	 *
     15 	 * @since Twenty Twenty 1.0
     16 	 */
     17 	class TwentyTwenty_Walker_Comment extends Walker_Comment {
     18 
     19 		/**
     20 		 * Outputs a comment in the HTML5 format.
     21 		 *
     22 		 * @since Twenty Twenty 1.0
     23 		 *
     24 		 * @see wp_list_comments()
     25 		 * @see https://developer.wordpress.org/reference/functions/get_comment_author_url/
     26 		 * @see https://developer.wordpress.org/reference/functions/get_comment_author/
     27 		 * @see https://developer.wordpress.org/reference/functions/get_avatar/
     28 		 * @see https://developer.wordpress.org/reference/functions/get_comment_reply_link/
     29 		 * @see https://developer.wordpress.org/reference/functions/get_edit_comment_link/
     30 		 *
     31 		 * @param WP_Comment $comment Comment to display.
     32 		 * @param int        $depth   Depth of the current comment.
     33 		 * @param array      $args    An array of arguments.
     34 		 */
     35 		protected function html5_comment( $comment, $depth, $args ) {
     36 
     37 			$tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
     38 
     39 			?>
     40 			<<?php echo $tag; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- static output ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $this->has_children ? 'parent' : '', $comment ); ?>>
     41 				<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
     42 					<footer class="comment-meta">
     43 						<div class="comment-author vcard">
     44 							<?php
     45 							$comment_author_url = get_comment_author_url( $comment );
     46 							$comment_author     = get_comment_author( $comment );
     47 							$avatar             = get_avatar( $comment, $args['avatar_size'] );
     48 							if ( 0 !== $args['avatar_size'] ) {
     49 								if ( empty( $comment_author_url ) ) {
     50 									echo wp_kses_post( $avatar );
     51 								} else {
     52 									printf( '<a href="%s" rel="external nofollow" class="url">', $comment_author_url ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped --Escaped in https://developer.wordpress.org/reference/functions/get_comment_author_url/
     53 									echo wp_kses_post( $avatar );
     54 								}
     55 							}
     56 
     57 							printf(
     58 								'<span class="fn">%1$s</span><span class="screen-reader-text says">%2$s</span>',
     59 								esc_html( $comment_author ),
     60 								__( 'says:', 'twentytwenty' )
     61 							);
     62 
     63 							if ( ! empty( $comment_author_url ) ) {
     64 								echo '</a>';
     65 							}
     66 							?>
     67 						</div><!-- .comment-author -->
     68 
     69 						<div class="comment-metadata">
     70 							<?php
     71 							/* translators: 1: Comment date, 2: Comment time. */
     72 							$comment_timestamp = sprintf( __( '%1$s at %2$s', 'twentytwenty' ), get_comment_date( '', $comment ), get_comment_time() );
     73 
     74 							printf(
     75 								'<a href="%s"><time datetime="%s" title="%s">%s</time></a>',
     76 								esc_url( get_comment_link( $comment, $args ) ),
     77 								get_comment_time( 'c' ),
     78 								esc_attr( $comment_timestamp ),
     79 								esc_html( $comment_timestamp )
     80 							);
     81 
     82 							if ( get_edit_comment_link() ) {
     83 								printf(
     84 									' <span aria-hidden="true">&bull;</span> <a class="comment-edit-link" href="%s">%s</a>',
     85 									esc_url( get_edit_comment_link() ),
     86 									__( 'Edit', 'twentytwenty' )
     87 								);
     88 							}
     89 							?>
     90 						</div><!-- .comment-metadata -->
     91 
     92 					</footer><!-- .comment-meta -->
     93 
     94 					<div class="comment-content entry-content">
     95 
     96 						<?php
     97 
     98 						comment_text();
     99 
    100 						if ( '0' === $comment->comment_approved ) {
    101 							?>
    102 							<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentytwenty' ); ?></p>
    103 							<?php
    104 						}
    105 
    106 						?>
    107 
    108 					</div><!-- .comment-content -->
    109 
    110 					<?php
    111 
    112 					$comment_reply_link = get_comment_reply_link(
    113 						array_merge(
    114 							$args,
    115 							array(
    116 								'add_below' => 'div-comment',
    117 								'depth'     => $depth,
    118 								'max_depth' => $args['max_depth'],
    119 								'before'    => '<span class="comment-reply">',
    120 								'after'     => '</span>',
    121 							)
    122 						)
    123 					);
    124 
    125 					$by_post_author = twentytwenty_is_comment_by_post_author( $comment );
    126 
    127 					if ( $comment_reply_link || $by_post_author ) {
    128 						?>
    129 
    130 						<footer class="comment-footer-meta">
    131 
    132 							<?php
    133 							if ( $comment_reply_link ) {
    134 								echo $comment_reply_link; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Link is escaped in https://developer.wordpress.org/reference/functions/get_comment_reply_link/
    135 							}
    136 							if ( $by_post_author ) {
    137 								echo '<span class="by-post-author">' . __( 'By Post Author', 'twentytwenty' ) . '</span>';
    138 							}
    139 							?>
    140 
    141 						</footer>
    142 
    143 						<?php
    144 					}
    145 					?>
    146 
    147 				</article><!-- .comment-body -->
    148 
    149 			<?php
    150 		}
    151 	}
    152 }