[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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


Generated : Wed Jun 19 08:20:01 2024 Cross-referenced by PHPXref