[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

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


Generated: Tue Apr 7 01:00:07 2020 Cross-referenced by PHPXref 0.7.1