[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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


Generated : Sat Sep 26 08:20:01 2020 Cross-referenced by PHPXref