[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> comment-template.php (source)

   1  <?php
   2  /**
   3   * Comment template functions
   4   *
   5   * These functions are meant to live inside of the WordPress loop.
   6   *
   7   * @package WordPress
   8   * @subpackage Template
   9   */
  10  
  11  /**
  12   * Retrieves the author of the current comment.
  13   *
  14   * If the comment has an empty comment_author field, then 'Anonymous' person is
  15   * assumed.
  16   *
  17   * @since 1.5.0
  18   * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
  19   *
  20   * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to retrieve the author.
  21   *                                   Default current comment.
  22   * @return string The comment author
  23   */
  24  function get_comment_author( $comment_ID = 0 ) {
  25      $comment    = get_comment( $comment_ID );
  26      $comment_ID = ! empty( $comment->comment_ID ) ? $comment->comment_ID : $comment_ID;
  27  
  28      if ( empty( $comment->comment_author ) ) {
  29          $user = ! empty( $comment->user_id ) ? get_userdata( $comment->user_id ) : false;
  30          if ( $user ) {
  31              $author = $user->display_name;
  32          } else {
  33              $author = __( 'Anonymous' );
  34          }
  35      } else {
  36          $author = $comment->comment_author;
  37      }
  38  
  39      /**
  40       * Filters the returned comment author name.
  41       *
  42       * @since 1.5.0
  43       * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
  44       *
  45       * @param string     $author     The comment author's username.
  46       * @param string     $comment_ID The comment ID as a numeric string.
  47       * @param WP_Comment $comment    The comment object.
  48       */
  49      return apply_filters( 'get_comment_author', $author, $comment_ID, $comment );
  50  }
  51  
  52  /**
  53   * Displays the author of the current comment.
  54   *
  55   * @since 0.71
  56   * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
  57   *
  58   * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author.
  59   *                                   Default current comment.
  60   */
  61  function comment_author( $comment_ID = 0 ) {
  62      $comment = get_comment( $comment_ID );
  63      $author  = get_comment_author( $comment );
  64  
  65      /**
  66       * Filters the comment author's name for display.
  67       *
  68       * @since 1.2.0
  69       * @since 4.1.0 The `$comment_ID` parameter was added.
  70       *
  71       * @param string $author     The comment author's username.
  72       * @param string $comment_ID The comment ID as a numeric string.
  73       */
  74      echo apply_filters( 'comment_author', $author, $comment->comment_ID );
  75  }
  76  
  77  /**
  78   * Retrieves the email of the author of the current comment.
  79   *
  80   * @since 1.5.0
  81   * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
  82   *
  83   * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's email.
  84   *                                   Default current comment.
  85   * @return string The current comment author's email
  86   */
  87  function get_comment_author_email( $comment_ID = 0 ) {
  88      $comment = get_comment( $comment_ID );
  89  
  90      /**
  91       * Filters the comment author's returned email address.
  92       *
  93       * @since 1.5.0
  94       * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
  95       *
  96       * @param string     $comment_author_email The comment author's email address.
  97       * @param string     $comment_ID           The comment ID as a numeric string.
  98       * @param WP_Comment $comment              The comment object.
  99       */
 100      return apply_filters( 'get_comment_author_email', $comment->comment_author_email, $comment->comment_ID, $comment );
 101  }
 102  
 103  /**
 104   * Displays the email of the author of the current global $comment.
 105   *
 106   * Care should be taken to protect the email address and assure that email
 107   * harvesters do not capture your commenter's email address. Most assume that
 108   * their email address will not appear in raw form on the site. Doing so will
 109   * enable anyone, including those that people don't want to get the email
 110   * address and use it for their own means good and bad.
 111   *
 112   * @since 0.71
 113   * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 114   *
 115   * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's email.
 116   *                                   Default current comment.
 117   */
 118  function comment_author_email( $comment_ID = 0 ) {
 119      $comment      = get_comment( $comment_ID );
 120      $author_email = get_comment_author_email( $comment );
 121  
 122      /**
 123       * Filters the comment author's email for display.
 124       *
 125       * @since 1.2.0
 126       * @since 4.1.0 The `$comment_ID` parameter was added.
 127       *
 128       * @param string $author_email The comment author's email address.
 129       * @param string $comment_ID   The comment ID as a numeric string.
 130       */
 131      echo apply_filters( 'author_email', $author_email, $comment->comment_ID );
 132  }
 133  
 134  /**
 135   * Displays the HTML email link to the author of the current comment.
 136   *
 137   * Care should be taken to protect the email address and assure that email
 138   * harvesters do not capture your commenter's email address. Most assume that
 139   * their email address will not appear in raw form on the site. Doing so will
 140   * enable anyone, including those that people don't want to get the email
 141   * address and use it for their own means good and bad.
 142   *
 143   * @since 0.71
 144   * @since 4.6.0 Added the `$comment` parameter.
 145   *
 146   * @param string         $linktext Optional. Text to display instead of the comment author's email address.
 147   *                                 Default empty.
 148   * @param string         $before   Optional. Text or HTML to display before the email link. Default empty.
 149   * @param string         $after    Optional. Text or HTML to display after the email link. Default empty.
 150   * @param int|WP_Comment $comment  Optional. Comment ID or WP_Comment object. Default is the current comment.
 151   */
 152  function comment_author_email_link( $linktext = '', $before = '', $after = '', $comment = null ) {
 153      $link = get_comment_author_email_link( $linktext, $before, $after, $comment );
 154      if ( $link ) {
 155          echo $link;
 156      }
 157  }
 158  
 159  /**
 160   * Returns the HTML email link to the author of the current comment.
 161   *
 162   * Care should be taken to protect the email address and assure that email
 163   * harvesters do not capture your commenter's email address. Most assume that
 164   * their email address will not appear in raw form on the site. Doing so will
 165   * enable anyone, including those that people don't want to get the email
 166   * address and use it for their own means good and bad.
 167   *
 168   * @since 2.7.0
 169   * @since 4.6.0 Added the `$comment` parameter.
 170   *
 171   * @param string         $linktext Optional. Text to display instead of the comment author's email address.
 172   *                                 Default empty.
 173   * @param string         $before   Optional. Text or HTML to display before the email link. Default empty.
 174   * @param string         $after    Optional. Text or HTML to display after the email link. Default empty.
 175   * @param int|WP_Comment $comment  Optional. Comment ID or WP_Comment object. Default is the current comment.
 176   * @return string HTML markup for the comment author email link. By default, the email address is obfuscated
 177   *                via the {@see 'comment_email'} filter with antispambot().
 178   */
 179  function get_comment_author_email_link( $linktext = '', $before = '', $after = '', $comment = null ) {
 180      $comment = get_comment( $comment );
 181  
 182      /**
 183       * Filters the comment author's email for display.
 184       *
 185       * Care should be taken to protect the email address and assure that email
 186       * harvesters do not capture your commenter's email address.
 187       *
 188       * @since 1.2.0
 189       * @since 4.1.0 The `$comment` parameter was added.
 190       *
 191       * @param string     $comment_author_email The comment author's email address.
 192       * @param WP_Comment $comment              The comment object.
 193       */
 194      $email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );
 195  
 196      if ( ( ! empty( $email ) ) && ( '@' !== $email ) ) {
 197          $display = ( '' !== $linktext ) ? $linktext : $email;
 198          $return  = $before;
 199          $return .= sprintf( '<a href="%1$s">%2$s</a>', esc_url( 'mailto:' . $email ), esc_html( $display ) );
 200          $return .= $after;
 201          return $return;
 202      } else {
 203          return '';
 204      }
 205  }
 206  
 207  /**
 208   * Retrieves the HTML link to the URL of the author of the current comment.
 209   *
 210   * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
 211   * which falls back to the global comment variable if the $comment_ID argument is empty.
 212   *
 213   * @since 1.5.0
 214   * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 215   *
 216   * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's link.
 217   *                                   Default current comment.
 218   * @return string The comment author name or HTML link for author's URL.
 219   */
 220  function get_comment_author_link( $comment_ID = 0 ) {
 221      $comment = get_comment( $comment_ID );
 222      $url     = get_comment_author_url( $comment );
 223      $author  = get_comment_author( $comment );
 224  
 225      if ( empty( $url ) || 'http://' === $url ) {
 226          $return = $author;
 227      } else {
 228          $return = "<a href='$url' rel='external nofollow ugc' class='url'>$author</a>";
 229      }
 230  
 231      /**
 232       * Filters the comment author's link for display.
 233       *
 234       * @since 1.5.0
 235       * @since 4.1.0 The `$author` and `$comment_ID` parameters were added.
 236       *
 237       * @param string $return     The HTML-formatted comment author link.
 238       *                           Empty for an invalid URL.
 239       * @param string $author     The comment author's username.
 240       * @param string $comment_ID The comment ID as a numeric string.
 241       */
 242      return apply_filters( 'get_comment_author_link', $return, $author, $comment->comment_ID );
 243  }
 244  
 245  /**
 246   * Displays the HTML link to the URL of the author of the current comment.
 247   *
 248   * @since 0.71
 249   * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 250   *
 251   * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's link.
 252   *                                   Default current comment.
 253   */
 254  function comment_author_link( $comment_ID = 0 ) {
 255      echo get_comment_author_link( $comment_ID );
 256  }
 257  
 258  /**
 259   * Retrieves the IP address of the author of the current comment.
 260   *
 261   * @since 1.5.0
 262   * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 263   *
 264   * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's IP address.
 265   *                                   Default current comment.
 266   * @return string Comment author's IP address, or an empty string if it's not available.
 267   */
 268  function get_comment_author_IP( $comment_ID = 0 ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
 269      $comment = get_comment( $comment_ID );
 270  
 271      /**
 272       * Filters the comment author's returned IP address.
 273       *
 274       * @since 1.5.0
 275       * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
 276       *
 277       * @param string     $comment_author_IP The comment author's IP address, or an empty string if it's not available.
 278       * @param string     $comment_ID        The comment ID as a numeric string.
 279       * @param WP_Comment $comment           The comment object.
 280       */
 281      return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP, $comment->comment_ID, $comment );  // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
 282  }
 283  
 284  /**
 285   * Displays the IP address of the author of the current comment.
 286   *
 287   * @since 0.71
 288   * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 289   *
 290   * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's IP address.
 291   *                                   Default current comment.
 292   */
 293  function comment_author_IP( $comment_ID = 0 ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
 294      echo esc_html( get_comment_author_IP( $comment_ID ) );
 295  }
 296  
 297  /**
 298   * Retrieves the URL of the author of the current comment, not linked.
 299   *
 300   * @since 1.5.0
 301   * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 302   *
 303   * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's URL.
 304   *                                   Default current comment.
 305   * @return string Comment author URL, if provided, an empty string otherwise.
 306   */
 307  function get_comment_author_url( $comment_ID = 0 ) {
 308      $comment = get_comment( $comment_ID );
 309      $url     = '';
 310      $id      = 0;
 311  
 312      if ( ! empty( $comment ) ) {
 313          $author_url = ( 'http://' === $comment->comment_author_url ) ? '' : $comment->comment_author_url;
 314          $url        = esc_url( $author_url, array( 'http', 'https' ) );
 315          $id         = $comment->comment_ID;
 316      }
 317  
 318      /**
 319       * Filters the comment author's URL.
 320       *
 321       * @since 1.5.0
 322       * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
 323       *
 324       * @param string          $url        The comment author's URL, or an empty string.
 325       * @param string|int      $comment_ID The comment ID as a numeric string, or 0 if not found.
 326       * @param WP_Comment|null $comment    The comment object, or null if not found.
 327       */
 328      return apply_filters( 'get_comment_author_url', $url, $id, $comment );
 329  }
 330  
 331  /**
 332   * Displays the URL of the author of the current comment, not linked.
 333   *
 334   * @since 0.71
 335   * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 336   *
 337   * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's URL.
 338   *                                   Default current comment.
 339   */
 340  function comment_author_url( $comment_ID = 0 ) {
 341      $comment    = get_comment( $comment_ID );
 342      $author_url = get_comment_author_url( $comment );
 343  
 344      /**
 345       * Filters the comment author's URL for display.
 346       *
 347       * @since 1.2.0
 348       * @since 4.1.0 The `$comment_ID` parameter was added.
 349       *
 350       * @param string $author_url The comment author's URL.
 351       * @param string $comment_ID The comment ID as a numeric string.
 352       */
 353      echo apply_filters( 'comment_url', $author_url, $comment->comment_ID );
 354  }
 355  
 356  /**
 357   * Retrieves the HTML link of the URL of the author of the current comment.
 358   *
 359   * $linktext parameter is only used if the URL does not exist for the comment
 360   * author. If the URL does exist then the URL will be used and the $linktext
 361   * will be ignored.
 362   *
 363   * Encapsulate the HTML link between the $before and $after. So it will appear
 364   * in the order of $before, link, and finally $after.
 365   *
 366   * @since 1.5.0
 367   * @since 4.6.0 Added the `$comment` parameter.
 368   *
 369   * @param string         $linktext Optional. The text to display instead of the comment
 370   *                                 author's email address. Default empty.
 371   * @param string         $before   Optional. The text or HTML to display before the email link.
 372   *                                 Default empty.
 373   * @param string         $after    Optional. The text or HTML to display after the email link.
 374   *                                 Default empty.
 375   * @param int|WP_Comment $comment  Optional. Comment ID or WP_Comment object.
 376   *                                 Default is the current comment.
 377   * @return string The HTML link between the $before and $after parameters.
 378   */
 379  function get_comment_author_url_link( $linktext = '', $before = '', $after = '', $comment = 0 ) {
 380      $url     = get_comment_author_url( $comment );
 381      $display = ( '' !== $linktext ) ? $linktext : $url;
 382      $display = str_replace( 'http://www.', '', $display );
 383      $display = str_replace( 'http://', '', $display );
 384  
 385      if ( '/' === substr( $display, -1 ) ) {
 386          $display = substr( $display, 0, -1 );
 387      }
 388  
 389      $return = "$before<a href='$url' rel='external'>$display</a>$after";
 390  
 391      /**
 392       * Filters the comment author's returned URL link.
 393       *
 394       * @since 1.5.0
 395       *
 396       * @param string $return The HTML-formatted comment author URL link.
 397       */
 398      return apply_filters( 'get_comment_author_url_link', $return );
 399  }
 400  
 401  /**
 402   * Displays the HTML link of the URL of the author of the current comment.
 403   *
 404   * @since 0.71
 405   * @since 4.6.0 Added the `$comment` parameter.
 406   *
 407   * @param string         $linktext Optional. Text to display instead of the comment author's
 408   *                                 email address. Default empty.
 409   * @param string         $before   Optional. Text or HTML to display before the email link.
 410   *                                 Default empty.
 411   * @param string         $after    Optional. Text or HTML to display after the email link.
 412   *                                 Default empty.
 413   * @param int|WP_Comment $comment  Optional. Comment ID or WP_Comment object.
 414   *                                 Default is the current comment.
 415   */
 416  function comment_author_url_link( $linktext = '', $before = '', $after = '', $comment = 0 ) {
 417      echo get_comment_author_url_link( $linktext, $before, $after, $comment );
 418  }
 419  
 420  /**
 421   * Generates semantic classes for each comment element.
 422   *
 423   * @since 2.7.0
 424   * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object.
 425   *
 426   * @param string|string[] $css_class Optional. One or more classes to add to the class list.
 427   *                                   Default empty.
 428   * @param int|WP_Comment  $comment   Comment ID or WP_Comment object. Default current comment.
 429   * @param int|WP_Post     $post_id   Post ID or WP_Post object. Default current post.
 430   * @param bool            $display   Optional. Whether to print or return the output.
 431   *                                   Default true.
 432   * @return void|string Void if `$display` argument is true, comment classes if `$display` is false.
 433   */
 434  function comment_class( $css_class = '', $comment = null, $post_id = null, $display = true ) {
 435      // Separates classes with a single space, collates classes for comment DIV.
 436      $css_class = 'class="' . implode( ' ', get_comment_class( $css_class, $comment, $post_id ) ) . '"';
 437  
 438      if ( $display ) {
 439          echo $css_class;
 440      } else {
 441          return $css_class;
 442      }
 443  }
 444  
 445  /**
 446   * Returns the classes for the comment div as an array.
 447   *
 448   * @since 2.7.0
 449   * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
 450   *
 451   * @global int $comment_alt
 452   * @global int $comment_depth
 453   * @global int $comment_thread_alt
 454   *
 455   * @param string|string[] $css_class  Optional. One or more classes to add to the class list. Default empty.
 456   * @param int|WP_Comment  $comment_id Comment ID or WP_Comment object. Default current comment.
 457   * @param int|WP_Post     $post_id    Post ID or WP_Post object. Default current post.
 458   * @return string[] An array of classes.
 459   */
 460  function get_comment_class( $css_class = '', $comment_id = null, $post_id = null ) {
 461      global $comment_alt, $comment_depth, $comment_thread_alt;
 462  
 463      $classes = array();
 464  
 465      $comment = get_comment( $comment_id );
 466      if ( ! $comment ) {
 467          return $classes;
 468      }
 469  
 470      // Get the comment type (comment, trackback).
 471      $classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
 472  
 473      // Add classes for comment authors that are registered users.
 474      $user = $comment->user_id ? get_userdata( $comment->user_id ) : false;
 475      if ( $user ) {
 476          $classes[] = 'byuser';
 477          $classes[] = 'comment-author-' . sanitize_html_class( $user->user_nicename, $comment->user_id );
 478          // For comment authors who are the author of the post.
 479          $post = get_post( $post_id );
 480          if ( $post ) {
 481              if ( $comment->user_id === $post->post_author ) {
 482                  $classes[] = 'bypostauthor';
 483              }
 484          }
 485      }
 486  
 487      if ( empty( $comment_alt ) ) {
 488          $comment_alt = 0;
 489      }
 490      if ( empty( $comment_depth ) ) {
 491          $comment_depth = 1;
 492      }
 493      if ( empty( $comment_thread_alt ) ) {
 494          $comment_thread_alt = 0;
 495      }
 496  
 497      if ( $comment_alt % 2 ) {
 498          $classes[] = 'odd';
 499          $classes[] = 'alt';
 500      } else {
 501          $classes[] = 'even';
 502      }
 503  
 504      $comment_alt++;
 505  
 506      // Alt for top-level comments.
 507      if ( 1 == $comment_depth ) {
 508          if ( $comment_thread_alt % 2 ) {
 509              $classes[] = 'thread-odd';
 510              $classes[] = 'thread-alt';
 511          } else {
 512              $classes[] = 'thread-even';
 513          }
 514          $comment_thread_alt++;
 515      }
 516  
 517      $classes[] = "depth-$comment_depth";
 518  
 519      if ( ! empty( $css_class ) ) {
 520          if ( ! is_array( $css_class ) ) {
 521              $css_class = preg_split( '#\s+#', $css_class );
 522          }
 523          $classes = array_merge( $classes, $css_class );
 524      }
 525  
 526      $classes = array_map( 'esc_attr', $classes );
 527  
 528      /**
 529       * Filters the returned CSS classes for the current comment.
 530       *
 531       * @since 2.7.0
 532       *
 533       * @param string[]    $classes    An array of comment classes.
 534       * @param string[]    $css_class  An array of additional classes added to the list.
 535       * @param string      $comment_id The comment ID as a numeric string.
 536       * @param WP_Comment  $comment    The comment object.
 537       * @param int|WP_Post $post_id    The post ID or WP_Post object.
 538       */
 539      return apply_filters( 'comment_class', $classes, $css_class, $comment->comment_ID, $comment, $post_id );
 540  }
 541  
 542  /**
 543   * Retrieves the comment date of the current comment.
 544   *
 545   * @since 1.5.0
 546   * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 547   *
 548   * @param string         $format     Optional. PHP date format. Defaults to the 'date_format' option.
 549   * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the date.
 550   *                                   Default current comment.
 551   * @return string The comment's date.
 552   */
 553  function get_comment_date( $format = '', $comment_ID = 0 ) {
 554      $comment = get_comment( $comment_ID );
 555  
 556      $_format = ! empty( $format ) ? $format : get_option( 'date_format' );
 557  
 558      $date = mysql2date( $_format, $comment->comment_date );
 559  
 560      /**
 561       * Filters the returned comment date.
 562       *
 563       * @since 1.5.0
 564       *
 565       * @param string|int $date    Formatted date string or Unix timestamp.
 566       * @param string     $format  PHP date format.
 567       * @param WP_Comment $comment The comment object.
 568       */
 569      return apply_filters( 'get_comment_date', $date, $format, $comment );
 570  }
 571  
 572  /**
 573   * Displays the comment date of the current comment.
 574   *
 575   * @since 0.71
 576   * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 577   *
 578   * @param string         $format     Optional. PHP date format. Defaults to the 'date_format' option.
 579   * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the date.
 580   *                                   Default current comment.
 581   */
 582  function comment_date( $format = '', $comment_ID = 0 ) {
 583      echo get_comment_date( $format, $comment_ID );
 584  }
 585  
 586  /**
 587   * Retrieves the excerpt of the given comment.
 588   *
 589   * Returns a maximum of 20 words with an ellipsis appended if necessary.
 590   *
 591   * @since 1.5.0
 592   * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 593   *
 594   * @param int|WP_Comment $comment_ID  WP_Comment or ID of the comment for which to get the excerpt.
 595   *                                    Default current comment.
 596   * @return string The possibly truncated comment excerpt.
 597   */
 598  function get_comment_excerpt( $comment_ID = 0 ) {
 599      $comment = get_comment( $comment_ID );
 600  
 601      if ( ! post_password_required( $comment->comment_post_ID ) ) {
 602          $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
 603      } else {
 604          $comment_text = __( 'Password protected' );
 605      }
 606  
 607      /* translators: Maximum number of words used in a comment excerpt. */
 608      $comment_excerpt_length = (int) _x( '20', 'comment_excerpt_length' );
 609  
 610      /**
 611       * Filters the maximum number of words used in the comment excerpt.
 612       *
 613       * @since 4.4.0
 614       *
 615       * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt.
 616       */
 617      $comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length );
 618  
 619      $excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '&hellip;' );
 620  
 621      /**
 622       * Filters the retrieved comment excerpt.
 623       *
 624       * @since 1.5.0
 625       * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
 626       *
 627       * @param string     $excerpt    The comment excerpt text.
 628       * @param string     $comment_ID The comment ID as a numeric string.
 629       * @param WP_Comment $comment    The comment object.
 630       */
 631      return apply_filters( 'get_comment_excerpt', $excerpt, $comment->comment_ID, $comment );
 632  }
 633  
 634  /**
 635   * Displays the excerpt of the current comment.
 636   *
 637   * @since 1.2.0
 638   * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 639   *
 640   * @param int|WP_Comment $comment_ID  WP_Comment or ID of the comment for which to print the excerpt.
 641   *                                    Default current comment.
 642   */
 643  function comment_excerpt( $comment_ID = 0 ) {
 644      $comment         = get_comment( $comment_ID );
 645      $comment_excerpt = get_comment_excerpt( $comment );
 646  
 647      /**
 648       * Filters the comment excerpt for display.
 649       *
 650       * @since 1.2.0
 651       * @since 4.1.0 The `$comment_ID` parameter was added.
 652       *
 653       * @param string $comment_excerpt The comment excerpt text.
 654       * @param string $comment_ID      The comment ID as a numeric string.
 655       */
 656      echo apply_filters( 'comment_excerpt', $comment_excerpt, $comment->comment_ID );
 657  }
 658  
 659  /**
 660   * Retrieves the comment ID of the current comment.
 661   *
 662   * @since 1.5.0
 663   *
 664   * @return string The comment ID as a numeric string.
 665   */
 666  function get_comment_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
 667      $comment    = get_comment();
 668      $comment_ID = ! empty( $comment->comment_ID ) ? $comment->comment_ID : '0';
 669  
 670      /**
 671       * Filters the returned comment ID.
 672       *
 673       * @since 1.5.0
 674       * @since 4.1.0 The `$comment` parameter was added.
 675       *
 676       * @param string     $comment_ID The current comment ID as a numeric string.
 677       * @param WP_Comment $comment    The comment object.
 678       */
 679      return apply_filters( 'get_comment_ID', $comment_ID, $comment );  // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
 680  }
 681  
 682  /**
 683   * Displays the comment ID of the current comment.
 684   *
 685   * @since 0.71
 686   */
 687  function comment_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
 688      echo get_comment_ID();
 689  }
 690  
 691  /**
 692   * Retrieves the link to a given comment.
 693   *
 694   * @since 1.5.0
 695   * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. Added `$cpage` argument.
 696   *
 697   * @see get_page_of_comment()
 698   *
 699   * @global WP_Rewrite $wp_rewrite      WordPress rewrite component.
 700   * @global bool       $in_comment_loop
 701   *
 702   * @param WP_Comment|int|null $comment Comment to retrieve. Default current comment.
 703   * @param array               $args {
 704   *     An array of optional arguments to override the defaults.
 705   *
 706   *     @type string     $type      Passed to get_page_of_comment().
 707   *     @type int        $page      Current page of comments, for calculating comment pagination.
 708   *     @type int        $per_page  Per-page value for comment pagination.
 709   *     @type int        $max_depth Passed to get_page_of_comment().
 710   *     @type int|string $cpage     Value to use for the comment's "comment-page" or "cpage" value.
 711   *                                 If provided, this value overrides any value calculated from `$page`
 712   *                                 and `$per_page`.
 713   * }
 714   * @return string The permalink to the given comment.
 715   */
 716  function get_comment_link( $comment = null, $args = array() ) {
 717      global $wp_rewrite, $in_comment_loop;
 718  
 719      $comment = get_comment( $comment );
 720  
 721      // Back-compat.
 722      if ( ! is_array( $args ) ) {
 723          $args = array( 'page' => $args );
 724      }
 725  
 726      $defaults = array(
 727          'type'      => 'all',
 728          'page'      => '',
 729          'per_page'  => '',
 730          'max_depth' => '',
 731          'cpage'     => null,
 732      );
 733      $args     = wp_parse_args( $args, $defaults );
 734  
 735      $link = get_permalink( $comment->comment_post_ID );
 736  
 737      // The 'cpage' param takes precedence.
 738      if ( ! is_null( $args['cpage'] ) ) {
 739          $cpage = $args['cpage'];
 740  
 741          // No 'cpage' is provided, so we calculate one.
 742      } else {
 743          if ( '' === $args['per_page'] && get_option( 'page_comments' ) ) {
 744              $args['per_page'] = get_option( 'comments_per_page' );
 745          }
 746  
 747          if ( empty( $args['per_page'] ) ) {
 748              $args['per_page'] = 0;
 749              $args['page']     = 0;
 750          }
 751  
 752          $cpage = $args['page'];
 753  
 754          if ( '' == $cpage ) {
 755              if ( ! empty( $in_comment_loop ) ) {
 756                  $cpage = get_query_var( 'cpage' );
 757              } else {
 758                  // Requires a database hit, so we only do it when we can't figure out from context.
 759                  $cpage = get_page_of_comment( $comment->comment_ID, $args );
 760              }
 761          }
 762  
 763          /*
 764           * If the default page displays the oldest comments, the permalinks for comments on the default page
 765           * do not need a 'cpage' query var.
 766           */
 767          if ( 'oldest' === get_option( 'default_comments_page' ) && 1 === $cpage ) {
 768              $cpage = '';
 769          }
 770      }
 771  
 772      if ( $cpage && get_option( 'page_comments' ) ) {
 773          if ( $wp_rewrite->using_permalinks() ) {
 774              if ( $cpage ) {
 775                  $link = trailingslashit( $link ) . $wp_rewrite->comments_pagination_base . '-' . $cpage;
 776              }
 777  
 778              $link = user_trailingslashit( $link, 'comment' );
 779          } elseif ( $cpage ) {
 780              $link = add_query_arg( 'cpage', $cpage, $link );
 781          }
 782      }
 783  
 784      if ( $wp_rewrite->using_permalinks() ) {
 785          $link = user_trailingslashit( $link, 'comment' );
 786      }
 787  
 788      $link = $link . '#comment-' . $comment->comment_ID;
 789  
 790      /**
 791       * Filters the returned single comment permalink.
 792       *
 793       * @since 2.8.0
 794       * @since 4.4.0 Added the `$cpage` parameter.
 795       *
 796       * @see get_page_of_comment()
 797       *
 798       * @param string     $link    The comment permalink with '#comment-$id' appended.
 799       * @param WP_Comment $comment The current comment object.
 800       * @param array      $args    An array of arguments to override the defaults.
 801       * @param int        $cpage   The calculated 'cpage' value.
 802       */
 803      return apply_filters( 'get_comment_link', $link, $comment, $args, $cpage );
 804  }
 805  
 806  /**
 807   * Retrieves the link to the current post comments.
 808   *
 809   * @since 1.5.0
 810   *
 811   * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
 812   * @return string The link to the comments.
 813   */
 814  function get_comments_link( $post_id = 0 ) {
 815      $hash          = get_comments_number( $post_id ) ? '#comments' : '#respond';
 816      $comments_link = get_permalink( $post_id ) . $hash;
 817  
 818      /**
 819       * Filters the returned post comments permalink.
 820       *
 821       * @since 3.6.0
 822       *
 823       * @param string      $comments_link Post comments permalink with '#comments' appended.
 824       * @param int|WP_Post $post_id       Post ID or WP_Post object.
 825       */
 826      return apply_filters( 'get_comments_link', $comments_link, $post_id );
 827  }
 828  
 829  /**
 830   * Displays the link to the current post comments.
 831   *
 832   * @since 0.71
 833   *
 834   * @param string $deprecated   Not Used.
 835   * @param string $deprecated_2 Not Used.
 836   */
 837  function comments_link( $deprecated = '', $deprecated_2 = '' ) {
 838      if ( ! empty( $deprecated ) ) {
 839          _deprecated_argument( __FUNCTION__, '0.72' );
 840      }
 841      if ( ! empty( $deprecated_2 ) ) {
 842          _deprecated_argument( __FUNCTION__, '1.3.0' );
 843      }
 844      echo esc_url( get_comments_link() );
 845  }
 846  
 847  /**
 848   * Retrieves the amount of comments a post has.
 849   *
 850   * @since 1.5.0
 851   *
 852   * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`.
 853   * @return string|int If the post exists, a numeric string representing the number of comments
 854   *                    the post has, otherwise 0.
 855   */
 856  function get_comments_number( $post_id = 0 ) {
 857      $post = get_post( $post_id );
 858  
 859      if ( ! $post ) {
 860          $count = 0;
 861      } else {
 862          $count   = $post->comment_count;
 863          $post_id = $post->ID;
 864      }
 865  
 866      /**
 867       * Filters the returned comment count for a post.
 868       *
 869       * @since 1.5.0
 870       *
 871       * @param string|int $count   A string representing the number of comments a post has, otherwise 0.
 872       * @param int        $post_id Post ID.
 873       */
 874      return apply_filters( 'get_comments_number', $count, $post_id );
 875  }
 876  
 877  /**
 878   * Displays the language string for the number of comments the current post has.
 879   *
 880   * @since 0.71
 881   * @since 5.4.0 The `$deprecated` parameter was changed to `$post_id`.
 882   *
 883   * @param string|false $zero    Optional. Text for no comments. Default false.
 884   * @param string|false $one     Optional. Text for one comment. Default false.
 885   * @param string|false $more    Optional. Text for more than one comment. Default false.
 886   * @param int|WP_Post  $post_id Optional. Post ID or WP_Post object. Default is the global `$post`.
 887   */
 888  function comments_number( $zero = false, $one = false, $more = false, $post_id = 0 ) {
 889      echo get_comments_number_text( $zero, $one, $more, $post_id );
 890  }
 891  
 892  /**
 893   * Displays the language string for the number of comments the current post has.
 894   *
 895   * @since 4.0.0
 896   * @since 5.4.0 Added the `$post_id` parameter to allow using the function outside of the loop.
 897   *
 898   * @param string      $zero    Optional. Text for no comments. Default false.
 899   * @param string      $one     Optional. Text for one comment. Default false.
 900   * @param string      $more    Optional. Text for more than one comment. Default false.
 901   * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`.
 902   * @return string Language string for the number of comments a post has.
 903   */
 904  function get_comments_number_text( $zero = false, $one = false, $more = false, $post_id = 0 ) {
 905      $number = get_comments_number( $post_id );
 906  
 907      if ( $number > 1 ) {
 908          if ( false === $more ) {
 909              /* translators: %s: Number of comments. */
 910              $output = sprintf( _n( '%s Comment', '%s Comments', $number ), number_format_i18n( $number ) );
 911          } else {
 912              // % Comments
 913              /*
 914               * translators: If comment number in your language requires declension,
 915               * translate this to 'on'. Do not translate into your own language.
 916               */
 917              if ( 'on' === _x( 'off', 'Comment number declension: on or off' ) ) {
 918                  $text = preg_replace( '#<span class="screen-reader-text">.+?</span>#', '', $more );
 919                  $text = preg_replace( '/&.+?;/', '', $text ); // Kill entities.
 920                  $text = trim( strip_tags( $text ), '% ' );
 921  
 922                  // Replace '% Comments' with a proper plural form.
 923                  if ( $text && ! preg_match( '/[0-9]+/', $text ) && false !== strpos( $more, '%' ) ) {
 924                      /* translators: %s: Number of comments. */
 925                      $new_text = _n( '%s Comment', '%s Comments', $number );
 926                      $new_text = trim( sprintf( $new_text, '' ) );
 927  
 928                      $more = str_replace( $text, $new_text, $more );
 929                      if ( false === strpos( $more, '%' ) ) {
 930                          $more = '% ' . $more;
 931                      }
 932                  }
 933              }
 934  
 935              $output = str_replace( '%', number_format_i18n( $number ), $more );
 936          }
 937      } elseif ( 0 == $number ) {
 938          $output = ( false === $zero ) ? __( 'No Comments' ) : $zero;
 939      } else { // Must be one.
 940          $output = ( false === $one ) ? __( '1 Comment' ) : $one;
 941      }
 942      /**
 943       * Filters the comments count for display.
 944       *
 945       * @since 1.5.0
 946       *
 947       * @see _n()
 948       *
 949       * @param string $output A translatable string formatted based on whether the count
 950       *                       is equal to 0, 1, or 1+.
 951       * @param int    $number The number of post comments.
 952       */
 953      return apply_filters( 'comments_number', $output, $number );
 954  }
 955  
 956  /**
 957   * Retrieves the text of the current comment.
 958   *
 959   * @since 1.5.0
 960   * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 961   * @since 5.4.0 Added 'In reply to %s.' prefix to child comments in comments feed.
 962   *
 963   * @see Walker_Comment::comment()
 964   *
 965   * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the text.
 966   *                                   Default current comment.
 967   * @param array          $args       Optional. An array of arguments. Default empty array.
 968   * @return string The comment content.
 969   */
 970  function get_comment_text( $comment_ID = 0, $args = array() ) {
 971      $comment = get_comment( $comment_ID );
 972  
 973      $comment_content = $comment->comment_content;
 974  
 975      if ( is_comment_feed() && $comment->comment_parent ) {
 976          $parent = get_comment( $comment->comment_parent );
 977          if ( $parent ) {
 978              $parent_link = esc_url( get_comment_link( $parent ) );
 979              $name        = get_comment_author( $parent );
 980  
 981              $comment_content = sprintf(
 982                  /* translators: %s: Comment link. */
 983                  ent2ncr( __( 'In reply to %s.' ) ),
 984                  '<a href="' . $parent_link . '">' . $name . '</a>'
 985              ) . "\n\n" . $comment_content;
 986          }
 987      }
 988  
 989      /**
 990       * Filters the text of a comment.
 991       *
 992       * @since 1.5.0
 993       *
 994       * @see Walker_Comment::comment()
 995       *
 996       * @param string     $comment_content Text of the comment.
 997       * @param WP_Comment $comment         The comment object.
 998       * @param array      $args            An array of arguments.
 999       */
1000      return apply_filters( 'get_comment_text', $comment_content, $comment, $args );
1001  }
1002  
1003  /**
1004   * Displays the text of the current comment.
1005   *
1006   * @since 0.71
1007   * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
1008   *
1009   * @see Walker_Comment::comment()
1010   *
1011   * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the text.
1012   *                                   Default current comment.
1013   * @param array          $args       Optional. An array of arguments. Default empty array.
1014   */
1015  function comment_text( $comment_ID = 0, $args = array() ) {
1016      $comment = get_comment( $comment_ID );
1017  
1018      $comment_text = get_comment_text( $comment, $args );
1019      /**
1020       * Filters the text of a comment to be displayed.
1021       *
1022       * @since 1.2.0
1023       *
1024       * @see Walker_Comment::comment()
1025       *
1026       * @param string          $comment_text Text of the current comment.
1027       * @param WP_Comment|null $comment      The comment object. Null if not found.
1028       * @param array           $args         An array of arguments.
1029       */
1030      echo apply_filters( 'comment_text', $comment_text, $comment, $args );
1031  }
1032  
1033  /**
1034   * Retrieves the comment time of the current comment.
1035   *
1036   * @since 1.5.0
1037   *
1038   * @param string $format    Optional. PHP time format. Defaults to the 'time_format' option.
1039   * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
1040   * @param bool   $translate Optional. Whether to translate the time (for use in feeds).
1041   *                          Default true.
1042   * @return string The formatted time.
1043   */
1044  function get_comment_time( $format = '', $gmt = false, $translate = true ) {
1045      $comment = get_comment();
1046  
1047      $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
1048  
1049      $_format = ! empty( $format ) ? $format : get_option( 'time_format' );
1050  
1051      $date = mysql2date( $_format, $comment_date, $translate );
1052  
1053      /**
1054       * Filters the returned comment time.
1055       *
1056       * @since 1.5.0
1057       *
1058       * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
1059       * @param string     $format    PHP date format.
1060       * @param bool       $gmt       Whether the GMT date is in use.
1061       * @param bool       $translate Whether the time is translated.
1062       * @param WP_Comment $comment   The comment object.
1063       */
1064      return apply_filters( 'get_comment_time', $date, $format, $gmt, $translate, $comment );
1065  }
1066  
1067  /**
1068   * Displays the comment time of the current comment.
1069   *
1070   * @since 0.71
1071   *
1072   * @param string $format Optional. PHP time format. Defaults to the 'time_format' option.
1073   */
1074  function comment_time( $format = '' ) {
1075      echo get_comment_time( $format );
1076  }
1077  
1078  /**
1079   * Retrieves the comment type of the current comment.
1080   *
1081   * @since 1.5.0
1082   * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
1083   *
1084   * @param int|WP_Comment $comment_ID Optional. WP_Comment or ID of the comment for which to get the type.
1085   *                                   Default current comment.
1086   * @return string The comment type.
1087   */
1088  function get_comment_type( $comment_ID = 0 ) {
1089      $comment = get_comment( $comment_ID );
1090  
1091      if ( '' === $comment->comment_type ) {
1092          $comment->comment_type = 'comment';
1093      }
1094  
1095      /**
1096       * Filters the returned comment type.
1097       *
1098       * @since 1.5.0
1099       * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
1100       *
1101       * @param string     $comment_type The type of comment, such as 'comment', 'pingback', or 'trackback'.
1102       * @param string     $comment_ID   The comment ID as a numeric string.
1103       * @param WP_Comment $comment      The comment object.
1104       */
1105      return apply_filters( 'get_comment_type', $comment->comment_type, $comment->comment_ID, $comment );
1106  }
1107  
1108  /**
1109   * Displays the comment type of the current comment.
1110   *
1111   * @since 0.71
1112   *
1113   * @param string|false $commenttxt   Optional. String to display for comment type. Default false.
1114   * @param string|false $trackbacktxt Optional. String to display for trackback type. Default false.
1115   * @param string|false $pingbacktxt  Optional. String to display for pingback type. Default false.
1116   */
1117  function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) {
1118      if ( false === $commenttxt ) {
1119          $commenttxt = _x( 'Comment', 'noun' );
1120      }
1121      if ( false === $trackbacktxt ) {
1122          $trackbacktxt = __( 'Trackback' );
1123      }
1124      if ( false === $pingbacktxt ) {
1125          $pingbacktxt = __( 'Pingback' );
1126      }
1127      $type = get_comment_type();
1128      switch ( $type ) {
1129          case 'trackback':
1130              echo $trackbacktxt;
1131              break;
1132          case 'pingback':
1133              echo $pingbacktxt;
1134              break;
1135          default:
1136              echo $commenttxt;
1137      }
1138  }
1139  
1140  /**
1141   * Retrieves the current post's trackback URL.
1142   *
1143   * There is a check to see if permalink's have been enabled and if so, will
1144   * retrieve the pretty path. If permalinks weren't enabled, the ID of the
1145   * current post is used and appended to the correct page to go to.
1146   *
1147   * @since 1.5.0
1148   *
1149   * @return string The trackback URL after being filtered.
1150   */
1151  function get_trackback_url() {
1152      if ( get_option( 'permalink_structure' ) ) {
1153          $tb_url = trailingslashit( get_permalink() ) . user_trailingslashit( 'trackback', 'single_trackback' );
1154      } else {
1155          $tb_url = get_option( 'siteurl' ) . '/wp-trackback.php?p=' . get_the_ID();
1156      }
1157  
1158      /**
1159       * Filters the returned trackback URL.
1160       *
1161       * @since 2.2.0
1162       *
1163       * @param string $tb_url The trackback URL.
1164       */
1165      return apply_filters( 'trackback_url', $tb_url );
1166  }
1167  
1168  /**
1169   * Displays the current post's trackback URL.
1170   *
1171   * @since 0.71
1172   *
1173   * @param bool $deprecated_echo Not used.
1174   * @return void|string Should only be used to echo the trackback URL, use get_trackback_url()
1175   *                     for the result instead.
1176   */
1177  function trackback_url( $deprecated_echo = true ) {
1178      if ( true !== $deprecated_echo ) {
1179          _deprecated_argument(
1180              __FUNCTION__,
1181              '2.5.0',
1182              sprintf(
1183                  /* translators: %s: get_trackback_url() */
1184                  __( 'Use %s instead if you do not want the value echoed.' ),
1185                  '<code>get_trackback_url()</code>'
1186              )
1187          );
1188      }
1189  
1190      if ( $deprecated_echo ) {
1191          echo get_trackback_url();
1192      } else {
1193          return get_trackback_url();
1194      }
1195  }
1196  
1197  /**
1198   * Generates and displays the RDF for the trackback information of current post.
1199   *
1200   * Deprecated in 3.0.0, and restored in 3.0.1.
1201   *
1202   * @since 0.71
1203   *
1204   * @param int|string $deprecated Not used (Was $timezone = 0).
1205   */
1206  function trackback_rdf( $deprecated = '' ) {
1207      if ( ! empty( $deprecated ) ) {
1208          _deprecated_argument( __FUNCTION__, '2.5.0' );
1209      }
1210  
1211      if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && false !== stripos( $_SERVER['HTTP_USER_AGENT'], 'W3C_Validator' ) ) {
1212          return;
1213      }
1214  
1215      echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
1216              xmlns:dc="http://purl.org/dc/elements/1.1/"
1217              xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
1218          <rdf:Description rdf:about="';
1219      the_permalink();
1220      echo '"' . "\n";
1221      echo '    dc:identifier="';
1222      the_permalink();
1223      echo '"' . "\n";
1224      echo '    dc:title="' . str_replace( '--', '&#x2d;&#x2d;', wptexturize( strip_tags( get_the_title() ) ) ) . '"' . "\n";
1225      echo '    trackback:ping="' . get_trackback_url() . '"' . " />\n";
1226      echo '</rdf:RDF>';
1227  }
1228  
1229  /**
1230   * Determines whether the current post is open for comments.
1231   *
1232   * For more information on this and similar theme functions, check out
1233   * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
1234   * Conditional Tags} article in the Theme Developer Handbook.
1235   *
1236   * @since 1.5.0
1237   *
1238   * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
1239   * @return bool True if the comments are open.
1240   */
1241  function comments_open( $post_id = null ) {
1242  
1243      $_post = get_post( $post_id );
1244  
1245      $post_id = $_post ? $_post->ID : 0;
1246      $open    = ( $_post && ( 'open' === $_post->comment_status ) );
1247  
1248      /**
1249       * Filters whether the current post is open for comments.
1250       *
1251       * @since 2.5.0
1252       *
1253       * @param bool $open    Whether the current post is open for comments.
1254       * @param int  $post_id The post ID.
1255       */
1256      return apply_filters( 'comments_open', $open, $post_id );
1257  }
1258  
1259  /**
1260   * Determines whether the current post is open for pings.
1261   *
1262   * For more information on this and similar theme functions, check out
1263   * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
1264   * Conditional Tags} article in the Theme Developer Handbook.
1265   *
1266   * @since 1.5.0
1267   *
1268   * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
1269   * @return bool True if pings are accepted
1270   */
1271  function pings_open( $post_id = null ) {
1272  
1273      $_post = get_post( $post_id );
1274  
1275      $post_id = $_post ? $_post->ID : 0;
1276      $open    = ( $_post && ( 'open' === $_post->ping_status ) );
1277  
1278      /**
1279       * Filters whether the current post is open for pings.
1280       *
1281       * @since 2.5.0
1282       *
1283       * @param bool $open    Whether the current post is open for pings.
1284       * @param int  $post_id The post ID.
1285       */
1286      return apply_filters( 'pings_open', $open, $post_id );
1287  }
1288  
1289  /**
1290   * Displays form token for unfiltered comments.
1291   *
1292   * Will only display nonce token if the current user has permissions for
1293   * unfiltered html. Won't display the token for other users.
1294   *
1295   * The function was backported to 2.0.10 and was added to versions 2.1.3 and
1296   * above. Does not exist in versions prior to 2.0.10 in the 2.0 branch and in
1297   * the 2.1 branch, prior to 2.1.3. Technically added in 2.2.0.
1298   *
1299   * Backported to 2.0.10.
1300   *
1301   * @since 2.1.3
1302   */
1303  function wp_comment_form_unfiltered_html_nonce() {
1304      $post    = get_post();
1305      $post_id = $post ? $post->ID : 0;
1306  
1307      if ( current_user_can( 'unfiltered_html' ) ) {
1308          wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false );
1309          echo "<script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>\n";
1310      }
1311  }
1312  
1313  /**
1314   * Loads the comment template specified in $file.
1315   *
1316   * Will not display the comments template if not on single post or page, or if
1317   * the post does not have comments.
1318   *
1319   * Uses the WordPress database object to query for the comments. The comments
1320   * are passed through the {@see 'comments_array'} filter hook with the list of comments
1321   * and the post ID respectively.
1322   *
1323   * The `$file` path is passed through a filter hook called {@see 'comments_template'},
1324   * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path
1325   * first and if it fails it will require the default comment template from the
1326   * default theme. If either does not exist, then the WordPress process will be
1327   * halted. It is advised for that reason, that the default theme is not deleted.
1328   *
1329   * Will not try to get the comments if the post has none.
1330   *
1331   * @since 1.5.0
1332   *
1333   * @global WP_Query   $wp_query         WordPress Query object.
1334   * @global WP_Post    $post             Global post object.
1335   * @global wpdb       $wpdb             WordPress database abstraction object.
1336   * @global int        $id
1337   * @global WP_Comment $comment          Global comment object.
1338   * @global string     $user_login
1339   * @global string     $user_identity
1340   * @global bool       $overridden_cpage
1341   * @global bool       $withcomments
1342   *
1343   * @param string $file              Optional. The file to load. Default '/comments.php'.
1344   * @param bool   $separate_comments Optional. Whether to separate the comments by comment type.
1345   *                                  Default false.
1346   */
1347  function comments_template( $file = '/comments.php', $separate_comments = false ) {
1348      global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage;
1349  
1350      if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) {
1351          return;
1352      }
1353  
1354      if ( empty( $file ) ) {
1355          $file = '/comments.php';
1356      }
1357  
1358      $req = get_option( 'require_name_email' );
1359  
1360      /*
1361       * Comment author information fetched from the comment cookies.
1362       */
1363      $commenter = wp_get_current_commenter();
1364  
1365      /*
1366       * The name of the current comment author escaped for use in attributes.
1367       * Escaped by sanitize_comment_cookies().
1368       */
1369      $comment_author = $commenter['comment_author'];
1370  
1371      /*
1372       * The email address of the current comment author escaped for use in attributes.
1373       * Escaped by sanitize_comment_cookies().
1374       */
1375      $comment_author_email = $commenter['comment_author_email'];
1376  
1377      /*
1378       * The URL of the current comment author escaped for use in attributes.
1379       */
1380      $comment_author_url = esc_url( $commenter['comment_author_url'] );
1381  
1382      $comment_args = array(
1383          'orderby'                   => 'comment_date_gmt',
1384          'order'                     => 'ASC',
1385          'status'                    => 'approve',
1386          'post_id'                   => $post->ID,
1387          'no_found_rows'             => false,
1388          'update_comment_meta_cache' => false, // We lazy-load comment meta for performance.
1389      );
1390  
1391      if ( get_option( 'thread_comments' ) ) {
1392          $comment_args['hierarchical'] = 'threaded';
1393      } else {
1394          $comment_args['hierarchical'] = false;
1395      }
1396  
1397      if ( is_user_logged_in() ) {
1398          $comment_args['include_unapproved'] = array( get_current_user_id() );
1399      } else {
1400          $unapproved_email = wp_get_unapproved_comment_author_email();
1401  
1402          if ( $unapproved_email ) {
1403              $comment_args['include_unapproved'] = array( $unapproved_email );
1404          }
1405      }
1406  
1407      $per_page = 0;
1408      if ( get_option( 'page_comments' ) ) {
1409          $per_page = (int) get_query_var( 'comments_per_page' );
1410          if ( 0 === $per_page ) {
1411              $per_page = (int) get_option( 'comments_per_page' );
1412          }
1413  
1414          $comment_args['number'] = $per_page;
1415          $page                   = (int) get_query_var( 'cpage' );
1416  
1417          if ( $page ) {
1418              $comment_args['offset'] = ( $page - 1 ) * $per_page;
1419          } elseif ( 'oldest' === get_option( 'default_comments_page' ) ) {
1420              $comment_args['offset'] = 0;
1421          } else {
1422              // If fetching the first page of 'newest', we need a top-level comment count.
1423              $top_level_query = new WP_Comment_Query();
1424              $top_level_args  = array(
1425                  'count'   => true,
1426                  'orderby' => false,
1427                  'post_id' => $post->ID,
1428                  'status'  => 'approve',
1429              );
1430  
1431              if ( $comment_args['hierarchical'] ) {
1432                  $top_level_args['parent'] = 0;
1433              }
1434  
1435              if ( isset( $comment_args['include_unapproved'] ) ) {
1436                  $top_level_args['include_unapproved'] = $comment_args['include_unapproved'];
1437              }
1438  
1439              /**
1440               * Filters the arguments used in the top level comments query.
1441               *
1442               * @since 5.6.0
1443               *
1444               * @see WP_Comment_Query::__construct()
1445               *
1446               * @param array $top_level_args {
1447               *     The top level query arguments for the comments template.
1448               *
1449               *     @type bool         $count   Whether to return a comment count.
1450               *     @type string|array $orderby The field(s) to order by.
1451               *     @type int          $post_id The post ID.
1452               *     @type string|array $status  The comment status to limit results by.
1453               * }
1454               */
1455              $top_level_args = apply_filters( 'comments_template_top_level_query_args', $top_level_args );
1456  
1457              $top_level_count = $top_level_query->query( $top_level_args );
1458  
1459              $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
1460          }
1461      }
1462  
1463      /**
1464       * Filters the arguments used to query comments in comments_template().
1465       *
1466       * @since 4.5.0
1467       *
1468       * @see WP_Comment_Query::__construct()
1469       *
1470       * @param array $comment_args {
1471       *     Array of WP_Comment_Query arguments.
1472       *
1473       *     @type string|array $orderby                   Field(s) to order by.
1474       *     @type string       $order                     Order of results. Accepts 'ASC' or 'DESC'.
1475       *     @type string       $status                    Comment status.
1476       *     @type array        $include_unapproved        Array of IDs or email addresses whose unapproved comments
1477       *                                                   will be included in results.
1478       *     @type int          $post_id                   ID of the post.
1479       *     @type bool         $no_found_rows             Whether to refrain from querying for found rows.
1480       *     @type bool         $update_comment_meta_cache Whether to prime cache for comment meta.
1481       *     @type bool|string  $hierarchical              Whether to query for comments hierarchically.
1482       *     @type int          $offset                    Comment offset.
1483       *     @type int          $number                    Number of comments to fetch.
1484       * }
1485       */
1486      $comment_args = apply_filters( 'comments_template_query_args', $comment_args );
1487  
1488      $comment_query = new WP_Comment_Query( $comment_args );
1489      $_comments     = $comment_query->comments;
1490  
1491      // Trees must be flattened before they're passed to the walker.
1492      if ( $comment_args['hierarchical'] ) {
1493          $comments_flat = array();
1494          foreach ( $_comments as $_comment ) {
1495              $comments_flat[]  = $_comment;
1496              $comment_children = $_comment->get_children(
1497                  array(
1498                      'format'  => 'flat',
1499                      'status'  => $comment_args['status'],
1500                      'orderby' => $comment_args['orderby'],
1501                  )
1502              );
1503  
1504              foreach ( $comment_children as $comment_child ) {
1505                  $comments_flat[] = $comment_child;
1506              }
1507          }
1508      } else {
1509          $comments_flat = $_comments;
1510      }
1511  
1512      /**
1513       * Filters the comments array.
1514       *
1515       * @since 2.1.0
1516       *
1517       * @param array $comments Array of comments supplied to the comments template.
1518       * @param int   $post_ID  Post ID.
1519       */
1520      $wp_query->comments = apply_filters( 'comments_array', $comments_flat, $post->ID );
1521  
1522      $comments                        = &$wp_query->comments;
1523      $wp_query->comment_count         = count( $wp_query->comments );
1524      $wp_query->max_num_comment_pages = $comment_query->max_num_pages;
1525  
1526      if ( $separate_comments ) {
1527          $wp_query->comments_by_type = separate_comments( $comments );
1528          $comments_by_type           = &$wp_query->comments_by_type;
1529      } else {
1530          $wp_query->comments_by_type = array();
1531      }
1532  
1533      $overridden_cpage = false;
1534  
1535      if ( '' == get_query_var( 'cpage' ) && $wp_query->max_num_comment_pages > 1 ) {
1536          set_query_var( 'cpage', 'newest' === get_option( 'default_comments_page' ) ? get_comment_pages_count() : 1 );
1537          $overridden_cpage = true;
1538      }
1539  
1540      if ( ! defined( 'COMMENTS_TEMPLATE' ) ) {
1541          define( 'COMMENTS_TEMPLATE', true );
1542      }
1543  
1544      $theme_template = STYLESHEETPATH . $file;
1545  
1546      /**
1547       * Filters the path to the theme template file used for the comments template.
1548       *
1549       * @since 1.5.1
1550       *
1551       * @param string $theme_template The path to the theme template file.
1552       */
1553      $include = apply_filters( 'comments_template', $theme_template );
1554  
1555      if ( file_exists( $include ) ) {
1556          require $include;
1557      } elseif ( file_exists( TEMPLATEPATH . $file ) ) {
1558          require TEMPLATEPATH . $file;
1559      } else { // Backward compat code will be removed in a future release.
1560          require  ABSPATH . WPINC . '/theme-compat/comments.php';
1561      }
1562  }
1563  
1564  /**
1565   * Displays the link to the comments for the current post ID.
1566   *
1567   * @since 0.71
1568   *
1569   * @param false|string $zero      Optional. String to display when no comments. Default false.
1570   * @param false|string $one       Optional. String to display when only one comment is available. Default false.
1571   * @param false|string $more      Optional. String to display when there are more than one comment. Default false.
1572   * @param string       $css_class Optional. CSS class to use for comments. Default empty.
1573   * @param false|string $none      Optional. String to display when comments have been turned off. Default false.
1574   */
1575  function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
1576      $post_id    = get_the_ID();
1577      $post_title = get_the_title();
1578      $number     = get_comments_number( $post_id );
1579  
1580      if ( false === $zero ) {
1581          /* translators: %s: Post title. */
1582          $zero = sprintf( __( 'No Comments<span class="screen-reader-text"> on %s</span>' ), $post_title );
1583      }
1584  
1585      if ( false === $one ) {
1586          /* translators: %s: Post title. */
1587          $one = sprintf( __( '1 Comment<span class="screen-reader-text"> on %s</span>' ), $post_title );
1588      }
1589  
1590      if ( false === $more ) {
1591          /* translators: 1: Number of comments, 2: Post title. */
1592          $more = _n( '%1$s Comment<span class="screen-reader-text"> on %2$s</span>', '%1$s Comments<span class="screen-reader-text"> on %2$s</span>', $number );
1593          $more = sprintf( $more, number_format_i18n( $number ), $post_title );
1594      }
1595  
1596      if ( false === $none ) {
1597          /* translators: %s: Post title. */
1598          $none = sprintf( __( 'Comments Off<span class="screen-reader-text"> on %s</span>' ), $post_title );
1599      }
1600  
1601      if ( 0 == $number && ! comments_open() && ! pings_open() ) {
1602          echo '<span' . ( ( ! empty( $css_class ) ) ? ' class="' . esc_attr( $css_class ) . '"' : '' ) . '>' . $none . '</span>';
1603          return;
1604      }
1605  
1606      if ( post_password_required() ) {
1607          _e( 'Enter your password to view comments.' );
1608          return;
1609      }
1610  
1611      echo '<a href="';
1612      if ( 0 == $number ) {
1613          $respond_link = get_permalink() . '#respond';
1614          /**
1615           * Filters the respond link when a post has no comments.
1616           *
1617           * @since 4.4.0
1618           *
1619           * @param string $respond_link The default response link.
1620           * @param int    $post_id      The post ID.
1621           */
1622          echo apply_filters( 'respond_link', $respond_link, $post_id );
1623      } else {
1624          comments_link();
1625      }
1626      echo '"';
1627  
1628      if ( ! empty( $css_class ) ) {
1629          echo ' class="' . $css_class . '" ';
1630      }
1631  
1632      $attributes = '';
1633      /**
1634       * Filters the comments link attributes for display.
1635       *
1636       * @since 2.5.0
1637       *
1638       * @param string $attributes The comments link attributes. Default empty.
1639       */
1640      echo apply_filters( 'comments_popup_link_attributes', $attributes );
1641  
1642      echo '>';
1643      comments_number( $zero, $one, $more );
1644      echo '</a>';
1645  }
1646  
1647  /**
1648   * Retrieves HTML content for reply to comment link.
1649   *
1650   * @since 2.7.0
1651   * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object.
1652   *
1653   * @param array          $args {
1654   *     Optional. Override default arguments.
1655   *
1656   *     @type string $add_below  The first part of the selector used to identify the comment to respond below.
1657   *                              The resulting value is passed as the first parameter to addComment.moveForm(),
1658   *                              concatenated as $add_below-$comment->comment_ID. Default 'comment'.
1659   *     @type string $respond_id The selector identifying the responding comment. Passed as the third parameter
1660   *                              to addComment.moveForm(), and appended to the link URL as a hash value.
1661   *                              Default 'respond'.
1662   *     @type string $reply_text The text of the Reply link. Default 'Reply'.
1663   *     @type string $login_text The text of the link to reply if logged out. Default 'Log in to Reply'.
1664   *     @type int    $max_depth  The max depth of the comment tree. Default 0.
1665   *     @type int    $depth      The depth of the new comment. Must be greater than 0 and less than the value
1666   *                              of the 'thread_comments_depth' option set in Settings > Discussion. Default 0.
1667   *     @type string $before     The text or HTML to add before the reply link. Default empty.
1668   *     @type string $after      The text or HTML to add after the reply link. Default empty.
1669   * }
1670   * @param int|WP_Comment $comment Comment being replied to. Default current comment.
1671   * @param int|WP_Post    $post    Post ID or WP_Post object the comment is going to be displayed on.
1672   *                                Default current post.
1673   * @return string|false|null Link to show comment form, if successful. False, if comments are closed.
1674   */
1675  function get_comment_reply_link( $args = array(), $comment = null, $post = null ) {
1676      $defaults = array(
1677          'add_below'     => 'comment',
1678          'respond_id'    => 'respond',
1679          'reply_text'    => __( 'Reply' ),
1680          /* translators: Comment reply button text. %s: Comment author name. */
1681          'reply_to_text' => __( 'Reply to %s' ),
1682          'login_text'    => __( 'Log in to Reply' ),
1683          'max_depth'     => 0,
1684          'depth'         => 0,
1685          'before'        => '',
1686          'after'         => '',
1687      );
1688  
1689      $args = wp_parse_args( $args, $defaults );
1690  
1691      if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) {
1692          return;
1693      }
1694  
1695      $comment = get_comment( $comment );
1696  
1697      if ( empty( $comment ) ) {
1698          return;
1699      }
1700  
1701      if ( empty( $post ) ) {
1702          $post = $comment->comment_post_ID;
1703      }
1704  
1705      $post = get_post( $post );
1706  
1707      if ( ! comments_open( $post->ID ) ) {
1708          return false;
1709      }
1710  
1711      if ( get_option( 'page_comments' ) ) {
1712          $permalink = str_replace( '#comment-' . $comment->comment_ID, '', get_comment_link( $comment ) );
1713      } else {
1714          $permalink = get_permalink( $post->ID );
1715      }
1716  
1717      /**
1718       * Filters the comment reply link arguments.
1719       *
1720       * @since 4.1.0
1721       *
1722       * @param array      $args    Comment reply link arguments. See get_comment_reply_link()
1723       *                            for more information on accepted arguments.
1724       * @param WP_Comment $comment The object of the comment being replied to.
1725       * @param WP_Post    $post    The WP_Post object.
1726       */
1727      $args = apply_filters( 'comment_reply_link_args', $args, $comment, $post );
1728  
1729      if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
1730          $link = sprintf(
1731              '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',
1732              esc_url( wp_login_url( get_permalink() ) ),
1733              $args['login_text']
1734          );
1735      } else {
1736          $data_attributes = array(
1737              'commentid'      => $comment->comment_ID,
1738              'postid'         => $post->ID,
1739              'belowelement'   => $args['add_below'] . '-' . $comment->comment_ID,
1740              'respondelement' => $args['respond_id'],
1741              'replyto'        => sprintf( $args['reply_to_text'], get_comment_author( $comment ) ),
1742          );
1743  
1744          $data_attribute_string = '';
1745  
1746          foreach ( $data_attributes as $name => $value ) {
1747              $data_attribute_string .= " data-$name}=\"" . esc_attr( $value ) . '"';
1748          }
1749  
1750          $data_attribute_string = trim( $data_attribute_string );
1751  
1752          $link = sprintf(
1753              "<a rel='nofollow' class='comment-reply-link' href='%s' %s aria-label='%s'>%s</a>",
1754              esc_url(
1755                  add_query_arg(
1756                      array(
1757                          'replytocom'      => $comment->comment_ID,
1758                          'unapproved'      => false,
1759                          'moderation-hash' => false,
1760                      ),
1761                      $permalink
1762                  )
1763              ) . '#' . $args['respond_id'],
1764              $data_attribute_string,
1765              esc_attr( sprintf( $args['reply_to_text'], get_comment_author( $comment ) ) ),
1766              $args['reply_text']
1767          );
1768      }
1769  
1770      /**
1771       * Filters the comment reply link.
1772       *
1773       * @since 2.7.0
1774       *
1775       * @param string     $link    The HTML markup for the comment reply link.
1776       * @param array      $args    An array of arguments overriding the defaults.
1777       * @param WP_Comment $comment The object of the comment being replied.
1778       * @param WP_Post    $post    The WP_Post object.
1779       */
1780      return apply_filters( 'comment_reply_link', $args['before'] . $link . $args['after'], $args, $comment, $post );
1781  }
1782  
1783  /**
1784   * Displays the HTML content for reply to comment link.
1785   *
1786   * @since 2.7.0
1787   *
1788   * @see get_comment_reply_link()
1789   *
1790   * @param array          $args    Optional. Override default options. Default empty array.
1791   * @param int|WP_Comment $comment Comment being replied to. Default current comment.
1792   * @param int|WP_Post    $post    Post ID or WP_Post object the comment is going to be displayed on.
1793   *                                Default current post.
1794   */
1795  function comment_reply_link( $args = array(), $comment = null, $post = null ) {
1796      echo get_comment_reply_link( $args, $comment, $post );
1797  }
1798  
1799  /**
1800   * Retrieves HTML content for reply to post link.
1801   *
1802   * @since 2.7.0
1803   *
1804   * @param array       $args {
1805   *     Optional. Override default arguments.
1806   *
1807   *     @type string $add_below  The first part of the selector used to identify the comment to respond below.
1808   *                              The resulting value is passed as the first parameter to addComment.moveForm(),
1809   *                              concatenated as $add_below-$comment->comment_ID. Default is 'post'.
1810   *     @type string $respond_id The selector identifying the responding comment. Passed as the third parameter
1811   *                              to addComment.moveForm(), and appended to the link URL as a hash value.
1812   *                              Default 'respond'.
1813   *     @type string $reply_text Text of the Reply link. Default is 'Leave a Comment'.
1814   *     @type string $login_text Text of the link to reply if logged out. Default is 'Log in to leave a Comment'.
1815   *     @type string $before     Text or HTML to add before the reply link. Default empty.
1816   *     @type string $after      Text or HTML to add after the reply link. Default empty.
1817   * }
1818   * @param int|WP_Post $post    Optional. Post ID or WP_Post object the comment is going to be displayed on.
1819   *                             Default current post.
1820   * @return string|false|null Link to show comment form, if successful. False, if comments are closed.
1821   */
1822  function get_post_reply_link( $args = array(), $post = null ) {
1823      $defaults = array(
1824          'add_below'  => 'post',
1825          'respond_id' => 'respond',
1826          'reply_text' => __( 'Leave a Comment' ),
1827          'login_text' => __( 'Log in to leave a Comment' ),
1828          'before'     => '',
1829          'after'      => '',
1830      );
1831  
1832      $args = wp_parse_args( $args, $defaults );
1833  
1834      $post = get_post( $post );
1835  
1836      if ( ! comments_open( $post->ID ) ) {
1837          return false;
1838      }
1839  
1840      if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
1841          $link = sprintf(
1842              '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',
1843              wp_login_url( get_permalink() ),
1844              $args['login_text']
1845          );
1846      } else {
1847          $onclick = sprintf(
1848              'return addComment.moveForm( "%1$s-%2$s", "0", "%3$s", "%2$s" )',
1849              $args['add_below'],
1850              $post->ID,
1851              $args['respond_id']
1852          );
1853  
1854          $link = sprintf(
1855              "<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s'>%s</a>",
1856              get_permalink( $post->ID ) . '#' . $args['respond_id'],
1857              $onclick,
1858              $args['reply_text']
1859          );
1860      }
1861      $formatted_link = $args['before'] . $link . $args['after'];
1862  
1863      /**
1864       * Filters the formatted post comments link HTML.
1865       *
1866       * @since 2.7.0
1867       *
1868       * @param string      $formatted The HTML-formatted post comments link.
1869       * @param int|WP_Post $post      The post ID or WP_Post object.
1870       */
1871      return apply_filters( 'post_comments_link', $formatted_link, $post );
1872  }
1873  
1874  /**
1875   * Displays the HTML content for reply to post link.
1876   *
1877   * @since 2.7.0
1878   *
1879   * @see get_post_reply_link()
1880   *
1881   * @param array       $args Optional. Override default options. Default empty array.
1882   * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
1883   *                          Default current post.
1884   */
1885  function post_reply_link( $args = array(), $post = null ) {
1886      echo get_post_reply_link( $args, $post );
1887  }
1888  
1889  /**
1890   * Retrieves HTML content for cancel comment reply link.
1891   *
1892   * @since 2.7.0
1893   *
1894   * @param string $text Optional. Text to display for cancel reply link. If empty,
1895   *                     defaults to 'Click here to cancel reply'. Default empty.
1896   * @return string
1897   */
1898  function get_cancel_comment_reply_link( $text = '' ) {
1899      if ( empty( $text ) ) {
1900          $text = __( 'Click here to cancel reply.' );
1901      }
1902  
1903      $style = isset( $_GET['replytocom'] ) ? '' : ' style="display:none;"';
1904      $link  = esc_html( remove_query_arg( array( 'replytocom', 'unapproved', 'moderation-hash' ) ) ) . '#respond';
1905  
1906      $formatted_link = '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>';
1907  
1908      /**
1909       * Filters the cancel comment reply link HTML.
1910       *
1911       * @since 2.7.0
1912       *
1913       * @param string $formatted_link The HTML-formatted cancel comment reply link.
1914       * @param string $link           Cancel comment reply link URL.
1915       * @param string $text           Cancel comment reply link text.
1916       */
1917      return apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text );
1918  }
1919  
1920  /**
1921   * Displays HTML content for cancel comment reply link.
1922   *
1923   * @since 2.7.0
1924   *
1925   * @param string $text Optional. Text to display for cancel reply link. If empty,
1926   *                     defaults to 'Click here to cancel reply'. Default empty.
1927   */
1928  function cancel_comment_reply_link( $text = '' ) {
1929      echo get_cancel_comment_reply_link( $text );
1930  }
1931  
1932  /**
1933   * Retrieves hidden input HTML for replying to comments.
1934   *
1935   * @since 3.0.0
1936   *
1937   * @param int $post_id Optional. Post ID. Defaults to the current post ID.
1938   * @return string Hidden input HTML for replying to comments.
1939   */
1940  function get_comment_id_fields( $post_id = 0 ) {
1941      if ( empty( $post_id ) ) {
1942          $post_id = get_the_ID();
1943      }
1944  
1945      $reply_to_id = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0;
1946      $result      = "<input type='hidden' name='comment_post_ID' value='$post_id' id='comment_post_ID' />\n";
1947      $result     .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$reply_to_id' />\n";
1948  
1949      /**
1950       * Filters the returned comment ID fields.
1951       *
1952       * @since 3.0.0
1953       *
1954       * @param string $result      The HTML-formatted hidden ID field comment elements.
1955       * @param int    $post_id     The post ID.
1956       * @param int    $reply_to_id The ID of the comment being replied to.
1957       */
1958      return apply_filters( 'comment_id_fields', $result, $post_id, $reply_to_id );
1959  }
1960  
1961  /**
1962   * Outputs hidden input HTML for replying to comments.
1963   *
1964   * Adds two hidden inputs to the comment form to identify the `comment_post_ID`
1965   * and `comment_parent` values for threaded comments.
1966   *
1967   * This tag must be within the `<form>` section of the `comments.php` template.
1968   *
1969   * @since 2.7.0
1970   *
1971   * @see get_comment_id_fields()
1972   *
1973   * @param int $post_id Optional. Post ID. Defaults to the current post ID.
1974   */
1975  function comment_id_fields( $post_id = 0 ) {
1976      echo get_comment_id_fields( $post_id );
1977  }
1978  
1979  /**
1980   * Displays text based on comment reply status.
1981   *
1982   * Only affects users with JavaScript disabled.
1983   *
1984   * @internal The $comment global must be present to allow template tags access to the current
1985   *           comment. See https://core.trac.wordpress.org/changeset/36512.
1986   *
1987   * @since 2.7.0
1988   *
1989   * @global WP_Comment $comment Global comment object.
1990   *
1991   * @param string|false $no_reply_text  Optional. Text to display when not replying to a comment.
1992   *                                     Default false.
1993   * @param string|false $reply_text     Optional. Text to display when replying to a comment.
1994   *                                     Default false. Accepts "%s" for the author of the comment
1995   *                                     being replied to.
1996   * @param bool         $link_to_parent Optional. Boolean to control making the author's name a link
1997   *                                     to their comment. Default true.
1998   */
1999  function comment_form_title( $no_reply_text = false, $reply_text = false, $link_to_parent = true ) {
2000      global $comment;
2001  
2002      if ( false === $no_reply_text ) {
2003          $no_reply_text = __( 'Leave a Reply' );
2004      }
2005  
2006      if ( false === $reply_text ) {
2007          /* translators: %s: Author of the comment being replied to. */
2008          $reply_text = __( 'Leave a Reply to %s' );
2009      }
2010  
2011      $reply_to_id = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0;
2012  
2013      if ( 0 == $reply_to_id ) {
2014          echo $no_reply_text;
2015      } else {
2016          // Sets the global so that template tags can be used in the comment form.
2017          $comment = get_comment( $reply_to_id );
2018  
2019          if ( $link_to_parent ) {
2020              $author = '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $comment ) . '</a>';
2021          } else {
2022              $author = get_comment_author( $comment );
2023          }
2024  
2025          printf( $reply_text, $author );
2026      }
2027  }
2028  
2029  /**
2030   * Displays a list of comments.
2031   *
2032   * Used in the comments.php template to list comments for a particular post.
2033   *
2034   * @since 2.7.0
2035   *
2036   * @see WP_Query->comments
2037   *
2038   * @global WP_Query $wp_query           WordPress Query object.
2039   * @global int      $comment_alt
2040   * @global int      $comment_depth
2041   * @global int      $comment_thread_alt
2042   * @global bool     $overridden_cpage
2043   * @global bool     $in_comment_loop
2044   *
2045   * @param string|array $args {
2046   *     Optional. Formatting options.
2047   *
2048   *     @type object   $walker            Instance of a Walker class to list comments. Default null.
2049   *     @type int      $max_depth         The maximum comments depth. Default empty.
2050   *     @type string   $style             The style of list ordering. Accepts 'ul', 'ol', or 'div'.
2051   *                                       'div' will result in no additional list markup. Default 'ul'.
2052   *     @type callable $callback          Callback function to use. Default null.
2053   *     @type callable $end-callback      Callback function to use at the end. Default null.
2054   *     @type string   $type              Type of comments to list. Accepts 'all', 'comment',
2055   *                                       'pingback', 'trackback', 'pings'. Default 'all'.
2056   *     @type int      $page              Page ID to list comments for. Default empty.
2057   *     @type int      $per_page          Number of comments to list per page. Default empty.
2058   *     @type int      $avatar_size       Height and width dimensions of the avatar size. Default 32.
2059   *     @type bool     $reverse_top_level Ordering of the listed comments. If true, will display
2060   *                                       newest comments first. Default null.
2061   *     @type bool     $reverse_children  Whether to reverse child comments in the list. Default null.
2062   *     @type string   $format            How to format the comments list. Accepts 'html5', 'xhtml'.
2063   *                                       Default 'html5' if the theme supports it.
2064   *     @type bool     $short_ping        Whether to output short pings. Default false.
2065   *     @type bool     $echo              Whether to echo the output or return it. Default true.
2066   * }
2067   * @param WP_Comment[] $comments Optional. Array of WP_Comment objects.
2068   * @return void|string Void if 'echo' argument is true, or no comments to list.
2069   *                     Otherwise, HTML list of comments.
2070   */
2071  function wp_list_comments( $args = array(), $comments = null ) {
2072      global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
2073  
2074      $in_comment_loop = true;
2075  
2076      $comment_alt        = 0;
2077      $comment_thread_alt = 0;
2078      $comment_depth      = 1;
2079  
2080      $defaults = array(
2081          'walker'            => null,
2082          'max_depth'         => '',
2083          'style'             => 'ul',
2084          'callback'          => null,
2085          'end-callback'      => null,
2086          'type'              => 'all',
2087          'page'              => '',
2088          'per_page'          => '',
2089          'avatar_size'       => 32,
2090          'reverse_top_level' => null,
2091          'reverse_children'  => '',
2092          'format'            => current_theme_supports( 'html5', 'comment-list' ) ? 'html5' : 'xhtml',
2093          'short_ping'        => false,
2094          'echo'              => true,
2095      );
2096  
2097      $parsed_args = wp_parse_args( $args, $defaults );
2098  
2099      /**
2100       * Filters the arguments used in retrieving the comment list.
2101       *
2102       * @since 4.0.0
2103       *
2104       * @see wp_list_comments()
2105       *
2106       * @param array $parsed_args An array of arguments for displaying comments.
2107       */
2108      $parsed_args = apply_filters( 'wp_list_comments_args', $parsed_args );
2109  
2110      // Figure out what comments we'll be looping through ($_comments).
2111      if ( null !== $comments ) {
2112          $comments = (array) $comments;
2113          if ( empty( $comments ) ) {
2114              return;
2115          }
2116          if ( 'all' !== $parsed_args['type'] ) {
2117              $comments_by_type = separate_comments( $comments );
2118              if ( empty( $comments_by_type[ $parsed_args['type'] ] ) ) {
2119                  return;
2120              }
2121              $_comments = $comments_by_type[ $parsed_args['type'] ];
2122          } else {
2123              $_comments = $comments;
2124          }
2125      } else {
2126          /*
2127           * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query,
2128           * perform a separate comment query and allow Walker_Comment to paginate.
2129           */
2130          if ( $parsed_args['page'] || $parsed_args['per_page'] ) {
2131              $current_cpage = get_query_var( 'cpage' );
2132              if ( ! $current_cpage ) {
2133                  $current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages;
2134              }
2135  
2136              $current_per_page = get_query_var( 'comments_per_page' );
2137              if ( $parsed_args['page'] != $current_cpage || $parsed_args['per_page'] != $current_per_page ) {
2138                  $comment_args = array(
2139                      'post_id' => get_the_ID(),
2140                      'orderby' => 'comment_date_gmt',
2141                      'order'   => 'ASC',
2142                      'status'  => 'approve',
2143                  );
2144  
2145                  if ( is_user_logged_in() ) {
2146                      $comment_args['include_unapproved'] = array( get_current_user_id() );
2147                  } else {
2148                      $unapproved_email = wp_get_unapproved_comment_author_email();
2149  
2150                      if ( $unapproved_email ) {
2151                          $comment_args['include_unapproved'] = array( $unapproved_email );
2152                      }
2153                  }
2154  
2155                  $comments = get_comments( $comment_args );
2156  
2157                  if ( 'all' !== $parsed_args['type'] ) {
2158                      $comments_by_type = separate_comments( $comments );
2159                      if ( empty( $comments_by_type[ $parsed_args['type'] ] ) ) {
2160                          return;
2161                      }
2162  
2163                      $_comments = $comments_by_type[ $parsed_args['type'] ];
2164                  } else {
2165                      $_comments = $comments;
2166                  }
2167              }
2168  
2169              // Otherwise, fall back on the comments from `$wp_query->comments`.
2170          } else {
2171              if ( empty( $wp_query->comments ) ) {
2172                  return;
2173              }
2174              if ( 'all' !== $parsed_args['type'] ) {
2175                  if ( empty( $wp_query->comments_by_type ) ) {
2176                      $wp_query->comments_by_type = separate_comments( $wp_query->comments );
2177                  }
2178                  if ( empty( $wp_query->comments_by_type[ $parsed_args['type'] ] ) ) {
2179                      return;
2180                  }
2181                  $_comments = $wp_query->comments_by_type[ $parsed_args['type'] ];
2182              } else {
2183                  $_comments = $wp_query->comments;
2184              }
2185  
2186              if ( $wp_query->max_num_comment_pages ) {
2187                  $default_comments_page = get_option( 'default_comments_page' );
2188                  $cpage                 = get_query_var( 'cpage' );
2189                  if ( 'newest' === $default_comments_page ) {
2190                      $parsed_args['cpage'] = $cpage;
2191  
2192                      /*
2193                      * When first page shows oldest comments, post permalink is the same as
2194                      * the comment permalink.
2195                      */
2196                  } elseif ( 1 == $cpage ) {
2197                      $parsed_args['cpage'] = '';
2198                  } else {
2199                      $parsed_args['cpage'] = $cpage;
2200                  }
2201  
2202                  $parsed_args['page']     = 0;
2203                  $parsed_args['per_page'] = 0;
2204              }
2205          }
2206      }
2207  
2208      if ( '' === $parsed_args['per_page'] && get_option( 'page_comments' ) ) {
2209          $parsed_args['per_page'] = get_query_var( 'comments_per_page' );
2210      }
2211  
2212      if ( empty( $parsed_args['per_page'] ) ) {
2213          $parsed_args['per_page'] = 0;
2214          $parsed_args['page']     = 0;
2215      }
2216  
2217      if ( '' === $parsed_args['max_depth'] ) {
2218          if ( get_option( 'thread_comments' ) ) {
2219              $parsed_args['max_depth'] = get_option( 'thread_comments_depth' );
2220          } else {
2221              $parsed_args['max_depth'] = -1;
2222          }
2223      }
2224  
2225      if ( '' === $parsed_args['page'] ) {
2226          if ( empty( $overridden_cpage ) ) {
2227              $parsed_args['page'] = get_query_var( 'cpage' );
2228          } else {
2229              $threaded            = ( -1 != $parsed_args['max_depth'] );
2230              $parsed_args['page'] = ( 'newest' === get_option( 'default_comments_page' ) ) ? get_comment_pages_count( $_comments, $parsed_args['per_page'], $threaded ) : 1;
2231              set_query_var( 'cpage', $parsed_args['page'] );
2232          }
2233      }
2234      // Validation check.
2235      $parsed_args['page'] = (int) $parsed_args['page'];
2236      if ( 0 == $parsed_args['page'] && 0 != $parsed_args['per_page'] ) {
2237          $parsed_args['page'] = 1;
2238      }
2239  
2240      if ( null === $parsed_args['reverse_top_level'] ) {
2241          $parsed_args['reverse_top_level'] = ( 'desc' === get_option( 'comment_order' ) );
2242      }
2243  
2244      wp_queue_comments_for_comment_meta_lazyload( $_comments );
2245  
2246      if ( empty( $parsed_args['walker'] ) ) {
2247          $walker = new Walker_Comment;
2248      } else {
2249          $walker = $parsed_args['walker'];
2250      }
2251  
2252      $output = $walker->paged_walk( $_comments, $parsed_args['max_depth'], $parsed_args['page'], $parsed_args['per_page'], $parsed_args );
2253  
2254      $in_comment_loop = false;
2255  
2256      if ( $parsed_args['echo'] ) {
2257          echo $output;
2258      } else {
2259          return $output;
2260      }
2261  }
2262  
2263  /**
2264   * Outputs a complete commenting form for use within a template.
2265   *
2266   * Most strings and form fields may be controlled through the `$args` array passed
2267   * into the function, while you may also choose to use the {@see 'comment_form_default_fields'}
2268   * filter to modify the array of default fields if you'd just like to add a new
2269   * one or remove a single field. All fields are also individually passed through
2270   * a filter of the {@see 'comment_form_field_$name'} where `$name` is the key used
2271   * in the array of fields.
2272   *
2273   * @since 3.0.0
2274   * @since 4.1.0 Introduced the 'class_submit' argument.
2275   * @since 4.2.0 Introduced the 'submit_button' and 'submit_fields' arguments.
2276   * @since 4.4.0 Introduced the 'class_form', 'title_reply_before', 'title_reply_after',
2277   *              'cancel_reply_before', and 'cancel_reply_after' arguments.
2278   * @since 4.5.0 The 'author', 'email', and 'url' form fields are limited to 245, 100,
2279   *              and 200 characters, respectively.
2280   * @since 4.6.0 Introduced the 'action' argument.
2281   * @since 4.9.6 Introduced the 'cookies' default comment field.
2282   * @since 5.5.0 Introduced the 'class_container' argument.
2283   *
2284   * @param array       $args {
2285   *     Optional. Default arguments and form fields to override.
2286   *
2287   *     @type array $fields {
2288   *         Default comment fields, filterable by default via the {@see 'comment_form_default_fields'} hook.
2289   *
2290   *         @type string $author  Comment author field HTML.
2291   *         @type string $email   Comment author email field HTML.
2292   *         @type string $url     Comment author URL field HTML.
2293   *         @type string $cookies Comment cookie opt-in field HTML.
2294   *     }
2295   *     @type string $comment_field        The comment textarea field HTML.
2296   *     @type string $must_log_in          HTML element for a 'must be logged in to comment' message.
2297   *     @type string $logged_in_as         HTML element for a 'logged in as [user]' message.
2298   *     @type string $comment_notes_before HTML element for a message displayed before the comment fields
2299   *                                        if the user is not logged in.
2300   *                                        Default 'Your email address will not be published.'.
2301   *     @type string $comment_notes_after  HTML element for a message displayed after the textarea field.
2302   *     @type string $action               The comment form element action attribute. Default '/wp-comments-post.php'.
2303   *     @type string $id_form              The comment form element id attribute. Default 'commentform'.
2304   *     @type string $id_submit            The comment submit element id attribute. Default 'submit'.
2305   *     @type string $class_container      The comment form container class attribute. Default 'comment-respond'.
2306   *     @type string $class_form           The comment form element class attribute. Default 'comment-form'.
2307   *     @type string $class_submit         The comment submit element class attribute. Default 'submit'.
2308   *     @type string $name_submit          The comment submit element name attribute. Default 'submit'.
2309   *     @type string $title_reply          The translatable 'reply' button label. Default 'Leave a Reply'.
2310   *     @type string $title_reply_to       The translatable 'reply-to' button label. Default 'Leave a Reply to %s',
2311   *                                        where %s is the author of the comment being replied to.
2312   *     @type string $title_reply_before   HTML displayed before the comment form title.
2313   *                                        Default: '<h3 id="reply-title" class="comment-reply-title">'.
2314   *     @type string $title_reply_after    HTML displayed after the comment form title.
2315   *                                        Default: '</h3>'.
2316   *     @type string $cancel_reply_before  HTML displayed before the cancel reply link.
2317   *     @type string $cancel_reply_after   HTML displayed after the cancel reply link.
2318   *     @type string $cancel_reply_link    The translatable 'cancel reply' button label. Default 'Cancel reply'.
2319   *     @type string $label_submit         The translatable 'submit' button label. Default 'Post a comment'.
2320   *     @type string $submit_button        HTML format for the Submit button.
2321   *                                        Default: '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />'.
2322   *     @type string $submit_field         HTML format for the markup surrounding the Submit button and comment hidden
2323   *                                        fields. Default: '<p class="form-submit">%1$s %2$s</p>', where %1$s is the
2324   *                                        submit button markup and %2$s is the comment hidden fields.
2325   *     @type string $format               The comment form format. Default 'xhtml'. Accepts 'xhtml', 'html5'.
2326   * }
2327   * @param int|WP_Post $post_id Post ID or WP_Post object to generate the form for. Default current post.
2328   */
2329  function comment_form( $args = array(), $post_id = null ) {
2330      if ( null === $post_id ) {
2331          $post_id = get_the_ID();
2332      }
2333  
2334      // Exit the function when comments for the post are closed.
2335      if ( ! comments_open( $post_id ) ) {
2336          /**
2337           * Fires after the comment form if comments are closed.
2338           *
2339           * @since 3.0.0
2340           */
2341          do_action( 'comment_form_comments_closed' );
2342  
2343          return;
2344      }
2345  
2346      $commenter     = wp_get_current_commenter();
2347      $user          = wp_get_current_user();
2348      $user_identity = $user->exists() ? $user->display_name : '';
2349  
2350      $args = wp_parse_args( $args );
2351      if ( ! isset( $args['format'] ) ) {
2352          $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';
2353      }
2354  
2355      $req   = get_option( 'require_name_email' );
2356      $html5 = 'html5' === $args['format'];
2357  
2358      // Define attributes in HTML5 or XHTML syntax.
2359      $required_attribute = ( $html5 ? ' required' : ' required="required"' );
2360      $checked_attribute  = ( $html5 ? ' checked' : ' checked="checked"' );
2361  
2362      // Identify required fields visually.
2363      $required_indicator = ' <span class="required" aria-hidden="true">*</span>';
2364  
2365      $fields = array(
2366          'author' => sprintf(
2367              '<p class="comment-form-author">%s %s</p>',
2368              sprintf(
2369                  '<label for="author">%s%s</label>',
2370                  __( 'Name' ),
2371                  ( $req ? $required_indicator : '' )
2372              ),
2373              sprintf(
2374                  '<input id="author" name="author" type="text" value="%s" size="30" maxlength="245"%s />',
2375                  esc_attr( $commenter['comment_author'] ),
2376                  ( $req ? $required_attribute : '' )
2377              )
2378          ),
2379          'email'  => sprintf(
2380              '<p class="comment-form-email">%s %s</p>',
2381              sprintf(
2382                  '<label for="email">%s%s</label>',
2383                  __( 'Email' ),
2384                  ( $req ? $required_indicator : '' )
2385              ),
2386              sprintf(
2387                  '<input id="email" name="email" %s value="%s" size="30" maxlength="100" aria-describedby="email-notes"%s />',
2388                  ( $html5 ? 'type="email"' : 'type="text"' ),
2389                  esc_attr( $commenter['comment_author_email'] ),
2390                  ( $req ? $required_attribute : '' )
2391              )
2392          ),
2393          'url'    => sprintf(
2394              '<p class="comment-form-url">%s %s</p>',
2395              sprintf(
2396                  '<label for="url">%s</label>',
2397                  __( 'Website' )
2398              ),
2399              sprintf(
2400                  '<input id="url" name="url" %s value="%s" size="30" maxlength="200" />',
2401                  ( $html5 ? 'type="url"' : 'type="text"' ),
2402                  esc_attr( $commenter['comment_author_url'] )
2403              )
2404          ),
2405      );
2406  
2407      if ( has_action( 'set_comment_cookies', 'wp_set_comment_cookies' ) && get_option( 'show_comments_cookies_opt_in' ) ) {
2408          $consent = empty( $commenter['comment_author_email'] ) ? '' : $checked_attribute;
2409  
2410          $fields['cookies'] = sprintf(
2411              '<p class="comment-form-cookies-consent">%s %s</p>',
2412              sprintf(
2413                  '<input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"%s />',
2414                  $consent
2415              ),
2416              sprintf(
2417                  '<label for="wp-comment-cookies-consent">%s</label>',
2418                  __( 'Save my name, email, and website in this browser for the next time I comment.' )
2419              )
2420          );
2421  
2422          // Ensure that the passed fields include cookies consent.
2423          if ( isset( $args['fields'] ) && ! isset( $args['fields']['cookies'] ) ) {
2424              $args['fields']['cookies'] = $fields['cookies'];
2425          }
2426      }
2427  
2428      $required_text = sprintf(
2429          /* translators: %s: Asterisk symbol (*). */
2430          ' <span class="required-field-message" aria-hidden="true">' . __( 'Required fields are marked %s' ) . '</span>',
2431          trim( $required_indicator )
2432      );
2433  
2434      /**
2435       * Filters the default comment form fields.
2436       *
2437       * @since 3.0.0
2438       *
2439       * @param string[] $fields Array of the default comment fields.
2440       */
2441      $fields = apply_filters( 'comment_form_default_fields', $fields );
2442  
2443      $defaults = array(
2444          'fields'               => $fields,
2445          'comment_field'        => sprintf(
2446              '<p class="comment-form-comment">%s %s</p>',
2447              sprintf(
2448                  '<label for="comment">%s%s</label>',
2449                  _x( 'Comment', 'noun' ),
2450                  $required_indicator
2451              ),
2452              '<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525"' . $required_attribute . '></textarea>'
2453          ),
2454          'must_log_in'          => sprintf(
2455              '<p class="must-log-in">%s</p>',
2456              sprintf(
2457                  /* translators: %s: Login URL. */
2458                  __( 'You must be <a href="%s">logged in</a> to post a comment.' ),
2459                  /** This filter is documented in wp-includes/link-template.php */
2460                  wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) )
2461              )
2462          ),
2463          'logged_in_as'         => sprintf(
2464              '<p class="logged-in-as">%s%s</p>',
2465              sprintf(
2466                  /* translators: 1: Edit user link, 2: Accessibility text, 3: User name, 4: Logout URL. */
2467                  __( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ),
2468                  get_edit_user_link(),
2469                  /* translators: %s: User name. */
2470                  esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ),
2471                  $user_identity,
2472                  /** This filter is documented in wp-includes/link-template.php */
2473                  wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) )
2474              ),
2475              $required_text
2476          ),
2477          'comment_notes_before' => sprintf(
2478              '<p class="comment-notes">%s%s</p>',
2479              sprintf(
2480                  '<span id="email-notes">%s</span>',
2481                  __( 'Your email address will not be published.' )
2482              ),
2483              $required_text
2484          ),
2485          'comment_notes_after'  => '',
2486          'action'               => site_url( '/wp-comments-post.php' ),
2487          'id_form'              => 'commentform',
2488          'id_submit'            => 'submit',
2489          'class_container'      => 'comment-respond',
2490          'class_form'           => 'comment-form',
2491          'class_submit'         => 'submit',
2492          'name_submit'          => 'submit',
2493          'title_reply'          => __( 'Leave a Reply' ),
2494          /* translators: %s: Author of the comment being replied to. */
2495          'title_reply_to'       => __( 'Leave a Reply to %s' ),
2496          'title_reply_before'   => '<h3 id="reply-title" class="comment-reply-title">',
2497          'title_reply_after'    => '</h3>',
2498          'cancel_reply_before'  => ' <small>',
2499          'cancel_reply_after'   => '</small>',
2500          'cancel_reply_link'    => __( 'Cancel reply' ),
2501          'label_submit'         => __( 'Post Comment' ),
2502          'submit_button'        => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />',
2503          'submit_field'         => '<p class="form-submit">%1$s %2$s</p>',
2504          'format'               => 'xhtml',
2505      );
2506  
2507      /**
2508       * Filters the comment form default arguments.
2509       *
2510       * Use {@see 'comment_form_default_fields'} to filter the comment fields.
2511       *
2512       * @since 3.0.0
2513       *
2514       * @param array $defaults The default comment form arguments.
2515       */
2516      $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
2517  
2518      // Ensure that the filtered arguments contain all required default values.
2519      $args = array_merge( $defaults, $args );
2520  
2521      // Remove `aria-describedby` from the email field if there's no associated description.
2522      if ( isset( $args['fields']['email'] ) && false === strpos( $args['comment_notes_before'], 'id="email-notes"' ) ) {
2523          $args['fields']['email'] = str_replace(
2524              ' aria-describedby="email-notes"',
2525              '',
2526              $args['fields']['email']
2527          );
2528      }
2529  
2530      /**
2531       * Fires before the comment form.
2532       *
2533       * @since 3.0.0
2534       */
2535      do_action( 'comment_form_before' );
2536      ?>
2537      <div id="respond" class="<?php echo esc_attr( $args['class_container'] ); ?>">
2538          <?php
2539          echo $args['title_reply_before'];
2540  
2541          comment_form_title( $args['title_reply'], $args['title_reply_to'] );
2542  
2543          if ( get_option( 'thread_comments' ) ) {
2544              echo $args['cancel_reply_before'];
2545  
2546              cancel_comment_reply_link( $args['cancel_reply_link'] );
2547  
2548              echo $args['cancel_reply_after'];
2549          }
2550  
2551          echo $args['title_reply_after'];
2552  
2553          if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) :
2554  
2555              echo $args['must_log_in'];
2556              /**
2557               * Fires after the HTML-formatted 'must log in after' message in the comment form.
2558               *
2559               * @since 3.0.0
2560               */
2561              do_action( 'comment_form_must_log_in_after' );
2562  
2563          else :
2564  
2565              printf(
2566                  '<form action="%s" method="post" id="%s" class="%s"%s>',
2567                  esc_url( $args['action'] ),
2568                  esc_attr( $args['id_form'] ),
2569                  esc_attr( $args['class_form'] ),
2570                  ( $html5 ? ' novalidate' : '' )
2571              );
2572  
2573              /**
2574               * Fires at the top of the comment form, inside the form tag.
2575               *
2576               * @since 3.0.0
2577               */
2578              do_action( 'comment_form_top' );
2579  
2580              if ( is_user_logged_in() ) :
2581  
2582                  /**
2583                   * Filters the 'logged in' message for the comment form for display.
2584                   *
2585                   * @since 3.0.0
2586                   *
2587                   * @param string $args_logged_in The logged-in-as HTML-formatted message.
2588                   * @param array  $commenter      An array containing the comment author's
2589                   *                               username, email, and URL.
2590                   * @param string $user_identity  If the commenter is a registered user,
2591                   *                               the display name, blank otherwise.
2592                   */
2593                  echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity );
2594  
2595                  /**
2596                   * Fires after the is_user_logged_in() check in the comment form.
2597                   *
2598                   * @since 3.0.0
2599                   *
2600                   * @param array  $commenter     An array containing the comment author's
2601                   *                              username, email, and URL.
2602                   * @param string $user_identity If the commenter is a registered user,
2603                   *                              the display name, blank otherwise.
2604                   */
2605                  do_action( 'comment_form_logged_in_after', $commenter, $user_identity );
2606  
2607              else :
2608  
2609                  echo $args['comment_notes_before'];
2610  
2611              endif;
2612  
2613              // Prepare an array of all fields, including the textarea.
2614              $comment_fields = array( 'comment' => $args['comment_field'] ) + (array) $args['fields'];
2615  
2616              /**
2617               * Filters the comment form fields, including the textarea.
2618               *
2619               * @since 4.4.0
2620               *
2621               * @param array $comment_fields The comment fields.
2622               */
2623              $comment_fields = apply_filters( 'comment_form_fields', $comment_fields );
2624  
2625              // Get an array of field names, excluding the textarea.
2626              $comment_field_keys = array_diff( array_keys( $comment_fields ), array( 'comment' ) );
2627  
2628              // Get the first and the last field name, excluding the textarea.
2629              $first_field = reset( $comment_field_keys );
2630              $last_field  = end( $comment_field_keys );
2631  
2632              foreach ( $comment_fields as $name => $field ) {
2633  
2634                  if ( 'comment' === $name ) {
2635  
2636                      /**
2637                       * Filters the content of the comment textarea field for display.
2638                       *
2639                       * @since 3.0.0
2640                       *
2641                       * @param string $args_comment_field The content of the comment textarea field.
2642                       */
2643                      echo apply_filters( 'comment_form_field_comment', $field );
2644  
2645                      echo $args['comment_notes_after'];
2646  
2647                  } elseif ( ! is_user_logged_in() ) {
2648  
2649                      if ( $first_field === $name ) {
2650                          /**
2651                           * Fires before the comment fields in the comment form, excluding the textarea.
2652                           *
2653                           * @since 3.0.0
2654                           */
2655                          do_action( 'comment_form_before_fields' );
2656                      }
2657  
2658                      /**
2659                       * Filters a comment form field for display.
2660                       *
2661                       * The dynamic portion of the hook name, `$name`, refers to the name
2662                       * of the comment form field.
2663                       *
2664                       * Possible hook names include:
2665                       *
2666                       *  - `comment_form_field_comment`
2667                       *  - `comment_form_field_author`
2668                       *  - `comment_form_field_email`
2669                       *  - `comment_form_field_url`
2670                       *  - `comment_form_field_cookies`
2671                       *
2672                       * @since 3.0.0
2673                       *
2674                       * @param string $field The HTML-formatted output of the comment form field.
2675                       */
2676                      echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
2677  
2678                      if ( $last_field === $name ) {
2679                          /**
2680                           * Fires after the comment fields in the comment form, excluding the textarea.
2681                           *
2682                           * @since 3.0.0
2683                           */
2684                          do_action( 'comment_form_after_fields' );
2685                      }
2686                  }
2687              }
2688  
2689              $submit_button = sprintf(
2690                  $args['submit_button'],
2691                  esc_attr( $args['name_submit'] ),
2692                  esc_attr( $args['id_submit'] ),
2693                  esc_attr( $args['class_submit'] ),
2694                  esc_attr( $args['label_submit'] )
2695              );
2696  
2697              /**
2698               * Filters the submit button for the comment form to display.
2699               *
2700               * @since 4.2.0
2701               *
2702               * @param string $submit_button HTML markup for the submit button.
2703               * @param array  $args          Arguments passed to comment_form().
2704               */
2705              $submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args );
2706  
2707              $submit_field = sprintf(
2708                  $args['submit_field'],
2709                  $submit_button,
2710                  get_comment_id_fields( $post_id )
2711              );
2712  
2713              /**
2714               * Filters the submit field for the comment form to display.
2715               *
2716               * The submit field includes the submit button, hidden fields for the
2717               * comment form, and any wrapper markup.
2718               *
2719               * @since 4.2.0
2720               *
2721               * @param string $submit_field HTML markup for the submit field.
2722               * @param array  $args         Arguments passed to comment_form().
2723               */
2724              echo apply_filters( 'comment_form_submit_field', $submit_field, $args );
2725  
2726              /**
2727               * Fires at the bottom of the comment form, inside the closing form tag.
2728               *
2729               * @since 1.5.0
2730               *
2731               * @param int $post_id The post ID.
2732               */
2733              do_action( 'comment_form', $post_id );
2734  
2735              echo '</form>';
2736  
2737          endif;
2738          ?>
2739      </div><!-- #respond -->
2740      <?php
2741  
2742      /**
2743       * Fires after the comment form.
2744       *
2745       * @since 3.0.0
2746       */
2747      do_action( 'comment_form_after' );
2748  }


Generated: Tue Mar 19 01:00:02 2024 Cross-referenced by PHPXref 0.7.1