angelovcom.net

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

class-twentynineteen-walker-comment.php (4084B)


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