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


Generated: Mon Jul 6 01:00:03 2020 Cross-referenced by PHPXref 0.7.1