[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

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


Generated: Tue Sep 17 01:00:03 2019 Cross-referenced by PHPXref 0.7.1