[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

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


Generated: Tue Jan 28 01:00:03 2020 Cross-referenced by PHPXref 0.7.1