[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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


Generated: Mon Jun 17 08:20:02 2019 Cross-referenced by PHPXref 0.7