[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

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


Generated: Mon Nov 18 01:00:04 2019 Cross-referenced by PHPXref 0.7.1