[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-content/themes/twentytwenty/classes/ -> class-twentytwenty-walker-comment.php (source)

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


Generated: Sat May 15 01:00:05 2021 Cross-referenced by PHPXref 0.7.1