wp/wp-includes/comment-template.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
     7  * @package WordPress
     7  * @package WordPress
     8  * @subpackage Template
     8  * @subpackage Template
     9  */
     9  */
    10 
    10 
    11 /**
    11 /**
    12  * Retrieve the author of the current comment.
    12  * Retrieves the author of the current comment.
    13  *
    13  *
    14  * If the comment has an empty comment_author field, then 'Anonymous' person is
    14  * If the comment has an empty comment_author field, then 'Anonymous' person is
    15  * assumed.
    15  * assumed.
    16  *
    16  *
    17  * @since 1.5.0
    17  * @since 1.5.0
    23  */
    23  */
    24 function get_comment_author( $comment_ID = 0 ) {
    24 function get_comment_author( $comment_ID = 0 ) {
    25 	$comment = get_comment( $comment_ID );
    25 	$comment = get_comment( $comment_ID );
    26 
    26 
    27 	if ( empty( $comment->comment_author ) ) {
    27 	if ( empty( $comment->comment_author ) ) {
    28 		if ( $comment->user_id && $user = get_userdata( $comment->user_id ) ) {
    28 		$user = $comment->user_id ? get_userdata( $comment->user_id ) : false;
       
    29 		if ( $user ) {
    29 			$author = $user->display_name;
    30 			$author = $user->display_name;
    30 		} else {
    31 		} else {
    31 			$author = __( 'Anonymous' );
    32 			$author = __( 'Anonymous' );
    32 		}
    33 		}
    33 	} else {
    34 	} else {
    71 	 */
    72 	 */
    72 	echo apply_filters( 'comment_author', $author, $comment->comment_ID );
    73 	echo apply_filters( 'comment_author', $author, $comment->comment_ID );
    73 }
    74 }
    74 
    75 
    75 /**
    76 /**
    76  * Retrieve the email of the author of the current comment.
    77  * Retrieves the email of the author of the current comment.
    77  *
    78  *
    78  * @since 1.5.0
    79  * @since 1.5.0
    79  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
    80  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
    80  *
    81  *
    81  * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's email.
    82  * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's email.
    97 	 */
    98 	 */
    98 	return apply_filters( 'get_comment_author_email', $comment->comment_author_email, $comment->comment_ID, $comment );
    99 	return apply_filters( 'get_comment_author_email', $comment->comment_author_email, $comment->comment_ID, $comment );
    99 }
   100 }
   100 
   101 
   101 /**
   102 /**
   102  * Display the email of the author of the current global $comment.
   103  * Displays the email of the author of the current global $comment.
   103  *
   104  *
   104  * Care should be taken to protect the email address and assure that email
   105  * Care should be taken to protect the email address and assure that email
   105  * harvesters do not capture your commenter's email address. Most assume that
   106  * harvesters do not capture your commenter's email address. Most assume that
   106  * their email address will not appear in raw form on the site. Doing so will
   107  * their email address will not appear in raw form on the site. Doing so will
   107  * enable anyone, including those that people don't want to get the email
   108  * enable anyone, including those that people don't want to get the email
   128 	 */
   129 	 */
   129 	echo apply_filters( 'author_email', $author_email, $comment->comment_ID );
   130 	echo apply_filters( 'author_email', $author_email, $comment->comment_ID );
   130 }
   131 }
   131 
   132 
   132 /**
   133 /**
   133  * Display the html email link to the author of the current comment.
   134  * Displays the HTML email link to the author of the current comment.
   134  *
   135  *
   135  * Care should be taken to protect the email address and assure that email
   136  * Care should be taken to protect the email address and assure that email
   136  * harvesters do not capture your commenter's email address. Most assume that
   137  * harvesters do not capture your commenter's email address. Most assume that
   137  * their email address will not appear in raw form on the site. Doing so will
   138  * their email address will not appear in raw form on the site. Doing so will
   138  * enable anyone, including those that people don't want to get the email
   139  * enable anyone, including those that people don't want to get the email
   146  * @param string         $before   Optional. Text or HTML to display before the email link. Default empty.
   147  * @param string         $before   Optional. Text or HTML to display before the email link. Default empty.
   147  * @param string         $after    Optional. Text or HTML to display after the email link. Default empty.
   148  * @param string         $after    Optional. Text or HTML to display after the email link. Default empty.
   148  * @param int|WP_Comment $comment  Optional. Comment ID or WP_Comment object. Default is the current comment.
   149  * @param int|WP_Comment $comment  Optional. Comment ID or WP_Comment object. Default is the current comment.
   149  */
   150  */
   150 function comment_author_email_link( $linktext = '', $before = '', $after = '', $comment = null ) {
   151 function comment_author_email_link( $linktext = '', $before = '', $after = '', $comment = null ) {
   151 	if ( $link = get_comment_author_email_link( $linktext, $before, $after, $comment ) ) {
   152 	$link = get_comment_author_email_link( $linktext, $before, $after, $comment );
       
   153 	if ( $link ) {
   152 		echo $link;
   154 		echo $link;
   153 	}
   155 	}
   154 }
   156 }
   155 
   157 
   156 /**
   158 /**
   157  * Return the html email link to the author of the current comment.
   159  * Returns the HTML email link to the author of the current comment.
   158  *
   160  *
   159  * Care should be taken to protect the email address and assure that email
   161  * Care should be taken to protect the email address and assure that email
   160  * harvesters do not capture your commenter's email address. Most assume that
   162  * harvesters do not capture your commenter's email address. Most assume that
   161  * their email address will not appear in raw form on the site. Doing so will
   163  * their email address will not appear in raw form on the site. Doing so will
   162  * enable anyone, including those that people don't want to get the email
   164  * enable anyone, including those that people don't want to get the email
   188 	 * @param string     $comment_author_email The comment author's email address.
   190 	 * @param string     $comment_author_email The comment author's email address.
   189 	 * @param WP_Comment $comment              The comment object.
   191 	 * @param WP_Comment $comment              The comment object.
   190 	 */
   192 	 */
   191 	$email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );
   193 	$email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );
   192 
   194 
   193 	if ( ( ! empty( $email ) ) && ( $email != '@' ) ) {
   195 	if ( ( ! empty( $email ) ) && ( '@' !== $email ) ) {
   194 		$display = ( $linktext != '' ) ? $linktext : $email;
   196 		$display = ( '' !== $linktext ) ? $linktext : $email;
   195 		$return  = $before;
   197 		$return  = $before;
   196 		$return .= sprintf( '<a href="%1$s">%2$s</a>', esc_url( 'mailto:' . $email ), esc_html( $display ) );
   198 		$return .= sprintf( '<a href="%1$s">%2$s</a>', esc_url( 'mailto:' . $email ), esc_html( $display ) );
   197 		$return .= $after;
   199 		$return .= $after;
   198 		return $return;
   200 		return $return;
   199 	} else {
   201 	} else {
   200 		return '';
   202 		return '';
   201 	}
   203 	}
   202 }
   204 }
   203 
   205 
   204 /**
   206 /**
   205  * Retrieve the HTML link to the URL of the author of the current comment.
   207  * Retrieves the HTML link to the URL of the author of the current comment.
   206  *
   208  *
   207  * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
   209  * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
   208  * which falls back to the global comment variable if the $comment_ID argument is empty.
   210  * which falls back to the global comment variable if the $comment_ID argument is empty.
   209  *
   211  *
   210  * @since 1.5.0
   212  * @since 1.5.0
   217 function get_comment_author_link( $comment_ID = 0 ) {
   219 function get_comment_author_link( $comment_ID = 0 ) {
   218 	$comment = get_comment( $comment_ID );
   220 	$comment = get_comment( $comment_ID );
   219 	$url     = get_comment_author_url( $comment );
   221 	$url     = get_comment_author_url( $comment );
   220 	$author  = get_comment_author( $comment );
   222 	$author  = get_comment_author( $comment );
   221 
   223 
   222 	if ( empty( $url ) || 'http://' == $url ) {
   224 	if ( empty( $url ) || 'http://' === $url ) {
   223 		$return = $author;
   225 		$return = $author;
   224 	} else {
   226 	} else {
   225 		$return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
   227 		$return = "<a href='$url' rel='external nofollow ugc' class='url'>$author</a>";
   226 	}
   228 	}
   227 
   229 
   228 	/**
   230 	/**
   229 	 * Filters the comment author's link for display.
   231 	 * Filters the comment author's link for display.
   230 	 *
   232 	 *
   238 	 */
   240 	 */
   239 	return apply_filters( 'get_comment_author_link', $return, $author, $comment->comment_ID );
   241 	return apply_filters( 'get_comment_author_link', $return, $author, $comment->comment_ID );
   240 }
   242 }
   241 
   243 
   242 /**
   244 /**
   243  * Display the html link to the url of the author of the current comment.
   245  * Displays the HTML link to the URL of the author of the current comment.
   244  *
   246  *
   245  * @since 0.71
   247  * @since 0.71
   246  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   248  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   247  *
   249  *
   248  * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's link.
   250  * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's link.
   260  *
   262  *
   261  * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's IP address.
   263  * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's IP address.
   262  *                                   Default current comment.
   264  *                                   Default current comment.
   263  * @return string Comment author's IP address.
   265  * @return string Comment author's IP address.
   264  */
   266  */
   265 function get_comment_author_IP( $comment_ID = 0 ) {
   267 function get_comment_author_IP( $comment_ID = 0 ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
   266 	$comment = get_comment( $comment_ID );
   268 	$comment = get_comment( $comment_ID );
   267 
   269 
   268 	/**
   270 	/**
   269 	 * Filters the comment author's returned IP address.
   271 	 * Filters the comment author's returned IP address.
   270 	 *
   272 	 *
   273 	 *
   275 	 *
   274 	 * @param string     $comment_author_IP The comment author's IP address.
   276 	 * @param string     $comment_author_IP The comment author's IP address.
   275 	 * @param int        $comment_ID        The comment ID.
   277 	 * @param int        $comment_ID        The comment ID.
   276 	 * @param WP_Comment $comment           The comment object.
   278 	 * @param WP_Comment $comment           The comment object.
   277 	 */
   279 	 */
   278 	return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP, $comment->comment_ID, $comment );
   280 	return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP, $comment->comment_ID, $comment );  // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
   279 }
   281 }
   280 
   282 
   281 /**
   283 /**
   282  * Display the IP address of the author of the current comment.
   284  * Displays the IP address of the author of the current comment.
   283  *
   285  *
   284  * @since 0.71
   286  * @since 0.71
   285  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   287  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   286  *
   288  *
   287  * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's IP address.
   289  * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's IP address.
   288  *                                   Default current comment.
   290  *                                   Default current comment.
   289  */
   291  */
   290 function comment_author_IP( $comment_ID = 0 ) {
   292 function comment_author_IP( $comment_ID = 0 ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
   291 	echo esc_html( get_comment_author_IP( $comment_ID ) );
   293 	echo esc_html( get_comment_author_IP( $comment_ID ) );
   292 }
   294 }
   293 
   295 
   294 /**
   296 /**
   295  * Retrieve the url of the author of the current comment.
   297  * Retrieves the URL of the author of the current comment, not linked.
   296  *
   298  *
   297  * @since 1.5.0
   299  * @since 1.5.0
   298  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   300  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   299  *
   301  *
   300  * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's URL.
   302  * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's URL.
   301  *                                   Default current comment.
   303  *                                   Default current comment.
   302  * @return string Comment author URL.
   304  * @return string Comment author URL, if provided, an empty string otherwise.
   303  */
   305  */
   304 function get_comment_author_url( $comment_ID = 0 ) {
   306 function get_comment_author_url( $comment_ID = 0 ) {
   305 	$comment = get_comment( $comment_ID );
   307 	$comment = get_comment( $comment_ID );
   306 	$url     = '';
   308 	$url     = '';
   307 	$id      = 0;
   309 	$id      = 0;
       
   310 
   308 	if ( ! empty( $comment ) ) {
   311 	if ( ! empty( $comment ) ) {
   309 		$author_url = ( 'http://' == $comment->comment_author_url ) ? '' : $comment->comment_author_url;
   312 		$author_url = ( 'http://' === $comment->comment_author_url ) ? '' : $comment->comment_author_url;
   310 		$url        = esc_url( $author_url, array( 'http', 'https' ) );
   313 		$url        = esc_url( $author_url, array( 'http', 'https' ) );
   311 		$id         = $comment->comment_ID;
   314 		$id         = $comment->comment_ID;
   312 	}
   315 	}
   313 
   316 
   314 	/**
   317 	/**
   323 	 */
   326 	 */
   324 	return apply_filters( 'get_comment_author_url', $url, $id, $comment );
   327 	return apply_filters( 'get_comment_author_url', $url, $id, $comment );
   325 }
   328 }
   326 
   329 
   327 /**
   330 /**
   328  * Display the url of the author of the current comment.
   331  * Displays the URL of the author of the current comment, not linked.
   329  *
   332  *
   330  * @since 0.71
   333  * @since 0.71
   331  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   334  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   332  *
   335  *
   333  * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's URL.
   336  * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's URL.
   348 	 */
   351 	 */
   349 	echo apply_filters( 'comment_url', $author_url, $comment->comment_ID );
   352 	echo apply_filters( 'comment_url', $author_url, $comment->comment_ID );
   350 }
   353 }
   351 
   354 
   352 /**
   355 /**
   353  * Retrieves the HTML link of the url of the author of the current comment.
   356  * Retrieves the HTML link of the URL of the author of the current comment.
   354  *
   357  *
   355  * $linktext parameter is only used if the URL does not exist for the comment
   358  * $linktext parameter is only used if the URL does not exist for the comment
   356  * author. If the URL does exist then the URL will be used and the $linktext
   359  * author. If the URL does exist then the URL will be used and the $linktext
   357  * will be ignored.
   360  * will be ignored.
   358  *
   361  *
   372  *                                 Default is the current comment.
   375  *                                 Default is the current comment.
   373  * @return string The HTML link between the $before and $after parameters.
   376  * @return string The HTML link between the $before and $after parameters.
   374  */
   377  */
   375 function get_comment_author_url_link( $linktext = '', $before = '', $after = '', $comment = 0 ) {
   378 function get_comment_author_url_link( $linktext = '', $before = '', $after = '', $comment = 0 ) {
   376 	$url     = get_comment_author_url( $comment );
   379 	$url     = get_comment_author_url( $comment );
   377 	$display = ( $linktext != '' ) ? $linktext : $url;
   380 	$display = ( '' !== $linktext ) ? $linktext : $url;
   378 	$display = str_replace( 'http://www.', '', $display );
   381 	$display = str_replace( 'http://www.', '', $display );
   379 	$display = str_replace( 'http://', '', $display );
   382 	$display = str_replace( 'http://', '', $display );
   380 
   383 
   381 	if ( '/' == substr( $display, -1 ) ) {
   384 	if ( '/' === substr( $display, -1 ) ) {
   382 		$display = substr( $display, 0, -1 );
   385 		$display = substr( $display, 0, -1 );
   383 	}
   386 	}
   384 
   387 
   385 	$return = "$before<a href='$url' rel='external'>$display</a>$after";
   388 	$return = "$before<a href='$url' rel='external'>$display</a>$after";
   386 
   389 
   393 	 */
   396 	 */
   394 	return apply_filters( 'get_comment_author_url_link', $return );
   397 	return apply_filters( 'get_comment_author_url_link', $return );
   395 }
   398 }
   396 
   399 
   397 /**
   400 /**
   398  * Displays the HTML link of the url of the author of the current comment.
   401  * Displays the HTML link of the URL of the author of the current comment.
   399  *
   402  *
   400  * @since 0.71
   403  * @since 0.71
   401  * @since 4.6.0 Added the `$comment` parameter.
   404  * @since 4.6.0 Added the `$comment` parameter.
   402  *
   405  *
   403  * @param string         $linktext Optional. Text to display instead of the comment author's
   406  * @param string         $linktext Optional. Text to display instead of the comment author's
   421  *
   424  *
   422  * @param string|array   $class    Optional. One or more classes to add to the class list.
   425  * @param string|array   $class    Optional. One or more classes to add to the class list.
   423  *                                 Default empty.
   426  *                                 Default empty.
   424  * @param int|WP_Comment $comment  Comment ID or WP_Comment object. Default current comment.
   427  * @param int|WP_Comment $comment  Comment ID or WP_Comment object. Default current comment.
   425  * @param int|WP_Post    $post_id  Post ID or WP_Post object. Default current post.
   428  * @param int|WP_Post    $post_id  Post ID or WP_Post object. Default current post.
   426  * @param bool           $echo     Optional. Whether to cho or return the output.
   429  * @param bool           $echo     Optional. Whether to echo or return the output.
   427  *                                 Default true.
   430  *                                 Default true.
   428  * @return string If `$echo` is false, the class will be returned. Void otherwise.
   431  * @return void|string Void if `$echo` argument is true, comment classes if `$echo` is false.
   429  */
   432  */
   430 function comment_class( $class = '', $comment = null, $post_id = null, $echo = true ) {
   433 function comment_class( $class = '', $comment = null, $post_id = null, $echo = true ) {
   431 	// Separates classes with a single space, collates classes for comment DIV
   434 	// Separates classes with a single space, collates classes for comment DIV.
   432 	$class = 'class="' . join( ' ', get_comment_class( $class, $comment, $post_id ) ) . '"';
   435 	$class = 'class="' . join( ' ', get_comment_class( $class, $comment, $post_id ) ) . '"';
       
   436 
   433 	if ( $echo ) {
   437 	if ( $echo ) {
   434 		echo $class;
   438 		echo $class;
   435 	} else {
   439 	} else {
   436 		return $class;
   440 		return $class;
   437 	}
   441 	}
   448  * @global int $comment_thread_alt
   452  * @global int $comment_thread_alt
   449  *
   453  *
   450  * @param string|array   $class      Optional. One or more classes to add to the class list. Default empty.
   454  * @param string|array   $class      Optional. One or more classes to add to the class list. Default empty.
   451  * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. Default current comment.
   455  * @param int|WP_Comment $comment_id Comment ID or WP_Comment object. Default current comment.
   452  * @param int|WP_Post    $post_id    Post ID or WP_Post object. Default current post.
   456  * @param int|WP_Post    $post_id    Post ID or WP_Post object. Default current post.
   453  * @return array An array of classes.
   457  * @return string[] An array of classes.
   454  */
   458  */
   455 function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
   459 function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
   456 	global $comment_alt, $comment_depth, $comment_thread_alt;
   460 	global $comment_alt, $comment_depth, $comment_thread_alt;
   457 
   461 
   458 	$classes = array();
   462 	$classes = array();
   460 	$comment = get_comment( $comment_id );
   464 	$comment = get_comment( $comment_id );
   461 	if ( ! $comment ) {
   465 	if ( ! $comment ) {
   462 		return $classes;
   466 		return $classes;
   463 	}
   467 	}
   464 
   468 
   465 	// Get the comment type (comment, trackback),
   469 	// Get the comment type (comment, trackback).
   466 	$classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
   470 	$classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
   467 
   471 
   468 	// Add classes for comment authors that are registered users.
   472 	// Add classes for comment authors that are registered users.
   469 	if ( $comment->user_id > 0 && $user = get_userdata( $comment->user_id ) ) {
   473 	$user = $comment->user_id ? get_userdata( $comment->user_id ) : false;
       
   474 	if ( $user ) {
   470 		$classes[] = 'byuser';
   475 		$classes[] = 'byuser';
   471 		$classes[] = 'comment-author-' . sanitize_html_class( $user->user_nicename, $comment->user_id );
   476 		$classes[] = 'comment-author-' . sanitize_html_class( $user->user_nicename, $comment->user_id );
   472 		// For comment authors who are the author of the post
   477 		// For comment authors who are the author of the post.
   473 		if ( $post = get_post( $post_id ) ) {
   478 		$post = get_post( $post_id );
       
   479 		if ( $post ) {
   474 			if ( $comment->user_id === $post->post_author ) {
   480 			if ( $comment->user_id === $post->post_author ) {
   475 				$classes[] = 'bypostauthor';
   481 				$classes[] = 'bypostauthor';
   476 			}
   482 			}
   477 		}
   483 		}
   478 	}
   484 	}
   494 		$classes[] = 'even';
   500 		$classes[] = 'even';
   495 	}
   501 	}
   496 
   502 
   497 	$comment_alt++;
   503 	$comment_alt++;
   498 
   504 
   499 	// Alt for top-level comments
   505 	// Alt for top-level comments.
   500 	if ( 1 == $comment_depth ) {
   506 	if ( 1 == $comment_depth ) {
   501 		if ( $comment_thread_alt % 2 ) {
   507 		if ( $comment_thread_alt % 2 ) {
   502 			$classes[] = 'thread-odd';
   508 			$classes[] = 'thread-odd';
   503 			$classes[] = 'thread-alt';
   509 			$classes[] = 'thread-alt';
   504 		} else {
   510 		} else {
   523 	 *
   529 	 *
   524 	 * @since 2.7.0
   530 	 * @since 2.7.0
   525 	 *
   531 	 *
   526 	 * @param string[]    $classes    An array of comment classes.
   532 	 * @param string[]    $classes    An array of comment classes.
   527 	 * @param string      $class      A comma-separated list of additional classes added to the list.
   533 	 * @param string      $class      A comma-separated list of additional classes added to the list.
   528 	 * @param int         $comment_id The comment id.
   534 	 * @param int         $comment_id The comment ID.
   529 	 * @param WP_Comment  $comment    The comment object.
   535 	 * @param WP_Comment  $comment    The comment object.
   530 	 * @param int|WP_Post $post_id    The post ID or WP_Post object.
   536 	 * @param int|WP_Post $post_id    The post ID or WP_Post object.
   531 	 */
   537 	 */
   532 	return apply_filters( 'comment_class', $classes, $class, $comment->comment_ID, $comment, $post_id );
   538 	return apply_filters( 'comment_class', $classes, $class, $comment->comment_ID, $comment, $post_id );
   533 }
   539 }
   534 
   540 
   535 /**
   541 /**
   536  * Retrieve the comment date of the current comment.
   542  * Retrieves the comment date of the current comment.
   537  *
   543  *
   538  * @since 1.5.0
   544  * @since 1.5.0
   539  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   545  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   540  *
   546  *
   541  * @param string          $d          Optional. The format of the date. Default user's setting.
   547  * @param string         $format     Optional. The format of the date. Default user's setting.
   542  * @param int|WP_Comment  $comment_ID WP_Comment or ID of the comment for which to get the date.
   548  * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the date.
   543  *                                    Default current comment.
   549  *                                   Default current comment.
   544  * @return string The comment's date.
   550  * @return string The comment's date.
   545  */
   551  */
   546 function get_comment_date( $d = '', $comment_ID = 0 ) {
   552 function get_comment_date( $format = '', $comment_ID = 0 ) {
   547 	$comment = get_comment( $comment_ID );
   553 	$comment = get_comment( $comment_ID );
   548 	if ( '' == $d ) {
   554 
   549 		$date = mysql2date( get_option( 'date_format' ), $comment->comment_date );
   555 	$_format = ! empty( $format ) ? $format : get_option( 'date_format' );
   550 	} else {
   556 
   551 		$date = mysql2date( $d, $comment->comment_date );
   557 	$date = mysql2date( $_format, $comment->comment_date );
   552 	}
   558 
   553 	/**
   559 	/**
   554 	 * Filters the returned comment date.
   560 	 * Filters the returned comment date.
   555 	 *
   561 	 *
   556 	 * @since 1.5.0
   562 	 * @since 1.5.0
   557 	 *
   563 	 *
   558 	 * @param string|int $date    Formatted date string or Unix timestamp.
   564 	 * @param string|int $date    Formatted date string or Unix timestamp.
   559 	 * @param string     $d       The format of the date.
   565 	 * @param string     $format  The format of the date.
   560 	 * @param WP_Comment $comment The comment object.
   566 	 * @param WP_Comment $comment The comment object.
   561 	 */
   567 	 */
   562 	return apply_filters( 'get_comment_date', $date, $d, $comment );
   568 	return apply_filters( 'get_comment_date', $date, $format, $comment );
   563 }
   569 }
   564 
   570 
   565 /**
   571 /**
   566  * Display the comment date of the current comment.
   572  * Displays the comment date of the current comment.
   567  *
   573  *
   568  * @since 0.71
   574  * @since 0.71
   569  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   575  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   570  *
   576  *
   571  * @param string         $d          Optional. The format of the date. Default user's settings.
   577  * @param string         $format     Optional. The format of the date. Default user's settings.
   572  * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the date.
   578  * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the date.
   573  *                                   Default current comment.
   579  *                                   Default current comment.
   574  */
   580  */
   575 function comment_date( $d = '', $comment_ID = 0 ) {
   581 function comment_date( $format = '', $comment_ID = 0 ) {
   576 	echo get_comment_date( $d, $comment_ID );
   582 	echo get_comment_date( $format, $comment_ID );
   577 }
   583 }
   578 
   584 
   579 /**
   585 /**
   580  * Retrieve the excerpt of the current comment.
   586  * Retrieves the excerpt of the given comment.
   581  *
   587  *
   582  * Will cut each word and only output the first 20 words with '&hellip;' at the end.
   588  * Returns a maximum of 20 words with an ellipsis appended if necessary.
   583  * If the word count is less than 20, then no truncating is done and no '&hellip;'
       
   584  * will appear.
       
   585  *
   589  *
   586  * @since 1.5.0
   590  * @since 1.5.0
   587  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   591  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   588  *
   592  *
   589  * @param int|WP_Comment $comment_ID  WP_Comment or ID of the comment for which to get the excerpt.
   593  * @param int|WP_Comment $comment_ID  WP_Comment or ID of the comment for which to get the excerpt.
   590  *                                    Default current comment.
   594  *                                    Default current comment.
   591  * @return string The maybe truncated comment with 20 words or less.
   595  * @return string The possibly truncated comment excerpt.
   592  */
   596  */
   593 function get_comment_excerpt( $comment_ID = 0 ) {
   597 function get_comment_excerpt( $comment_ID = 0 ) {
   594 	$comment      = get_comment( $comment_ID );
   598 	$comment = get_comment( $comment_ID );
   595 	$comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
   599 
   596 	$words        = explode( ' ', $comment_text );
   600 	if ( ! post_password_required( $comment->comment_post_ID ) ) {
   597 
   601 		$comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
   598 	/**
   602 	} else {
   599 	 * Filters the amount of words used in the comment excerpt.
   603 		$comment_text = __( 'Password protected' );
       
   604 	}
       
   605 
       
   606 	/* translators: Maximum number of words used in a comment excerpt. */
       
   607 	$comment_excerpt_length = intval( _x( '20', 'comment_excerpt_length' ) );
       
   608 
       
   609 	/**
       
   610 	 * Filters the maximum number of words used in the comment excerpt.
   600 	 *
   611 	 *
   601 	 * @since 4.4.0
   612 	 * @since 4.4.0
   602 	 *
   613 	 *
   603 	 * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt.
   614 	 * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt.
   604 	 */
   615 	 */
   605 	$comment_excerpt_length = apply_filters( 'comment_excerpt_length', 20 );
   616 	$comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length );
   606 
   617 
   607 	$use_ellipsis = count( $words ) > $comment_excerpt_length;
   618 	$excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '&hellip;' );
   608 	if ( $use_ellipsis ) {
   619 
   609 		$words = array_slice( $words, 0, $comment_excerpt_length );
       
   610 	}
       
   611 
       
   612 	$excerpt = trim( join( ' ', $words ) );
       
   613 	if ( $use_ellipsis ) {
       
   614 		$excerpt .= '&hellip;';
       
   615 	}
       
   616 	/**
   620 	/**
   617 	 * Filters the retrieved comment excerpt.
   621 	 * Filters the retrieved comment excerpt.
   618 	 *
   622 	 *
   619 	 * @since 1.5.0
   623 	 * @since 1.5.0
   620 	 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
   624 	 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
   625 	 */
   629 	 */
   626 	return apply_filters( 'get_comment_excerpt', $excerpt, $comment->comment_ID, $comment );
   630 	return apply_filters( 'get_comment_excerpt', $excerpt, $comment->comment_ID, $comment );
   627 }
   631 }
   628 
   632 
   629 /**
   633 /**
   630  * Display the excerpt of the current comment.
   634  * Displays the excerpt of the current comment.
   631  *
   635  *
   632  * @since 1.2.0
   636  * @since 1.2.0
   633  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   637  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   634  *
   638  *
   635  * @param int|WP_Comment $comment_ID  WP_Comment or ID of the comment for which to print the excerpt.
   639  * @param int|WP_Comment $comment_ID  WP_Comment or ID of the comment for which to print the excerpt.
   650 	 */
   654 	 */
   651 	echo apply_filters( 'comment_excerpt', $comment_excerpt, $comment->comment_ID );
   655 	echo apply_filters( 'comment_excerpt', $comment_excerpt, $comment->comment_ID );
   652 }
   656 }
   653 
   657 
   654 /**
   658 /**
   655  * Retrieve the comment id of the current comment.
   659  * Retrieves the comment ID of the current comment.
   656  *
   660  *
   657  * @since 1.5.0
   661  * @since 1.5.0
   658  *
   662  *
   659  * @return int The comment ID.
   663  * @return int The comment ID.
   660  */
   664  */
   661 function get_comment_ID() {
   665 function get_comment_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
   662 	$comment = get_comment();
   666 	$comment = get_comment();
   663 
   667 
   664 	/**
   668 	/**
   665 	 * Filters the returned comment ID.
   669 	 * Filters the returned comment ID.
   666 	 *
   670 	 *
   668 	 * @since 4.1.0 The `$comment_ID` parameter was added.
   672 	 * @since 4.1.0 The `$comment_ID` parameter was added.
   669 	 *
   673 	 *
   670 	 * @param int        $comment_ID The current comment ID.
   674 	 * @param int        $comment_ID The current comment ID.
   671 	 * @param WP_Comment $comment    The comment object.
   675 	 * @param WP_Comment $comment    The comment object.
   672 	 */
   676 	 */
   673 	return apply_filters( 'get_comment_ID', $comment->comment_ID, $comment );
   677 	return apply_filters( 'get_comment_ID', $comment->comment_ID, $comment );  // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
   674 }
   678 }
   675 
   679 
   676 /**
   680 /**
   677  * Display the comment id of the current comment.
   681  * Displays the comment ID of the current comment.
   678  *
   682  *
   679  * @since 0.71
   683  * @since 0.71
   680  */
   684  */
   681 function comment_ID() {
   685 function comment_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
   682 	echo get_comment_ID();
   686 	echo get_comment_ID();
   683 }
   687 }
   684 
   688 
   685 /**
   689 /**
   686  * Retrieve the link to a given comment.
   690  * Retrieves the link to a given comment.
   687  *
   691  *
   688  * @since 1.5.0
   692  * @since 1.5.0
   689  * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. Added `$cpage` argument.
   693  * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. Added `$cpage` argument.
   690  *
   694  *
   691  * @see get_page_of_comment()
   695  * @see get_page_of_comment()
   692  *
   696  *
   693  * @global WP_Rewrite $wp_rewrite
   697  * @global WP_Rewrite $wp_rewrite      WordPress rewrite component.
   694  * @global bool       $in_comment_loop
   698  * @global bool       $in_comment_loop
   695  *
   699  *
   696  * @param WP_Comment|int|null $comment Comment to retrieve. Default current comment.
   700  * @param WP_Comment|int|null $comment Comment to retrieve. Default current comment.
   697  * @param array               $args {
   701  * @param array               $args {
   698  *     An array of optional arguments to override the defaults.
   702  *     An array of optional arguments to override the defaults.
   819 	 */
   823 	 */
   820 	return apply_filters( 'get_comments_link', $comments_link, $post_id );
   824 	return apply_filters( 'get_comments_link', $comments_link, $post_id );
   821 }
   825 }
   822 
   826 
   823 /**
   827 /**
   824  * Display the link to the current post comments.
   828  * Displays the link to the current post comments.
   825  *
   829  *
   826  * @since 0.71
   830  * @since 0.71
   827  *
   831  *
   828  * @param string $deprecated   Not Used.
   832  * @param string $deprecated   Not Used.
   829  * @param string $deprecated_2 Not Used.
   833  * @param string $deprecated_2 Not Used.
   867 	 */
   871 	 */
   868 	return apply_filters( 'get_comments_number', $count, $post_id );
   872 	return apply_filters( 'get_comments_number', $count, $post_id );
   869 }
   873 }
   870 
   874 
   871 /**
   875 /**
   872  * Display the language string for the number of comments the current post has.
   876  * Displays the language string for the number of comments the current post has.
   873  *
   877  *
   874  * @since 0.71
   878  * @since 0.71
   875  *
   879  * @since 5.4.0 The `$deprecated` parameter was changed to `$post_id`.
   876  * @param string $zero       Optional. Text for no comments. Default false.
   880  *
   877  * @param string $one        Optional. Text for one comment. Default false.
   881  * @param string      $zero       Optional. Text for no comments. Default false.
   878  * @param string $more       Optional. Text for more than one comment. Default false.
   882  * @param string      $one        Optional. Text for one comment. Default false.
   879  * @param string $deprecated Not used.
   883  * @param string      $more       Optional. Text for more than one comment. Default false.
   880  */
   884  * @param int|WP_Post $post_id    Optional. Post ID or WP_Post object. Default is the global `$post`.
   881 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
   885  */
   882 	if ( ! empty( $deprecated ) ) {
   886 function comments_number( $zero = false, $one = false, $more = false, $post_id = 0 ) {
   883 		_deprecated_argument( __FUNCTION__, '1.3.0' );
   887 	echo get_comments_number_text( $zero, $one, $more, $post_id );
   884 	}
   888 }
   885 	echo get_comments_number_text( $zero, $one, $more );
   889 
   886 }
   890 /**
   887 
   891  * Displays the language string for the number of comments the current post has.
   888 /**
       
   889  * Display the language string for the number of comments the current post has.
       
   890  *
   892  *
   891  * @since 4.0.0
   893  * @since 4.0.0
   892  *
   894  * @since 5.4.0 Added the `$post_id` parameter to allow using the function outside of the loop.
   893  * @param string $zero Optional. Text for no comments. Default false.
   895  *
   894  * @param string $one  Optional. Text for one comment. Default false.
   896  * @param string      $zero    Optional. Text for no comments. Default false.
   895  * @param string $more Optional. Text for more than one comment. Default false.
   897  * @param string      $one     Optional. Text for one comment. Default false.
   896  */
   898  * @param string      $more    Optional. Text for more than one comment. Default false.
   897 function get_comments_number_text( $zero = false, $one = false, $more = false ) {
   899  * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`.
   898 	$number = get_comments_number();
   900  * @return string Language string for the number of comments a post has.
       
   901  */
       
   902 function get_comments_number_text( $zero = false, $one = false, $more = false, $post_id = 0 ) {
       
   903 	$number = get_comments_number( $post_id );
   899 
   904 
   900 	if ( $number > 1 ) {
   905 	if ( $number > 1 ) {
   901 		if ( false === $more ) {
   906 		if ( false === $more ) {
   902 			/* translators: %s: number of comments */
   907 			/* translators: %s: Number of comments. */
   903 			$output = sprintf( _n( '%s Comment', '%s Comments', $number ), number_format_i18n( $number ) );
   908 			$output = sprintf( _n( '%s Comment', '%s Comments', $number ), number_format_i18n( $number ) );
   904 		} else {
   909 		} else {
   905 			// % Comments
   910 			// % Comments
   906 			/* translators: If comment number in your language requires declension,
   911 			/*
       
   912 			 * translators: If comment number in your language requires declension,
   907 			 * translate this to 'on'. Do not translate into your own language.
   913 			 * translate this to 'on'. Do not translate into your own language.
   908 			 */
   914 			 */
   909 			if ( 'on' === _x( 'off', 'Comment number declension: on or off' ) ) {
   915 			if ( 'on' === _x( 'off', 'Comment number declension: on or off' ) ) {
   910 				$text = preg_replace( '#<span class="screen-reader-text">.+?</span>#', '', $more );
   916 				$text = preg_replace( '#<span class="screen-reader-text">.+?</span>#', '', $more );
   911 				$text = preg_replace( '/&.+?;/', '', $text ); // Kill entities
   917 				$text = preg_replace( '/&.+?;/', '', $text ); // Kill entities.
   912 				$text = trim( strip_tags( $text ), '% ' );
   918 				$text = trim( strip_tags( $text ), '% ' );
   913 
   919 
   914 				// Replace '% Comments' with a proper plural form
   920 				// Replace '% Comments' with a proper plural form.
   915 				if ( $text && ! preg_match( '/[0-9]+/', $text ) && false !== strpos( $more, '%' ) ) {
   921 				if ( $text && ! preg_match( '/[0-9]+/', $text ) && false !== strpos( $more, '%' ) ) {
   916 					/* translators: %s: number of comments */
   922 					/* translators: %s: Number of comments. */
   917 					$new_text = _n( '%s Comment', '%s Comments', $number );
   923 					$new_text = _n( '%s Comment', '%s Comments', $number );
   918 					$new_text = trim( sprintf( $new_text, '' ) );
   924 					$new_text = trim( sprintf( $new_text, '' ) );
   919 
   925 
   920 					$more = str_replace( $text, $new_text, $more );
   926 					$more = str_replace( $text, $new_text, $more );
   921 					if ( false === strpos( $more, '%' ) ) {
   927 					if ( false === strpos( $more, '%' ) ) {
   924 				}
   930 				}
   925 			}
   931 			}
   926 
   932 
   927 			$output = str_replace( '%', number_format_i18n( $number ), $more );
   933 			$output = str_replace( '%', number_format_i18n( $number ), $more );
   928 		}
   934 		}
   929 	} elseif ( $number == 0 ) {
   935 	} elseif ( 0 == $number ) {
   930 		$output = ( false === $zero ) ? __( 'No Comments' ) : $zero;
   936 		$output = ( false === $zero ) ? __( 'No Comments' ) : $zero;
   931 	} else { // must be one
   937 	} else { // Must be one.
   932 		$output = ( false === $one ) ? __( '1 Comment' ) : $one;
   938 		$output = ( false === $one ) ? __( '1 Comment' ) : $one;
   933 	}
   939 	}
   934 	/**
   940 	/**
   935 	 * Filters the comments count for display.
   941 	 * Filters the comments count for display.
   936 	 *
   942 	 *
   944 	 */
   950 	 */
   945 	return apply_filters( 'comments_number', $output, $number );
   951 	return apply_filters( 'comments_number', $output, $number );
   946 }
   952 }
   947 
   953 
   948 /**
   954 /**
   949  * Retrieve the text of the current comment.
   955  * Retrieves the text of the current comment.
   950  *
   956  *
   951  * @since 1.5.0
   957  * @since 1.5.0
   952  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   958  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
       
   959  * @since 5.4.0 Added 'In reply to %s.' prefix to child comments in comments feed.
   953  *
   960  *
   954  * @see Walker_Comment::comment()
   961  * @see Walker_Comment::comment()
   955  *
   962  *
   956  * @param int|WP_Comment  $comment_ID WP_Comment or ID of the comment for which to get the text.
   963  * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the text.
   957  *                                    Default current comment.
   964  *                                   Default current comment.
   958  * @param array           $args       Optional. An array of arguments. Default empty.
   965  * @param array          $args       Optional. An array of arguments. Default empty array.
   959  * @return string The comment content.
   966  * @return string The comment content.
   960  */
   967  */
   961 function get_comment_text( $comment_ID = 0, $args = array() ) {
   968 function get_comment_text( $comment_ID = 0, $args = array() ) {
   962 	$comment = get_comment( $comment_ID );
   969 	$comment = get_comment( $comment_ID );
       
   970 
       
   971 	$comment_content = $comment->comment_content;
       
   972 
       
   973 	if ( is_comment_feed() && $comment->comment_parent ) {
       
   974 		$parent = get_comment( $comment->comment_parent );
       
   975 		if ( $parent ) {
       
   976 			$parent_link = esc_url( get_comment_link( $parent ) );
       
   977 			$name        = get_comment_author( $parent );
       
   978 
       
   979 			$comment_content = sprintf(
       
   980 				/* translators: %s: Comment link. */
       
   981 				ent2ncr( __( 'In reply to %s.' ) ),
       
   982 				'<a href="' . $parent_link . '">' . $name . '</a>'
       
   983 			) . "\n\n" . $comment_content;
       
   984 		}
       
   985 	}
   963 
   986 
   964 	/**
   987 	/**
   965 	 * Filters the text of a comment.
   988 	 * Filters the text of a comment.
   966 	 *
   989 	 *
   967 	 * @since 1.5.0
   990 	 * @since 1.5.0
   970 	 *
   993 	 *
   971 	 * @param string     $comment_content Text of the comment.
   994 	 * @param string     $comment_content Text of the comment.
   972 	 * @param WP_Comment $comment         The comment object.
   995 	 * @param WP_Comment $comment         The comment object.
   973 	 * @param array      $args            An array of arguments.
   996 	 * @param array      $args            An array of arguments.
   974 	 */
   997 	 */
   975 	return apply_filters( 'get_comment_text', $comment->comment_content, $comment, $args );
   998 	return apply_filters( 'get_comment_text', $comment_content, $comment, $args );
   976 }
   999 }
   977 
  1000 
   978 /**
  1001 /**
   979  * Display the text of the current comment.
  1002  * Displays the text of the current comment.
   980  *
  1003  *
   981  * @since 0.71
  1004  * @since 0.71
   982  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
  1005  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
   983  *
  1006  *
   984  * @see Walker_Comment::comment()
  1007  * @see Walker_Comment::comment()
   985  *
  1008  *
   986  * @param int|WP_Comment  $comment_ID WP_Comment or ID of the comment for which to print the text.
  1009  * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the text.
   987  *                                    Default current comment.
  1010  *                                   Default current comment.
   988  * @param array           $args       Optional. An array of arguments. Default empty array. Default empty.
  1011  * @param array          $args       Optional. An array of arguments. Default empty array.
   989  */
  1012  */
   990 function comment_text( $comment_ID = 0, $args = array() ) {
  1013 function comment_text( $comment_ID = 0, $args = array() ) {
   991 	$comment = get_comment( $comment_ID );
  1014 	$comment = get_comment( $comment_ID );
   992 
  1015 
   993 	$comment_text = get_comment_text( $comment, $args );
  1016 	$comment_text = get_comment_text( $comment, $args );
   997 	 * @since 1.2.0
  1020 	 * @since 1.2.0
   998 	 *
  1021 	 *
   999 	 * @see Walker_Comment::comment()
  1022 	 * @see Walker_Comment::comment()
  1000 	 *
  1023 	 *
  1001 	 * @param string          $comment_text Text of the current comment.
  1024 	 * @param string          $comment_text Text of the current comment.
  1002 	 * @param WP_Comment|null $comment      The comment object.
  1025 	 * @param WP_Comment|null $comment      The comment object. Null if not found.
  1003 	 * @param array           $args         An array of arguments.
  1026 	 * @param array           $args         An array of arguments.
  1004 	 */
  1027 	 */
  1005 	echo apply_filters( 'comment_text', $comment_text, $comment, $args );
  1028 	echo apply_filters( 'comment_text', $comment_text, $comment, $args );
  1006 }
  1029 }
  1007 
  1030 
  1008 /**
  1031 /**
  1009  * Retrieve the comment time of the current comment.
  1032  * Retrieves the comment time of the current comment.
  1010  *
  1033  *
  1011  * @since 1.5.0
  1034  * @since 1.5.0
  1012  *
  1035  *
  1013  * @param string $d         Optional. The format of the time. Default user's settings.
  1036  * @param string $format    Optional. The format of the time. Default user's settings.
  1014  * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
  1037  * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
  1015  * @param bool   $translate Optional. Whether to translate the time (for use in feeds).
  1038  * @param bool   $translate Optional. Whether to translate the time (for use in feeds).
  1016  *                          Default true.
  1039  *                          Default true.
  1017  * @return string The formatted time.
  1040  * @return string The formatted time.
  1018  */
  1041  */
  1019 function get_comment_time( $d = '', $gmt = false, $translate = true ) {
  1042 function get_comment_time( $format = '', $gmt = false, $translate = true ) {
  1020 	$comment = get_comment();
  1043 	$comment = get_comment();
  1021 
  1044 
  1022 	$comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
  1045 	$comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
  1023 	if ( '' == $d ) {
  1046 
  1024 		$date = mysql2date( get_option( 'time_format' ), $comment_date, $translate );
  1047 	$_format = ! empty( $format ) ? $format : get_option( 'time_format' );
  1025 	} else {
  1048 
  1026 		$date = mysql2date( $d, $comment_date, $translate );
  1049 	$date = mysql2date( $_format, $comment_date, $translate );
  1027 	}
       
  1028 
  1050 
  1029 	/**
  1051 	/**
  1030 	 * Filters the returned comment time.
  1052 	 * Filters the returned comment time.
  1031 	 *
  1053 	 *
  1032 	 * @since 1.5.0
  1054 	 * @since 1.5.0
  1033 	 *
  1055 	 *
  1034 	 * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
  1056 	 * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
  1035 	 * @param string     $d         Date format.
  1057 	 * @param string     $format    Date format.
  1036 	 * @param bool       $gmt       Whether the GMT date is in use.
  1058 	 * @param bool       $gmt       Whether the GMT date is in use.
  1037 	 * @param bool       $translate Whether the time is translated.
  1059 	 * @param bool       $translate Whether the time is translated.
  1038 	 * @param WP_Comment $comment   The comment object.
  1060 	 * @param WP_Comment $comment   The comment object.
  1039 	 */
  1061 	 */
  1040 	return apply_filters( 'get_comment_time', $date, $d, $gmt, $translate, $comment );
  1062 	return apply_filters( 'get_comment_time', $date, $format, $gmt, $translate, $comment );
  1041 }
  1063 }
  1042 
  1064 
  1043 /**
  1065 /**
  1044  * Display the comment time of the current comment.
  1066  * Displays the comment time of the current comment.
  1045  *
  1067  *
  1046  * @since 0.71
  1068  * @since 0.71
  1047  *
  1069  *
  1048  * @param string $d Optional. The format of the time. Default user's settings.
  1070  * @param string $format Optional. The format of the time. Default user's settings.
  1049  */
  1071  */
  1050 function comment_time( $d = '' ) {
  1072 function comment_time( $format = '' ) {
  1051 	echo get_comment_time( $d );
  1073 	echo get_comment_time( $format );
  1052 }
  1074 }
  1053 
  1075 
  1054 /**
  1076 /**
  1055  * Retrieve the comment type of the current comment.
  1077  * Retrieves the comment type of the current comment.
  1056  *
  1078  *
  1057  * @since 1.5.0
  1079  * @since 1.5.0
  1058  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
  1080  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
  1059  *
  1081  *
  1060  * @param int|WP_Comment $comment_ID Optional. WP_Comment or ID of the comment for which to get the type.
  1082  * @param int|WP_Comment $comment_ID Optional. WP_Comment or ID of the comment for which to get the type.
  1061  *                                   Default current comment.
  1083  *                                   Default current comment.
  1062  * @return string The comment type.
  1084  * @return string The comment type.
  1063  */
  1085  */
  1064 function get_comment_type( $comment_ID = 0 ) {
  1086 function get_comment_type( $comment_ID = 0 ) {
  1065 	$comment = get_comment( $comment_ID );
  1087 	$comment = get_comment( $comment_ID );
  1066 	if ( '' == $comment->comment_type ) {
  1088 
       
  1089 	if ( '' === $comment->comment_type ) {
  1067 		$comment->comment_type = 'comment';
  1090 		$comment->comment_type = 'comment';
  1068 	}
  1091 	}
  1069 
  1092 
  1070 	/**
  1093 	/**
  1071 	 * Filters the returned comment type.
  1094 	 * Filters the returned comment type.
  1079 	 */
  1102 	 */
  1080 	return apply_filters( 'get_comment_type', $comment->comment_type, $comment->comment_ID, $comment );
  1103 	return apply_filters( 'get_comment_type', $comment->comment_type, $comment->comment_ID, $comment );
  1081 }
  1104 }
  1082 
  1105 
  1083 /**
  1106 /**
  1084  * Display the comment type of the current comment.
  1107  * Displays the comment type of the current comment.
  1085  *
  1108  *
  1086  * @since 0.71
  1109  * @since 0.71
  1087  *
  1110  *
  1088  * @param string $commenttxt   Optional. String to display for comment type. Default false.
  1111  * @param string $commenttxt   Optional. String to display for comment type. Default false.
  1089  * @param string $trackbacktxt Optional. String to display for trackback type. Default false.
  1112  * @param string $trackbacktxt Optional. String to display for trackback type. Default false.
  1111 			echo $commenttxt;
  1134 			echo $commenttxt;
  1112 	}
  1135 	}
  1113 }
  1136 }
  1114 
  1137 
  1115 /**
  1138 /**
  1116  * Retrieve The current post's trackback URL.
  1139  * Retrieves the current post's trackback URL.
  1117  *
  1140  *
  1118  * There is a check to see if permalink's have been enabled and if so, will
  1141  * There is a check to see if permalink's have been enabled and if so, will
  1119  * retrieve the pretty path. If permalinks weren't enabled, the ID of the
  1142  * retrieve the pretty path. If permalinks weren't enabled, the ID of the
  1120  * current post is used and appended to the correct page to go to.
  1143  * current post is used and appended to the correct page to go to.
  1121  *
  1144  *
  1122  * @since 1.5.0
  1145  * @since 1.5.0
  1123  *
  1146  *
  1124  * @return string The trackback URL after being filtered.
  1147  * @return string The trackback URL after being filtered.
  1125  */
  1148  */
  1126 function get_trackback_url() {
  1149 function get_trackback_url() {
  1127 	if ( '' != get_option( 'permalink_structure' ) ) {
  1150 	if ( get_option( 'permalink_structure' ) ) {
  1128 		$tb_url = trailingslashit( get_permalink() ) . user_trailingslashit( 'trackback', 'single_trackback' );
  1151 		$tb_url = trailingslashit( get_permalink() ) . user_trailingslashit( 'trackback', 'single_trackback' );
  1129 	} else {
  1152 	} else {
  1130 		$tb_url = get_option( 'siteurl' ) . '/wp-trackback.php?p=' . get_the_ID();
  1153 		$tb_url = get_option( 'siteurl' ) . '/wp-trackback.php?p=' . get_the_ID();
  1131 	}
  1154 	}
  1132 
  1155 
  1139 	 */
  1162 	 */
  1140 	return apply_filters( 'trackback_url', $tb_url );
  1163 	return apply_filters( 'trackback_url', $tb_url );
  1141 }
  1164 }
  1142 
  1165 
  1143 /**
  1166 /**
  1144  * Display the current post's trackback URL.
  1167  * Displays the current post's trackback URL.
  1145  *
  1168  *
  1146  * @since 0.71
  1169  * @since 0.71
  1147  *
  1170  *
  1148  * @param bool $deprecated_echo Not used.
  1171  * @param bool $deprecated_echo Not used.
  1149  * @return void|string Should only be used to echo the trackback URL, use get_trackback_url()
  1172  * @return void|string Should only be used to echo the trackback URL, use get_trackback_url()
  1152 function trackback_url( $deprecated_echo = true ) {
  1175 function trackback_url( $deprecated_echo = true ) {
  1153 	if ( true !== $deprecated_echo ) {
  1176 	if ( true !== $deprecated_echo ) {
  1154 		_deprecated_argument(
  1177 		_deprecated_argument(
  1155 			__FUNCTION__,
  1178 			__FUNCTION__,
  1156 			'2.5.0',
  1179 			'2.5.0',
  1157 			/* translators: %s: get_trackback_url() */
       
  1158 			sprintf(
  1180 			sprintf(
       
  1181 				/* translators: %s: get_trackback_url() */
  1159 				__( 'Use %s instead if you do not want the value echoed.' ),
  1182 				__( 'Use %s instead if you do not want the value echoed.' ),
  1160 				'<code>get_trackback_url()</code>'
  1183 				'<code>get_trackback_url()</code>'
  1161 			)
  1184 			)
  1162 		);
  1185 		);
  1163 	}
  1186 	}
  1168 		return get_trackback_url();
  1191 		return get_trackback_url();
  1169 	}
  1192 	}
  1170 }
  1193 }
  1171 
  1194 
  1172 /**
  1195 /**
  1173  * Generate and display the RDF for the trackback information of current post.
  1196  * Generates and displays the RDF for the trackback information of current post.
  1174  *
  1197  *
  1175  * Deprecated in 3.0.0, and restored in 3.0.1.
  1198  * Deprecated in 3.0.0, and restored in 3.0.1.
  1176  *
  1199  *
  1177  * @since 0.71
  1200  * @since 0.71
  1178  *
  1201  *
  1216 function comments_open( $post_id = null ) {
  1239 function comments_open( $post_id = null ) {
  1217 
  1240 
  1218 	$_post = get_post( $post_id );
  1241 	$_post = get_post( $post_id );
  1219 
  1242 
  1220 	$post_id = $_post ? $_post->ID : 0;
  1243 	$post_id = $_post ? $_post->ID : 0;
  1221 	$open    = ( 'open' == $_post->comment_status );
  1244 	$open    = ( 'open' === $_post->comment_status );
  1222 
  1245 
  1223 	/**
  1246 	/**
  1224 	 * Filters whether the current post is open for comments.
  1247 	 * Filters whether the current post is open for comments.
  1225 	 *
  1248 	 *
  1226 	 * @since 2.5.0
  1249 	 * @since 2.5.0
  1246 function pings_open( $post_id = null ) {
  1269 function pings_open( $post_id = null ) {
  1247 
  1270 
  1248 	$_post = get_post( $post_id );
  1271 	$_post = get_post( $post_id );
  1249 
  1272 
  1250 	$post_id = $_post ? $_post->ID : 0;
  1273 	$post_id = $_post ? $_post->ID : 0;
  1251 	$open    = ( 'open' == $_post->ping_status );
  1274 	$open    = ( 'open' === $_post->ping_status );
  1252 
  1275 
  1253 	/**
  1276 	/**
  1254 	 * Filters whether the current post is open for pings.
  1277 	 * Filters whether the current post is open for pings.
  1255 	 *
  1278 	 *
  1256 	 * @since 2.5.0
  1279 	 * @since 2.5.0
  1260 	 */
  1283 	 */
  1261 	return apply_filters( 'pings_open', $open, $post_id );
  1284 	return apply_filters( 'pings_open', $open, $post_id );
  1262 }
  1285 }
  1263 
  1286 
  1264 /**
  1287 /**
  1265  * Display form token for unfiltered comments.
  1288  * Displays form token for unfiltered comments.
  1266  *
  1289  *
  1267  * Will only display nonce token if the current user has permissions for
  1290  * Will only display nonce token if the current user has permissions for
  1268  * unfiltered html. Won't display the token for other users.
  1291  * unfiltered html. Won't display the token for other users.
  1269  *
  1292  *
  1270  * The function was backported to 2.0.10 and was added to versions 2.1.3 and
  1293  * The function was backported to 2.0.10 and was added to versions 2.1.3 and
  1284 		echo "<script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>\n";
  1307 		echo "<script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>\n";
  1285 	}
  1308 	}
  1286 }
  1309 }
  1287 
  1310 
  1288 /**
  1311 /**
  1289  * Load the comment template specified in $file.
  1312  * Loads the comment template specified in $file.
  1290  *
  1313  *
  1291  * Will not display the comments template if not on single post or page, or if
  1314  * Will not display the comments template if not on single post or page, or if
  1292  * the post does not have comments.
  1315  * the post does not have comments.
  1293  *
  1316  *
  1294  * Uses the WordPress database object to query for the comments. The comments
  1317  * Uses the WordPress database object to query for the comments. The comments
  1303  *
  1326  *
  1304  * Will not try to get the comments if the post has none.
  1327  * Will not try to get the comments if the post has none.
  1305  *
  1328  *
  1306  * @since 1.5.0
  1329  * @since 1.5.0
  1307  *
  1330  *
  1308  * @global WP_Query   $wp_query
  1331  * @global WP_Query   $wp_query         WordPress Query object.
  1309  * @global WP_Post    $post
  1332  * @global WP_Post    $post             Global post object.
  1310  * @global wpdb       $wpdb
  1333  * @global wpdb       $wpdb             WordPress database abstraction object.
  1311  * @global int        $id
  1334  * @global int        $id
  1312  * @global WP_Comment $comment
  1335  * @global WP_Comment $comment          Global comment object.
  1313  * @global string     $user_login
  1336  * @global string     $user_login
  1314  * @global int        $user_ID
       
  1315  * @global string     $user_identity
  1337  * @global string     $user_identity
  1316  * @global bool       $overridden_cpage
  1338  * @global bool       $overridden_cpage
  1317  * @global bool       $withcomments
  1339  * @global bool       $withcomments
  1318  *
  1340  *
  1319  * @param string $file              Optional. The file to load. Default '/comments.php'.
  1341  * @param string $file              Optional. The file to load. Default '/comments.php'.
  1320  * @param bool   $separate_comments Optional. Whether to separate the comments by comment type.
  1342  * @param bool   $separate_comments Optional. Whether to separate the comments by comment type.
  1321  *                                  Default false.
  1343  *                                  Default false.
  1322  */
  1344  */
  1323 function comments_template( $file = '/comments.php', $separate_comments = false ) {
  1345 function comments_template( $file = '/comments.php', $separate_comments = false ) {
  1324 	global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;
  1346 	global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage;
  1325 
  1347 
  1326 	if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) {
  1348 	if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) {
  1327 		return;
  1349 		return;
  1328 	}
  1350 	}
  1329 
  1351 
  1349 	 * Escaped by sanitize_comment_cookies().
  1371 	 * Escaped by sanitize_comment_cookies().
  1350 	 */
  1372 	 */
  1351 	$comment_author_email = $commenter['comment_author_email'];
  1373 	$comment_author_email = $commenter['comment_author_email'];
  1352 
  1374 
  1353 	/*
  1375 	/*
  1354 	 * The url of the current comment author escaped for use in attributes.
  1376 	 * The URL of the current comment author escaped for use in attributes.
  1355 	 */
  1377 	 */
  1356 	$comment_author_url = esc_url( $commenter['comment_author_url'] );
  1378 	$comment_author_url = esc_url( $commenter['comment_author_url'] );
  1357 
  1379 
  1358 	$comment_args = array(
  1380 	$comment_args = array(
  1359 		'orderby'                   => 'comment_date_gmt',
  1381 		'orderby'                   => 'comment_date_gmt',
  1368 		$comment_args['hierarchical'] = 'threaded';
  1390 		$comment_args['hierarchical'] = 'threaded';
  1369 	} else {
  1391 	} else {
  1370 		$comment_args['hierarchical'] = false;
  1392 		$comment_args['hierarchical'] = false;
  1371 	}
  1393 	}
  1372 
  1394 
  1373 	if ( $user_ID ) {
  1395 	if ( is_user_logged_in() ) {
  1374 		$comment_args['include_unapproved'] = array( $user_ID );
  1396 		$comment_args['include_unapproved'] = array( get_current_user_id() );
  1375 	} else {
  1397 	} else {
  1376 		$unapproved_email = wp_get_unapproved_comment_author_email();
  1398 		$unapproved_email = wp_get_unapproved_comment_author_email();
  1377 
  1399 
  1378 		if ( $unapproved_email ) {
  1400 		if ( $unapproved_email ) {
  1379 			$comment_args['include_unapproved'] = array( $unapproved_email );
  1401 			$comment_args['include_unapproved'] = array( $unapproved_email );
  1486 	} else {
  1508 	} else {
  1487 		$wp_query->comments_by_type = array();
  1509 		$wp_query->comments_by_type = array();
  1488 	}
  1510 	}
  1489 
  1511 
  1490 	$overridden_cpage = false;
  1512 	$overridden_cpage = false;
       
  1513 
  1491 	if ( '' == get_query_var( 'cpage' ) && $wp_query->max_num_comment_pages > 1 ) {
  1514 	if ( '' == get_query_var( 'cpage' ) && $wp_query->max_num_comment_pages > 1 ) {
  1492 		set_query_var( 'cpage', 'newest' == get_option( 'default_comments_page' ) ? get_comment_pages_count() : 1 );
  1515 		set_query_var( 'cpage', 'newest' === get_option( 'default_comments_page' ) ? get_comment_pages_count() : 1 );
  1493 		$overridden_cpage = true;
  1516 		$overridden_cpage = true;
  1494 	}
  1517 	}
  1495 
  1518 
  1496 	if ( ! defined( 'COMMENTS_TEMPLATE' ) ) {
  1519 	if ( ! defined( 'COMMENTS_TEMPLATE' ) ) {
  1497 		define( 'COMMENTS_TEMPLATE', true );
  1520 		define( 'COMMENTS_TEMPLATE', true );
  1498 	}
  1521 	}
  1499 
  1522 
  1500 	$theme_template = STYLESHEETPATH . $file;
  1523 	$theme_template = STYLESHEETPATH . $file;
       
  1524 
  1501 	/**
  1525 	/**
  1502 	 * Filters the path to the theme template file used for the comments template.
  1526 	 * Filters the path to the theme template file used for the comments template.
  1503 	 *
  1527 	 *
  1504 	 * @since 1.5.1
  1528 	 * @since 1.5.1
  1505 	 *
  1529 	 *
  1506 	 * @param string $theme_template The path to the theme template file.
  1530 	 * @param string $theme_template The path to the theme template file.
  1507 	 */
  1531 	 */
  1508 	$include = apply_filters( 'comments_template', $theme_template );
  1532 	$include = apply_filters( 'comments_template', $theme_template );
       
  1533 
  1509 	if ( file_exists( $include ) ) {
  1534 	if ( file_exists( $include ) ) {
  1510 		require( $include );
  1535 		require $include;
  1511 	} elseif ( file_exists( TEMPLATEPATH . $file ) ) {
  1536 	} elseif ( file_exists( TEMPLATEPATH . $file ) ) {
  1512 		require( TEMPLATEPATH . $file );
  1537 		require TEMPLATEPATH . $file;
  1513 	} else { // Backward compat code will be removed in a future release
  1538 	} else { // Backward compat code will be removed in a future release.
  1514 		require( ABSPATH . WPINC . '/theme-compat/comments.php' );
  1539 		require ABSPATH . WPINC . '/theme-compat/comments.php';
  1515 	}
  1540 	}
  1516 }
  1541 }
  1517 
  1542 
  1518 /**
  1543 /**
  1519  * Displays the link to the comments for the current post ID.
  1544  * Displays the link to the comments for the current post ID.
  1525  * @param false|string $more      Optional. String to display when there are more than one comment. Default false.
  1550  * @param false|string $more      Optional. String to display when there are more than one comment. Default false.
  1526  * @param string       $css_class Optional. CSS class to use for comments. Default empty.
  1551  * @param string       $css_class Optional. CSS class to use for comments. Default empty.
  1527  * @param false|string $none      Optional. String to display when comments have been turned off. Default false.
  1552  * @param false|string $none      Optional. String to display when comments have been turned off. Default false.
  1528  */
  1553  */
  1529 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
  1554 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
  1530 	$id     = get_the_ID();
  1555 	$post_id    = get_the_ID();
  1531 	$title  = get_the_title();
  1556 	$post_title = get_the_title();
  1532 	$number = get_comments_number( $id );
  1557 	$number     = get_comments_number( $post_id );
  1533 
  1558 
  1534 	if ( false === $zero ) {
  1559 	if ( false === $zero ) {
  1535 		/* translators: %s: post title */
  1560 		/* translators: %s: Post title. */
  1536 		$zero = sprintf( __( 'No Comments<span class="screen-reader-text"> on %s</span>' ), $title );
  1561 		$zero = sprintf( __( 'No Comments<span class="screen-reader-text"> on %s</span>' ), $post_title );
  1537 	}
  1562 	}
  1538 
  1563 
  1539 	if ( false === $one ) {
  1564 	if ( false === $one ) {
  1540 		/* translators: %s: post title */
  1565 		/* translators: %s: Post title. */
  1541 		$one = sprintf( __( '1 Comment<span class="screen-reader-text"> on %s</span>' ), $title );
  1566 		$one = sprintf( __( '1 Comment<span class="screen-reader-text"> on %s</span>' ), $post_title );
  1542 	}
  1567 	}
  1543 
  1568 
  1544 	if ( false === $more ) {
  1569 	if ( false === $more ) {
  1545 		/* translators: 1: number of comments, 2: post title */
  1570 		/* translators: 1: Number of comments, 2: Post title. */
  1546 		$more = _n( '%1$s Comment<span class="screen-reader-text"> on %2$s</span>', '%1$s Comments<span class="screen-reader-text"> on %2$s</span>', $number );
  1571 		$more = _n( '%1$s Comment<span class="screen-reader-text"> on %2$s</span>', '%1$s Comments<span class="screen-reader-text"> on %2$s</span>', $number );
  1547 		$more = sprintf( $more, number_format_i18n( $number ), $title );
  1572 		$more = sprintf( $more, number_format_i18n( $number ), $post_title );
  1548 	}
  1573 	}
  1549 
  1574 
  1550 	if ( false === $none ) {
  1575 	if ( false === $none ) {
  1551 		/* translators: %s: post title */
  1576 		/* translators: %s: Post title. */
  1552 		$none = sprintf( __( 'Comments Off<span class="screen-reader-text"> on %s</span>' ), $title );
  1577 		$none = sprintf( __( 'Comments Off<span class="screen-reader-text"> on %s</span>' ), $post_title );
  1553 	}
  1578 	}
  1554 
  1579 
  1555 	if ( 0 == $number && ! comments_open() && ! pings_open() ) {
  1580 	if ( 0 == $number && ! comments_open() && ! pings_open() ) {
  1556 		echo '<span' . ( ( ! empty( $css_class ) ) ? ' class="' . esc_attr( $css_class ) . '"' : '' ) . '>' . $none . '</span>';
  1581 		echo '<span' . ( ( ! empty( $css_class ) ) ? ' class="' . esc_attr( $css_class ) . '"' : '' ) . '>' . $none . '</span>';
  1557 		return;
  1582 		return;
  1569 		 * Filters the respond link when a post has no comments.
  1594 		 * Filters the respond link when a post has no comments.
  1570 		 *
  1595 		 *
  1571 		 * @since 4.4.0
  1596 		 * @since 4.4.0
  1572 		 *
  1597 		 *
  1573 		 * @param string $respond_link The default response link.
  1598 		 * @param string $respond_link The default response link.
  1574 		 * @param integer $id The post ID.
  1599 		 * @param int    $post_id      The post ID.
  1575 		 */
  1600 		 */
  1576 		echo apply_filters( 'respond_link', $respond_link, $id );
  1601 		echo apply_filters( 'respond_link', $respond_link, $post_id );
  1577 	} else {
  1602 	} else {
  1578 		comments_link();
  1603 		comments_link();
  1579 	}
  1604 	}
  1580 	echo '"';
  1605 	echo '"';
  1581 
  1606 
  1597 	comments_number( $zero, $one, $more );
  1622 	comments_number( $zero, $one, $more );
  1598 	echo '</a>';
  1623 	echo '</a>';
  1599 }
  1624 }
  1600 
  1625 
  1601 /**
  1626 /**
  1602  * Retrieve HTML content for reply to comment link.
  1627  * Retrieves HTML content for reply to comment link.
  1603  *
  1628  *
  1604  * @since 2.7.0
  1629  * @since 2.7.0
  1605  * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object.
  1630  * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object.
  1606  *
  1631  *
  1607  * @param array $args {
  1632  * @param array          $args {
  1608  *     Optional. Override default arguments.
  1633  *     Optional. Override default arguments.
  1609  *
  1634  *
  1610  *     @type string $add_below  The first part of the selector used to identify the comment to respond below.
  1635  *     @type string $add_below  The first part of the selector used to identify the comment to respond below.
  1611  *                              The resulting value is passed as the first parameter to addComment.moveForm(),
  1636  *                              The resulting value is passed as the first parameter to addComment.moveForm(),
  1612  *                              concatenated as $add_below-$comment->comment_ID. Default 'comment'.
  1637  *                              concatenated as $add_below-$comment->comment_ID. Default 'comment'.
  1622  *     @type string $after      The text or HTML to add after the reply link. Default empty.
  1647  *     @type string $after      The text or HTML to add after the reply link. Default empty.
  1623  * }
  1648  * }
  1624  * @param int|WP_Comment $comment Comment being replied to. Default current comment.
  1649  * @param int|WP_Comment $comment Comment being replied to. Default current comment.
  1625  * @param int|WP_Post    $post    Post ID or WP_Post object the comment is going to be displayed on.
  1650  * @param int|WP_Post    $post    Post ID or WP_Post object the comment is going to be displayed on.
  1626  *                                Default current post.
  1651  *                                Default current post.
  1627  * @return void|false|string Link to show comment form, if successful. False, if comments are closed.
  1652  * @return string|false|null Link to show comment form, if successful. False, if comments are closed.
  1628  */
  1653  */
  1629 function get_comment_reply_link( $args = array(), $comment = null, $post = null ) {
  1654 function get_comment_reply_link( $args = array(), $comment = null, $post = null ) {
  1630 	$defaults = array(
  1655 	$defaults = array(
  1631 		'add_below'     => 'comment',
  1656 		'add_below'     => 'comment',
  1632 		'respond_id'    => 'respond',
  1657 		'respond_id'    => 'respond',
  1633 		'reply_text'    => __( 'Reply' ),
  1658 		'reply_text'    => __( 'Reply' ),
  1634 		/* translators: Comment reply button text. %s: Comment author name */
  1659 		/* translators: Comment reply button text. %s: Comment author name. */
  1635 		'reply_to_text' => __( 'Reply to %s' ),
  1660 		'reply_to_text' => __( 'Reply to %s' ),
  1636 		'login_text'    => __( 'Log in to Reply' ),
  1661 		'login_text'    => __( 'Log in to Reply' ),
  1637 		'max_depth'     => 0,
  1662 		'max_depth'     => 0,
  1638 		'depth'         => 0,
  1663 		'depth'         => 0,
  1639 		'before'        => '',
  1664 		'before'        => '',
  1645 	if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) {
  1670 	if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) {
  1646 		return;
  1671 		return;
  1647 	}
  1672 	}
  1648 
  1673 
  1649 	$comment = get_comment( $comment );
  1674 	$comment = get_comment( $comment );
       
  1675 
       
  1676 	if ( empty( $comment ) ) {
       
  1677 		return;
       
  1678 	}
  1650 
  1679 
  1651 	if ( empty( $post ) ) {
  1680 	if ( empty( $post ) ) {
  1652 		$post = $comment->comment_post_ID;
  1681 		$post = $comment->comment_post_ID;
  1653 	}
  1682 	}
  1654 
  1683 
  1680 		$data_attributes = array(
  1709 		$data_attributes = array(
  1681 			'commentid'      => $comment->comment_ID,
  1710 			'commentid'      => $comment->comment_ID,
  1682 			'postid'         => $post->ID,
  1711 			'postid'         => $post->ID,
  1683 			'belowelement'   => $args['add_below'] . '-' . $comment->comment_ID,
  1712 			'belowelement'   => $args['add_below'] . '-' . $comment->comment_ID,
  1684 			'respondelement' => $args['respond_id'],
  1713 			'respondelement' => $args['respond_id'],
       
  1714 			'replyto'        => sprintf( $args['reply_to_text'], $comment->comment_author ),
  1685 		);
  1715 		);
  1686 
  1716 
  1687 		$data_attribute_string = '';
  1717 		$data_attribute_string = '';
  1688 
  1718 
  1689 		foreach ( $data_attributes as $name => $value ) {
  1719 		foreach ( $data_attributes as $name => $value ) {
  1698 				add_query_arg(
  1728 				add_query_arg(
  1699 					array(
  1729 					array(
  1700 						'replytocom'      => $comment->comment_ID,
  1730 						'replytocom'      => $comment->comment_ID,
  1701 						'unapproved'      => false,
  1731 						'unapproved'      => false,
  1702 						'moderation-hash' => false,
  1732 						'moderation-hash' => false,
  1703 					)
  1733 					),
       
  1734 					get_permalink( $post->ID )
  1704 				)
  1735 				)
  1705 			) . '#' . $args['respond_id'],
  1736 			) . '#' . $args['respond_id'],
  1706 			$data_attribute_string,
  1737 			$data_attribute_string,
  1707 			esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),
  1738 			esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),
  1708 			$args['reply_text']
  1739 			$args['reply_text']
  1712 	/**
  1743 	/**
  1713 	 * Filters the comment reply link.
  1744 	 * Filters the comment reply link.
  1714 	 *
  1745 	 *
  1715 	 * @since 2.7.0
  1746 	 * @since 2.7.0
  1716 	 *
  1747 	 *
  1717 	 * @param string  $link    The HTML markup for the comment reply link.
  1748 	 * @param string     $link    The HTML markup for the comment reply link.
  1718 	 * @param array   $args    An array of arguments overriding the defaults.
  1749 	 * @param array      $args    An array of arguments overriding the defaults.
  1719 	 * @param object  $comment The object of the comment being replied.
  1750 	 * @param WP_Comment $comment The object of the comment being replied.
  1720 	 * @param WP_Post $post    The WP_Post object.
  1751 	 * @param WP_Post    $post    The WP_Post object.
  1721 	 */
  1752 	 */
  1722 	return apply_filters( 'comment_reply_link', $args['before'] . $link . $args['after'], $args, $comment, $post );
  1753 	return apply_filters( 'comment_reply_link', $args['before'] . $link . $args['after'], $args, $comment, $post );
  1723 }
  1754 }
  1724 
  1755 
  1725 /**
  1756 /**
  1727  *
  1758  *
  1728  * @since 2.7.0
  1759  * @since 2.7.0
  1729  *
  1760  *
  1730  * @see get_comment_reply_link()
  1761  * @see get_comment_reply_link()
  1731  *
  1762  *
  1732  * @param array       $args    Optional. Override default options.
  1763  * @param array          $args    Optional. Override default options. Default empty array.
  1733  * @param int         $comment Comment being replied to. Default current comment.
  1764  * @param int|WP_Comment $comment Comment being replied to. Default current comment.
  1734  * @param int|WP_Post $post    Post ID or WP_Post object the comment is going to be displayed on.
  1765  * @param int|WP_Post    $post    Post ID or WP_Post object the comment is going to be displayed on.
  1735  *                             Default current post.
  1766  *                                Default current post.
  1736  * @return mixed Link to show comment form, if successful. False, if comments are closed.
       
  1737  */
  1767  */
  1738 function comment_reply_link( $args = array(), $comment = null, $post = null ) {
  1768 function comment_reply_link( $args = array(), $comment = null, $post = null ) {
  1739 	echo get_comment_reply_link( $args, $comment, $post );
  1769 	echo get_comment_reply_link( $args, $comment, $post );
  1740 }
  1770 }
  1741 
  1771 
  1742 /**
  1772 /**
  1743  * Retrieve HTML content for reply to post link.
  1773  * Retrieves HTML content for reply to post link.
  1744  *
  1774  *
  1745  * @since 2.7.0
  1775  * @since 2.7.0
  1746  *
  1776  *
  1747  * @param array $args {
  1777  * @param array       $args {
  1748  *     Optional. Override default arguments.
  1778  *     Optional. Override default arguments.
  1749  *
  1779  *
  1750  *     @type string $add_below  The first part of the selector used to identify the comment to respond below.
  1780  *     @type string $add_below  The first part of the selector used to identify the comment to respond below.
  1751  *                              The resulting value is passed as the first parameter to addComment.moveForm(),
  1781  *                              The resulting value is passed as the first parameter to addComment.moveForm(),
  1752  *                              concatenated as $add_below-$comment->comment_ID. Default is 'post'.
  1782  *                              concatenated as $add_below-$comment->comment_ID. Default is 'post'.
  1758  *     @type string $before     Text or HTML to add before the reply link. Default empty.
  1788  *     @type string $before     Text or HTML to add before the reply link. Default empty.
  1759  *     @type string $after      Text or HTML to add after the reply link. Default empty.
  1789  *     @type string $after      Text or HTML to add after the reply link. Default empty.
  1760  * }
  1790  * }
  1761  * @param int|WP_Post $post    Optional. Post ID or WP_Post object the comment is going to be displayed on.
  1791  * @param int|WP_Post $post    Optional. Post ID or WP_Post object the comment is going to be displayed on.
  1762  *                             Default current post.
  1792  *                             Default current post.
  1763  * @return false|null|string Link to show comment form, if successful. False, if comments are closed.
  1793  * @return string|false|null Link to show comment form, if successful. False, if comments are closed.
  1764  */
  1794  */
  1765 function get_post_reply_link( $args = array(), $post = null ) {
  1795 function get_post_reply_link( $args = array(), $post = null ) {
  1766 	$defaults = array(
  1796 	$defaults = array(
  1767 		'add_below'  => 'post',
  1797 		'add_below'  => 'post',
  1768 		'respond_id' => 'respond',
  1798 		'respond_id' => 'respond',
  1819  *
  1849  *
  1820  * @since 2.7.0
  1850  * @since 2.7.0
  1821  *
  1851  *
  1822  * @see get_post_reply_link()
  1852  * @see get_post_reply_link()
  1823  *
  1853  *
  1824  * @param array       $args Optional. Override default options,
  1854  * @param array       $args Optional. Override default options. Default empty array.
  1825  * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
  1855  * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
  1826  *                          Default current post.
  1856  *                          Default current post.
  1827  * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
       
  1828  */
  1857  */
  1829 function post_reply_link( $args = array(), $post = null ) {
  1858 function post_reply_link( $args = array(), $post = null ) {
  1830 	echo get_post_reply_link( $args, $post );
  1859 	echo get_post_reply_link( $args, $post );
  1831 }
  1860 }
  1832 
  1861 
  1833 /**
  1862 /**
  1834  * Retrieve HTML content for cancel comment reply link.
  1863  * Retrieves HTML content for cancel comment reply link.
  1835  *
  1864  *
  1836  * @since 2.7.0
  1865  * @since 2.7.0
  1837  *
  1866  *
  1838  * @param string $text Optional. Text to display for cancel reply link. Default empty.
  1867  * @param string $text Optional. Text to display for cancel reply link. If empty,
       
  1868  *                     defaults to 'Click here to cancel reply'. Default empty.
  1839  * @return string
  1869  * @return string
  1840  */
  1870  */
  1841 function get_cancel_comment_reply_link( $text = '' ) {
  1871 function get_cancel_comment_reply_link( $text = '' ) {
  1842 	if ( empty( $text ) ) {
  1872 	if ( empty( $text ) ) {
  1843 		$text = __( 'Click here to cancel reply.' );
  1873 		$text = __( 'Click here to cancel reply.' );
  1859 	 */
  1889 	 */
  1860 	return apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text );
  1890 	return apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text );
  1861 }
  1891 }
  1862 
  1892 
  1863 /**
  1893 /**
  1864  * Display HTML content for cancel comment reply link.
  1894  * Displays HTML content for cancel comment reply link.
  1865  *
  1895  *
  1866  * @since 2.7.0
  1896  * @since 2.7.0
  1867  *
  1897  *
  1868  * @param string $text Optional. Text to display for cancel reply link. Default empty.
  1898  * @param string $text Optional. Text to display for cancel reply link. If empty,
       
  1899  *                     defaults to 'Click here to cancel reply'. Default empty.
  1869  */
  1900  */
  1870 function cancel_comment_reply_link( $text = '' ) {
  1901 function cancel_comment_reply_link( $text = '' ) {
  1871 	echo get_cancel_comment_reply_link( $text );
  1902 	echo get_cancel_comment_reply_link( $text );
  1872 }
  1903 }
  1873 
  1904 
  1874 /**
  1905 /**
  1875  * Retrieve hidden input HTML for replying to comments.
  1906  * Retrieves hidden input HTML for replying to comments.
  1876  *
  1907  *
  1877  * @since 3.0.0
  1908  * @since 3.0.0
  1878  *
  1909  *
  1879  * @param int $id Optional. Post ID. Default current post ID.
  1910  * @param int $post_id Optional. Post ID. Defaults to the current post ID.
  1880  * @return string Hidden input HTML for replying to comments
  1911  * @return string Hidden input HTML for replying to comments.
  1881  */
  1912  */
  1882 function get_comment_id_fields( $id = 0 ) {
  1913 function get_comment_id_fields( $post_id = 0 ) {
  1883 	if ( empty( $id ) ) {
  1914 	if ( empty( $post_id ) ) {
  1884 		$id = get_the_ID();
  1915 		$post_id = get_the_ID();
  1885 	}
  1916 	}
  1886 
  1917 
  1887 	$replytoid = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0;
  1918 	$reply_to_id = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0;
  1888 	$result    = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";
  1919 	$result      = "<input type='hidden' name='comment_post_ID' value='$post_id' id='comment_post_ID' />\n";
  1889 	$result   .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";
  1920 	$result     .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$reply_to_id' />\n";
  1890 
  1921 
  1891 	/**
  1922 	/**
  1892 	 * Filters the returned comment id fields.
  1923 	 * Filters the returned comment ID fields.
  1893 	 *
  1924 	 *
  1894 	 * @since 3.0.0
  1925 	 * @since 3.0.0
  1895 	 *
  1926 	 *
  1896 	 * @param string $result    The HTML-formatted hidden id field comment elements.
  1927 	 * @param string $result      The HTML-formatted hidden ID field comment elements.
  1897 	 * @param int    $id        The post ID.
  1928 	 * @param int    $post_id     The post ID.
  1898 	 * @param int    $replytoid The id of the comment being replied to.
  1929 	 * @param int    $reply_to_id The ID of the comment being replied to.
  1899 	 */
  1930 	 */
  1900 	return apply_filters( 'comment_id_fields', $result, $id, $replytoid );
  1931 	return apply_filters( 'comment_id_fields', $result, $post_id, $reply_to_id );
  1901 }
  1932 }
  1902 
  1933 
  1903 /**
  1934 /**
  1904  * Output hidden input HTML for replying to comments.
  1935  * Outputs hidden input HTML for replying to comments.
       
  1936  *
       
  1937  * Adds two hidden inputs to the comment form to identify the `comment_post_ID`
       
  1938  * and `comment_parent` values for threaded comments.
       
  1939  *
       
  1940  * This tag must be within the `<form>` section of the `comments.php` template.
  1905  *
  1941  *
  1906  * @since 2.7.0
  1942  * @since 2.7.0
  1907  *
  1943  *
  1908  * @param int $id Optional. Post ID. Default current post ID.
  1944  * @see get_comment_id_fields()
  1909  */
  1945  *
  1910 function comment_id_fields( $id = 0 ) {
  1946  * @param int $post_id Optional. Post ID. Defaults to the current post ID.
  1911 	echo get_comment_id_fields( $id );
  1947  */
  1912 }
  1948 function comment_id_fields( $post_id = 0 ) {
  1913 
  1949 	echo get_comment_id_fields( $post_id );
  1914 /**
  1950 }
  1915  * Display text based on comment reply status.
  1951 
       
  1952 /**
       
  1953  * Displays text based on comment reply status.
  1916  *
  1954  *
  1917  * Only affects users with JavaScript disabled.
  1955  * Only affects users with JavaScript disabled.
  1918  *
  1956  *
  1919  * @internal The $comment global must be present to allow template tags access to the current
  1957  * @internal The $comment global must be present to allow template tags access to the current
  1920  *           comment. See https://core.trac.wordpress.org/changeset/36512.
  1958  *           comment. See https://core.trac.wordpress.org/changeset/36512.
  1921  *
  1959  *
  1922  * @since 2.7.0
  1960  * @since 2.7.0
  1923  *
  1961  *
  1924  * @global WP_Comment $comment Current comment.
  1962  * @global WP_Comment $comment Global comment object.
  1925  *
  1963  *
  1926  * @param string $noreplytext  Optional. Text to display when not replying to a comment.
  1964  * @param string $no_reply_text  Optional. Text to display when not replying to a comment.
  1927  *                             Default false.
  1965  *                               Default false.
  1928  * @param string $replytext    Optional. Text to display when replying to a comment.
  1966  * @param string $reply_text     Optional. Text to display when replying to a comment.
  1929  *                             Default false. Accepts "%s" for the author of the comment
  1967  *                               Default false. Accepts "%s" for the author of the comment
  1930  *                             being replied to.
  1968  *                               being replied to.
  1931  * @param string $linktoparent Optional. Boolean to control making the author's name a link
  1969  * @param string $link_to_parent Optional. Boolean to control making the author's name a link
  1932  *                             to their comment. Default true.
  1970  *                               to their comment. Default true.
  1933  */
  1971  */
  1934 function comment_form_title( $noreplytext = false, $replytext = false, $linktoparent = true ) {
  1972 function comment_form_title( $no_reply_text = false, $reply_text = false, $link_to_parent = true ) {
  1935 	global $comment;
  1973 	global $comment;
  1936 
  1974 
  1937 	if ( false === $noreplytext ) {
  1975 	if ( false === $no_reply_text ) {
  1938 		$noreplytext = __( 'Leave a Reply' );
  1976 		$no_reply_text = __( 'Leave a Reply' );
  1939 	}
  1977 	}
  1940 	if ( false === $replytext ) {
  1978 
  1941 		$replytext = __( 'Leave a Reply to %s' );
  1979 	if ( false === $reply_text ) {
  1942 	}
  1980 		/* translators: %s: Author of the comment being replied to. */
  1943 
  1981 		$reply_text = __( 'Leave a Reply to %s' );
  1944 	$replytoid = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0;
  1982 	}
  1945 
  1983 
  1946 	if ( 0 == $replytoid ) {
  1984 	$reply_to_id = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0;
  1947 		echo $noreplytext;
  1985 
       
  1986 	if ( 0 == $reply_to_id ) {
       
  1987 		echo $no_reply_text;
  1948 	} else {
  1988 	} else {
  1949 		// Sets the global so that template tags can be used in the comment form.
  1989 		// Sets the global so that template tags can be used in the comment form.
  1950 		$comment = get_comment( $replytoid );
  1990 		$comment = get_comment( $reply_to_id );
  1951 		$author  = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $comment ) . '</a>' : get_comment_author( $comment );
  1991 
  1952 		printf( $replytext, $author );
  1992 		if ( $link_to_parent ) {
  1953 	}
  1993 			$author = '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $comment ) . '</a>';
  1954 }
  1994 		} else {
  1955 
  1995 			$author = get_comment_author( $comment );
  1956 /**
  1996 		}
  1957  * List comments.
  1997 
       
  1998 		printf( $reply_text, $author );
       
  1999 	}
       
  2000 }
       
  2001 
       
  2002 /**
       
  2003  * Displays a list of comments.
  1958  *
  2004  *
  1959  * Used in the comments.php template to list comments for a particular post.
  2005  * Used in the comments.php template to list comments for a particular post.
  1960  *
  2006  *
  1961  * @since 2.7.0
  2007  * @since 2.7.0
  1962  *
  2008  *
  1963  * @see WP_Query->comments
  2009  * @see WP_Query->comments
  1964  *
  2010  *
  1965  * @global WP_Query $wp_query
  2011  * @global WP_Query $wp_query           WordPress Query object.
  1966  * @global int      $comment_alt
  2012  * @global int      $comment_alt
  1967  * @global int      $comment_depth
  2013  * @global int      $comment_depth
  1968  * @global int      $comment_thread_alt
  2014  * @global int      $comment_thread_alt
  1969  * @global bool     $overridden_cpage
  2015  * @global bool     $overridden_cpage
  1970  * @global bool     $in_comment_loop
  2016  * @global bool     $in_comment_loop
  1971  *
  2017  *
  1972  * @param string|array $args {
  2018  * @param string|array $args {
  1973  *     Optional. Formatting options.
  2019  *     Optional. Formatting options.
  1974  *
  2020  *
  1975  *     @type object $walker            Instance of a Walker class to list comments. Default null.
  2021  *     @type object   $walker            Instance of a Walker class to list comments. Default null.
  1976  *     @type int    $max_depth         The maximum comments depth. Default empty.
  2022  *     @type int      $max_depth         The maximum comments depth. Default empty.
  1977  *     @type string $style             The style of list ordering. Default 'ul'. Accepts 'ul', 'ol'.
  2023  *     @type string   $style             The style of list ordering. Accepts 'ul', 'ol', or 'div'.
  1978  *     @type string $callback          Callback function to use. Default null.
  2024  *                                       'div' will result in no additional list markup. Default 'ul'.
  1979  *     @type string $end-callback      Callback function to use at the end. Default null.
  2025  *     @type callable $callback          Callback function to use. Default null.
  1980  *     @type string $type              Type of comments to list.
  2026  *     @type callable $end-callback      Callback function to use at the end. Default null.
  1981  *                                     Default 'all'. Accepts 'all', 'comment', 'pingback', 'trackback', 'pings'.
  2027  *     @type string   $type              Type of comments to list. Accepts 'all', 'comment',
  1982  *     @type int    $page              Page ID to list comments for. Default empty.
  2028  *                                       'pingback', 'trackback', 'pings'. Default 'all'.
  1983  *     @type int    $per_page          Number of comments to list per page. Default empty.
  2029  *     @type int      $page              Page ID to list comments for. Default empty.
  1984  *     @type int    $avatar_size       Height and width dimensions of the avatar size. Default 32.
  2030  *     @type int      $per_page          Number of comments to list per page. Default empty.
  1985  *     @type bool   $reverse_top_level Ordering of the listed comments. If true, will display newest comments first.
  2031  *     @type int      $avatar_size       Height and width dimensions of the avatar size. Default 32.
  1986  *     @type bool   $reverse_children  Whether to reverse child comments in the list. Default null.
  2032  *     @type bool     $reverse_top_level Ordering of the listed comments. If true, will display
  1987  *     @type string $format            How to format the comments list.
  2033  *                                       newest comments first. Default null.
  1988  *                                     Default 'html5' if the theme supports it. Accepts 'html5', 'xhtml'.
  2034  *     @type bool     $reverse_children  Whether to reverse child comments in the list. Default null.
  1989  *     @type bool   $short_ping        Whether to output short pings. Default false.
  2035  *     @type string   $format            How to format the comments list. Accepts 'html5', 'xhtml'.
  1990  *     @type bool   $echo              Whether to echo the output or return it. Default true.
  2036  *                                       Default 'html5' if the theme supports it.
       
  2037  *     @type bool     $short_ping        Whether to output short pings. Default false.
       
  2038  *     @type bool     $echo              Whether to echo the output or return it. Default true.
  1991  * }
  2039  * }
  1992  * @param array $comments Optional. Array of WP_Comment objects.
  2040  * @param WP_Comment[] $comments Optional. Array of WP_Comment objects.
       
  2041  * @return void|string Void if 'echo' argument is true, or no comments to list.
       
  2042  *                     Otherwise, HTML list of comments.
  1993  */
  2043  */
  1994 function wp_list_comments( $args = array(), $comments = null ) {
  2044 function wp_list_comments( $args = array(), $comments = null ) {
  1995 	global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
  2045 	global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
  1996 
  2046 
  1997 	$in_comment_loop = true;
  2047 	$in_comment_loop = true;
  1998 
  2048 
  1999 	$comment_alt   = $comment_thread_alt = 0;
  2049 	$comment_alt        = 0;
  2000 	$comment_depth = 1;
  2050 	$comment_thread_alt = 0;
       
  2051 	$comment_depth      = 1;
  2001 
  2052 
  2002 	$defaults = array(
  2053 	$defaults = array(
  2003 		'walker'            => null,
  2054 		'walker'            => null,
  2004 		'max_depth'         => '',
  2055 		'max_depth'         => '',
  2005 		'style'             => 'ul',
  2056 		'style'             => 'ul',
  2014 		'format'            => current_theme_supports( 'html5', 'comment-list' ) ? 'html5' : 'xhtml',
  2065 		'format'            => current_theme_supports( 'html5', 'comment-list' ) ? 'html5' : 'xhtml',
  2015 		'short_ping'        => false,
  2066 		'short_ping'        => false,
  2016 		'echo'              => true,
  2067 		'echo'              => true,
  2017 	);
  2068 	);
  2018 
  2069 
  2019 	$r = wp_parse_args( $args, $defaults );
  2070 	$parsed_args = wp_parse_args( $args, $defaults );
  2020 
  2071 
  2021 	/**
  2072 	/**
  2022 	 * Filters the arguments used in retrieving the comment list.
  2073 	 * Filters the arguments used in retrieving the comment list.
  2023 	 *
  2074 	 *
  2024 	 * @since 4.0.0
  2075 	 * @since 4.0.0
  2025 	 *
  2076 	 *
  2026 	 * @see wp_list_comments()
  2077 	 * @see wp_list_comments()
  2027 	 *
  2078 	 *
  2028 	 * @param array $r An array of arguments for displaying comments.
  2079 	 * @param array $parsed_args An array of arguments for displaying comments.
  2029 	 */
  2080 	 */
  2030 	$r = apply_filters( 'wp_list_comments_args', $r );
  2081 	$parsed_args = apply_filters( 'wp_list_comments_args', $parsed_args );
  2031 
  2082 
  2032 	// Figure out what comments we'll be looping through ($_comments)
  2083 	// Figure out what comments we'll be looping through ($_comments).
  2033 	if ( null !== $comments ) {
  2084 	if ( null !== $comments ) {
  2034 		$comments = (array) $comments;
  2085 		$comments = (array) $comments;
  2035 		if ( empty( $comments ) ) {
  2086 		if ( empty( $comments ) ) {
  2036 			return;
  2087 			return;
  2037 		}
  2088 		}
  2038 		if ( 'all' != $r['type'] ) {
  2089 		if ( 'all' !== $parsed_args['type'] ) {
  2039 			$comments_by_type = separate_comments( $comments );
  2090 			$comments_by_type = separate_comments( $comments );
  2040 			if ( empty( $comments_by_type[ $r['type'] ] ) ) {
  2091 			if ( empty( $comments_by_type[ $parsed_args['type'] ] ) ) {
  2041 				return;
  2092 				return;
  2042 			}
  2093 			}
  2043 			$_comments = $comments_by_type[ $r['type'] ];
  2094 			$_comments = $comments_by_type[ $parsed_args['type'] ];
  2044 		} else {
  2095 		} else {
  2045 			$_comments = $comments;
  2096 			$_comments = $comments;
  2046 		}
  2097 		}
  2047 	} else {
  2098 	} else {
  2048 		/*
  2099 		/*
  2049 		 * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query,
  2100 		 * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query,
  2050 		 * perform a separate comment query and allow Walker_Comment to paginate.
  2101 		 * perform a separate comment query and allow Walker_Comment to paginate.
  2051 		 */
  2102 		 */
  2052 		if ( $r['page'] || $r['per_page'] ) {
  2103 		if ( $parsed_args['page'] || $parsed_args['per_page'] ) {
  2053 			$current_cpage = get_query_var( 'cpage' );
  2104 			$current_cpage = get_query_var( 'cpage' );
  2054 			if ( ! $current_cpage ) {
  2105 			if ( ! $current_cpage ) {
  2055 				$current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages;
  2106 				$current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages;
  2056 			}
  2107 			}
  2057 
  2108 
  2058 			$current_per_page = get_query_var( 'comments_per_page' );
  2109 			$current_per_page = get_query_var( 'comments_per_page' );
  2059 			if ( $r['page'] != $current_cpage || $r['per_page'] != $current_per_page ) {
  2110 			if ( $parsed_args['page'] != $current_cpage || $parsed_args['per_page'] != $current_per_page ) {
  2060 				$comment_args = array(
  2111 				$comment_args = array(
  2061 					'post_id' => get_the_ID(),
  2112 					'post_id' => get_the_ID(),
  2062 					'orderby' => 'comment_date_gmt',
  2113 					'orderby' => 'comment_date_gmt',
  2063 					'order'   => 'ASC',
  2114 					'order'   => 'ASC',
  2064 					'status'  => 'approve',
  2115 					'status'  => 'approve',
  2065 				);
  2116 				);
  2066 
  2117 
  2067 				if ( is_user_logged_in() ) {
  2118 				if ( is_user_logged_in() ) {
  2068 					$comment_args['include_unapproved'] = get_current_user_id();
  2119 					$comment_args['include_unapproved'] = array( get_current_user_id() );
  2069 				} else {
  2120 				} else {
  2070 					$unapproved_email = wp_get_unapproved_comment_author_email();
  2121 					$unapproved_email = wp_get_unapproved_comment_author_email();
  2071 
  2122 
  2072 					if ( $unapproved_email ) {
  2123 					if ( $unapproved_email ) {
  2073 						$comment_args['include_unapproved'] = array( $unapproved_email );
  2124 						$comment_args['include_unapproved'] = array( $unapproved_email );
  2074 					}
  2125 					}
  2075 				}
  2126 				}
  2076 
  2127 
  2077 				$comments = get_comments( $comment_args );
  2128 				$comments = get_comments( $comment_args );
  2078 
  2129 
  2079 				if ( 'all' != $r['type'] ) {
  2130 				if ( 'all' !== $parsed_args['type'] ) {
  2080 					$comments_by_type = separate_comments( $comments );
  2131 					$comments_by_type = separate_comments( $comments );
  2081 					if ( empty( $comments_by_type[ $r['type'] ] ) ) {
  2132 					if ( empty( $comments_by_type[ $parsed_args['type'] ] ) ) {
  2082 						return;
  2133 						return;
  2083 					}
  2134 					}
  2084 
  2135 
  2085 					$_comments = $comments_by_type[ $r['type'] ];
  2136 					$_comments = $comments_by_type[ $parsed_args['type'] ];
  2086 				} else {
  2137 				} else {
  2087 					$_comments = $comments;
  2138 					$_comments = $comments;
  2088 				}
  2139 				}
  2089 			}
  2140 			}
  2090 
  2141 
  2091 			// Otherwise, fall back on the comments from `$wp_query->comments`.
  2142 			// Otherwise, fall back on the comments from `$wp_query->comments`.
  2092 		} else {
  2143 		} else {
  2093 			if ( empty( $wp_query->comments ) ) {
  2144 			if ( empty( $wp_query->comments ) ) {
  2094 				return;
  2145 				return;
  2095 			}
  2146 			}
  2096 			if ( 'all' != $r['type'] ) {
  2147 			if ( 'all' !== $parsed_args['type'] ) {
  2097 				if ( empty( $wp_query->comments_by_type ) ) {
  2148 				if ( empty( $wp_query->comments_by_type ) ) {
  2098 					$wp_query->comments_by_type = separate_comments( $wp_query->comments );
  2149 					$wp_query->comments_by_type = separate_comments( $wp_query->comments );
  2099 				}
  2150 				}
  2100 				if ( empty( $wp_query->comments_by_type[ $r['type'] ] ) ) {
  2151 				if ( empty( $wp_query->comments_by_type[ $parsed_args['type'] ] ) ) {
  2101 					return;
  2152 					return;
  2102 				}
  2153 				}
  2103 				$_comments = $wp_query->comments_by_type[ $r['type'] ];
  2154 				$_comments = $wp_query->comments_by_type[ $parsed_args['type'] ];
  2104 			} else {
  2155 			} else {
  2105 				$_comments = $wp_query->comments;
  2156 				$_comments = $wp_query->comments;
  2106 			}
  2157 			}
  2107 
  2158 
  2108 			if ( $wp_query->max_num_comment_pages ) {
  2159 			if ( $wp_query->max_num_comment_pages ) {
  2109 				$default_comments_page = get_option( 'default_comments_page' );
  2160 				$default_comments_page = get_option( 'default_comments_page' );
  2110 				$cpage                 = get_query_var( 'cpage' );
  2161 				$cpage                 = get_query_var( 'cpage' );
  2111 				if ( 'newest' === $default_comments_page ) {
  2162 				if ( 'newest' === $default_comments_page ) {
  2112 					$r['cpage'] = $cpage;
  2163 					$parsed_args['cpage'] = $cpage;
  2113 
  2164 
  2114 					/*
  2165 					/*
  2115 					* When first page shows oldest comments, post permalink is the same as
  2166 					* When first page shows oldest comments, post permalink is the same as
  2116 					* the comment permalink.
  2167 					* the comment permalink.
  2117 					*/
  2168 					*/
  2118 				} elseif ( $cpage == 1 ) {
  2169 				} elseif ( 1 == $cpage ) {
  2119 					$r['cpage'] = '';
  2170 					$parsed_args['cpage'] = '';
  2120 				} else {
  2171 				} else {
  2121 					$r['cpage'] = $cpage;
  2172 					$parsed_args['cpage'] = $cpage;
  2122 				}
  2173 				}
  2123 
  2174 
  2124 				$r['page']     = 0;
  2175 				$parsed_args['page']     = 0;
  2125 				$r['per_page'] = 0;
  2176 				$parsed_args['per_page'] = 0;
  2126 			}
  2177 			}
  2127 		}
  2178 		}
  2128 	}
  2179 	}
  2129 
  2180 
  2130 	if ( '' === $r['per_page'] && get_option( 'page_comments' ) ) {
  2181 	if ( '' === $parsed_args['per_page'] && get_option( 'page_comments' ) ) {
  2131 		$r['per_page'] = get_query_var( 'comments_per_page' );
  2182 		$parsed_args['per_page'] = get_query_var( 'comments_per_page' );
  2132 	}
  2183 	}
  2133 
  2184 
  2134 	if ( empty( $r['per_page'] ) ) {
  2185 	if ( empty( $parsed_args['per_page'] ) ) {
  2135 		$r['per_page'] = 0;
  2186 		$parsed_args['per_page'] = 0;
  2136 		$r['page']     = 0;
  2187 		$parsed_args['page']     = 0;
  2137 	}
  2188 	}
  2138 
  2189 
  2139 	if ( '' === $r['max_depth'] ) {
  2190 	if ( '' === $parsed_args['max_depth'] ) {
  2140 		if ( get_option( 'thread_comments' ) ) {
  2191 		if ( get_option( 'thread_comments' ) ) {
  2141 			$r['max_depth'] = get_option( 'thread_comments_depth' );
  2192 			$parsed_args['max_depth'] = get_option( 'thread_comments_depth' );
  2142 		} else {
  2193 		} else {
  2143 			$r['max_depth'] = -1;
  2194 			$parsed_args['max_depth'] = -1;
  2144 		}
  2195 		}
  2145 	}
  2196 	}
  2146 
  2197 
  2147 	if ( '' === $r['page'] ) {
  2198 	if ( '' === $parsed_args['page'] ) {
  2148 		if ( empty( $overridden_cpage ) ) {
  2199 		if ( empty( $overridden_cpage ) ) {
  2149 			$r['page'] = get_query_var( 'cpage' );
  2200 			$parsed_args['page'] = get_query_var( 'cpage' );
  2150 		} else {
  2201 		} else {
  2151 			$threaded  = ( -1 != $r['max_depth'] );
  2202 			$threaded            = ( -1 != $parsed_args['max_depth'] );
  2152 			$r['page'] = ( 'newest' == get_option( 'default_comments_page' ) ) ? get_comment_pages_count( $_comments, $r['per_page'], $threaded ) : 1;
  2203 			$parsed_args['page'] = ( 'newest' === get_option( 'default_comments_page' ) ) ? get_comment_pages_count( $_comments, $parsed_args['per_page'], $threaded ) : 1;
  2153 			set_query_var( 'cpage', $r['page'] );
  2204 			set_query_var( 'cpage', $parsed_args['page'] );
  2154 		}
  2205 		}
  2155 	}
  2206 	}
  2156 	// Validation check
  2207 	// Validation check.
  2157 	$r['page'] = intval( $r['page'] );
  2208 	$parsed_args['page'] = intval( $parsed_args['page'] );
  2158 	if ( 0 == $r['page'] && 0 != $r['per_page'] ) {
  2209 	if ( 0 == $parsed_args['page'] && 0 != $parsed_args['per_page'] ) {
  2159 		$r['page'] = 1;
  2210 		$parsed_args['page'] = 1;
  2160 	}
  2211 	}
  2161 
  2212 
  2162 	if ( null === $r['reverse_top_level'] ) {
  2213 	if ( null === $parsed_args['reverse_top_level'] ) {
  2163 		$r['reverse_top_level'] = ( 'desc' == get_option( 'comment_order' ) );
  2214 		$parsed_args['reverse_top_level'] = ( 'desc' === get_option( 'comment_order' ) );
  2164 	}
  2215 	}
  2165 
  2216 
  2166 	wp_queue_comments_for_comment_meta_lazyload( $_comments );
  2217 	wp_queue_comments_for_comment_meta_lazyload( $_comments );
  2167 
  2218 
  2168 	if ( empty( $r['walker'] ) ) {
  2219 	if ( empty( $parsed_args['walker'] ) ) {
  2169 		$walker = new Walker_Comment;
  2220 		$walker = new Walker_Comment;
  2170 	} else {
  2221 	} else {
  2171 		$walker = $r['walker'];
  2222 		$walker = $parsed_args['walker'];
  2172 	}
  2223 	}
  2173 
  2224 
  2174 	$output = $walker->paged_walk( $_comments, $r['max_depth'], $r['page'], $r['per_page'], $r );
  2225 	$output = $walker->paged_walk( $_comments, $parsed_args['max_depth'], $parsed_args['page'], $parsed_args['per_page'], $parsed_args );
  2175 
  2226 
  2176 	$in_comment_loop = false;
  2227 	$in_comment_loop = false;
  2177 
  2228 
  2178 	if ( $r['echo'] ) {
  2229 	if ( $parsed_args['echo'] ) {
  2179 		echo $output;
  2230 		echo $output;
  2180 	} else {
  2231 	} else {
  2181 		return $output;
  2232 		return $output;
  2182 	}
  2233 	}
  2183 }
  2234 }
  2199  *              'cancel_reply_before', and 'cancel_reply_after' arguments.
  2250  *              'cancel_reply_before', and 'cancel_reply_after' arguments.
  2200  * @since 4.5.0 The 'author', 'email', and 'url' form fields are limited to 245, 100,
  2251  * @since 4.5.0 The 'author', 'email', and 'url' form fields are limited to 245, 100,
  2201  *              and 200 characters, respectively.
  2252  *              and 200 characters, respectively.
  2202  * @since 4.6.0 Introduced the 'action' argument.
  2253  * @since 4.6.0 Introduced the 'action' argument.
  2203  * @since 4.9.6 Introduced the 'cookies' default comment field.
  2254  * @since 4.9.6 Introduced the 'cookies' default comment field.
       
  2255  * @since 5.5.0 Introduced the 'class_container' argument.
  2204  *
  2256  *
  2205  * @param array       $args {
  2257  * @param array       $args {
  2206  *     Optional. Default arguments and form fields to override.
  2258  *     Optional. Default arguments and form fields to override.
  2207  *
  2259  *
  2208  *     @type array $fields {
  2260  *     @type array $fields {
  2221  *                                        Default 'Your email address will not be published.'.
  2273  *                                        Default 'Your email address will not be published.'.
  2222  *     @type string $comment_notes_after  HTML element for a message displayed after the textarea field.
  2274  *     @type string $comment_notes_after  HTML element for a message displayed after the textarea field.
  2223  *     @type string $action               The comment form element action attribute. Default '/wp-comments-post.php'.
  2275  *     @type string $action               The comment form element action attribute. Default '/wp-comments-post.php'.
  2224  *     @type string $id_form              The comment form element id attribute. Default 'commentform'.
  2276  *     @type string $id_form              The comment form element id attribute. Default 'commentform'.
  2225  *     @type string $id_submit            The comment submit element id attribute. Default 'submit'.
  2277  *     @type string $id_submit            The comment submit element id attribute. Default 'submit'.
       
  2278  *     @type string $class_container      The comment form container class attribute. Default 'comment-respond'.
  2226  *     @type string $class_form           The comment form element class attribute. Default 'comment-form'.
  2279  *     @type string $class_form           The comment form element class attribute. Default 'comment-form'.
  2227  *     @type string $class_submit         The comment submit element class attribute. Default 'submit'.
  2280  *     @type string $class_submit         The comment submit element class attribute. Default 'submit'.
  2228  *     @type string $name_submit          The comment submit element name attribute. Default 'submit'.
  2281  *     @type string $name_submit          The comment submit element name attribute. Default 'submit'.
  2229  *     @type string $title_reply          The translatable 'reply' button label. Default 'Leave a Reply'.
  2282  *     @type string $title_reply          The translatable 'reply' button label. Default 'Leave a Reply'.
  2230  *     @type string $title_reply_to       The translatable 'reply-to' button label. Default 'Leave a Reply to %s',
  2283  *     @type string $title_reply_to       The translatable 'reply-to' button label. Default 'Leave a Reply to %s',
  2273 	}
  2326 	}
  2274 
  2327 
  2275 	$req      = get_option( 'require_name_email' );
  2328 	$req      = get_option( 'require_name_email' );
  2276 	$html_req = ( $req ? " required='required'" : '' );
  2329 	$html_req = ( $req ? " required='required'" : '' );
  2277 	$html5    = 'html5' === $args['format'];
  2330 	$html5    = 'html5' === $args['format'];
  2278 	$fields   = array(
  2331 
  2279 		'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
  2332 	$fields = array(
  2280 					 '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $html_req . ' /></p>',
  2333 		'author' => sprintf(
  2281 		'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
  2334 			'<p class="comment-form-author">%s %s</p>',
  2282 					 '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" maxlength="100" aria-describedby="email-notes"' . $html_req . ' /></p>',
  2335 			sprintf(
  2283 		'url'    => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .
  2336 				'<label for="author">%s%s</label>',
  2284 					 '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>',
  2337 				__( 'Name' ),
       
  2338 				( $req ? ' <span class="required">*</span>' : '' )
       
  2339 			),
       
  2340 			sprintf(
       
  2341 				'<input id="author" name="author" type="text" value="%s" size="30" maxlength="245"%s />',
       
  2342 				esc_attr( $commenter['comment_author'] ),
       
  2343 				$html_req
       
  2344 			)
       
  2345 		),
       
  2346 		'email'  => sprintf(
       
  2347 			'<p class="comment-form-email">%s %s</p>',
       
  2348 			sprintf(
       
  2349 				'<label for="email">%s%s</label>',
       
  2350 				__( 'Email' ),
       
  2351 				( $req ? ' <span class="required">*</span>' : '' )
       
  2352 			),
       
  2353 			sprintf(
       
  2354 				'<input id="email" name="email" %s value="%s" size="30" maxlength="100" aria-describedby="email-notes"%s />',
       
  2355 				( $html5 ? 'type="email"' : 'type="text"' ),
       
  2356 				esc_attr( $commenter['comment_author_email'] ),
       
  2357 				$html_req
       
  2358 			)
       
  2359 		),
       
  2360 		'url'    => sprintf(
       
  2361 			'<p class="comment-form-url">%s %s</p>',
       
  2362 			sprintf(
       
  2363 				'<label for="url">%s</label>',
       
  2364 				__( 'Website' )
       
  2365 			),
       
  2366 			sprintf(
       
  2367 				'<input id="url" name="url" %s value="%s" size="30" maxlength="200" />',
       
  2368 				( $html5 ? 'type="url"' : 'type="text"' ),
       
  2369 				esc_attr( $commenter['comment_author_url'] )
       
  2370 			)
       
  2371 		),
  2285 	);
  2372 	);
  2286 
  2373 
  2287 	if ( has_action( 'set_comment_cookies', 'wp_set_comment_cookies' ) && get_option( 'show_comments_cookies_opt_in' ) ) {
  2374 	if ( has_action( 'set_comment_cookies', 'wp_set_comment_cookies' ) && get_option( 'show_comments_cookies_opt_in' ) ) {
  2288 		$consent           = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';
  2375 		$consent = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';
  2289 		$fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' .
  2376 
  2290 							 '<label for="wp-comment-cookies-consent">' . __( 'Save my name, email, and website in this browser for the next time I comment.' ) . '</label></p>';
  2377 		$fields['cookies'] = sprintf(
       
  2378 			'<p class="comment-form-cookies-consent">%s %s</p>',
       
  2379 			sprintf(
       
  2380 				'<input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"%s />',
       
  2381 				$consent
       
  2382 			),
       
  2383 			sprintf(
       
  2384 				'<label for="wp-comment-cookies-consent">%s</label>',
       
  2385 				__( 'Save my name, email, and website in this browser for the next time I comment.' )
       
  2386 			)
       
  2387 		);
  2291 
  2388 
  2292 		// Ensure that the passed fields include cookies consent.
  2389 		// Ensure that the passed fields include cookies consent.
  2293 		if ( isset( $args['fields'] ) && ! isset( $args['fields']['cookies'] ) ) {
  2390 		if ( isset( $args['fields'] ) && ! isset( $args['fields']['cookies'] ) ) {
  2294 			$args['fields']['cookies'] = $fields['cookies'];
  2391 			$args['fields']['cookies'] = $fields['cookies'];
  2295 		}
  2392 		}
  2296 	}
  2393 	}
  2297 
  2394 
  2298 	$required_text = sprintf( ' ' . __( 'Required fields are marked %s' ), '<span class="required">*</span>' );
  2395 	$required_text = sprintf(
       
  2396 		/* translators: %s: Asterisk symbol (*). */
       
  2397 		' ' . __( 'Required fields are marked %s' ),
       
  2398 		'<span class="required">*</span>'
       
  2399 	);
  2299 
  2400 
  2300 	/**
  2401 	/**
  2301 	 * Filters the default comment form fields.
  2402 	 * Filters the default comment form fields.
  2302 	 *
  2403 	 *
  2303 	 * @since 3.0.0
  2404 	 * @since 3.0.0
  2304 	 *
  2405 	 *
  2305 	 * @param string[] $fields Array of the default comment fields.
  2406 	 * @param string[] $fields Array of the default comment fields.
  2306 	 */
  2407 	 */
  2307 	$fields   = apply_filters( 'comment_form_default_fields', $fields );
  2408 	$fields = apply_filters( 'comment_form_default_fields', $fields );
       
  2409 
  2308 	$defaults = array(
  2410 	$defaults = array(
  2309 		'fields'               => $fields,
  2411 		'fields'               => $fields,
  2310 		'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea></p>',
  2412 		'comment_field'        => sprintf(
  2311 		/** This filter is documented in wp-includes/link-template.php */
  2413 			'<p class="comment-form-comment">%s %s</p>',
  2312 		'must_log_in'          => '<p class="must-log-in">' . sprintf(
  2414 			sprintf(
  2313 			/* translators: %s: login URL */
  2415 				'<label for="comment">%s</label>',
  2314 									__( 'You must be <a href="%s">logged in</a> to post a comment.' ),
  2416 				_x( 'Comment', 'noun' )
  2315 			wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) )
  2417 			),
  2316 		) . '</p>',
  2418 			'<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea>'
  2317 		/** This filter is documented in wp-includes/link-template.php */
  2419 		),
  2318 		'logged_in_as'         => '<p class="logged-in-as">' . sprintf(
  2420 		'must_log_in'          => sprintf(
  2319 			/* translators: 1: edit user link, 2: accessibility text, 3: user name, 4: logout URL */
  2421 			'<p class="must-log-in">%s</p>',
  2320 									__( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ),
  2422 			sprintf(
  2321 			get_edit_user_link(),
  2423 				/* translators: %s: Login URL. */
  2322 			/* translators: %s: user name */
  2424 				__( 'You must be <a href="%s">logged in</a> to post a comment.' ),
  2323 									esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ),
  2425 				/** This filter is documented in wp-includes/link-template.php */
  2324 			$user_identity,
  2426 				wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) )
  2325 			wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) )
  2427 			)
  2326 		) . '</p>',
  2428 		),
  2327 		'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>' . ( $req ? $required_text : '' ) . '</p>',
  2429 		'logged_in_as'         => sprintf(
       
  2430 			'<p class="logged-in-as">%s</p>',
       
  2431 			sprintf(
       
  2432 				/* translators: 1: Edit user link, 2: Accessibility text, 3: User name, 4: Logout URL. */
       
  2433 				__( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ),
       
  2434 				get_edit_user_link(),
       
  2435 				/* translators: %s: User name. */
       
  2436 				esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ),
       
  2437 				$user_identity,
       
  2438 				/** This filter is documented in wp-includes/link-template.php */
       
  2439 				wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) )
       
  2440 			)
       
  2441 		),
       
  2442 		'comment_notes_before' => sprintf(
       
  2443 			'<p class="comment-notes">%s%s</p>',
       
  2444 			sprintf(
       
  2445 				'<span id="email-notes">%s</span>',
       
  2446 				__( 'Your email address will not be published.' )
       
  2447 			),
       
  2448 			( $req ? $required_text : '' )
       
  2449 		),
  2328 		'comment_notes_after'  => '',
  2450 		'comment_notes_after'  => '',
  2329 		'action'               => site_url( '/wp-comments-post.php' ),
  2451 		'action'               => site_url( '/wp-comments-post.php' ),
  2330 		'id_form'              => 'commentform',
  2452 		'id_form'              => 'commentform',
  2331 		'id_submit'            => 'submit',
  2453 		'id_submit'            => 'submit',
       
  2454 		'class_container'      => 'comment-respond',
  2332 		'class_form'           => 'comment-form',
  2455 		'class_form'           => 'comment-form',
  2333 		'class_submit'         => 'submit',
  2456 		'class_submit'         => 'submit',
  2334 		'name_submit'          => 'submit',
  2457 		'name_submit'          => 'submit',
  2335 		'title_reply'          => __( 'Leave a Reply' ),
  2458 		'title_reply'          => __( 'Leave a Reply' ),
       
  2459 		/* translators: %s: Author of the comment being replied to. */
  2336 		'title_reply_to'       => __( 'Leave a Reply to %s' ),
  2460 		'title_reply_to'       => __( 'Leave a Reply to %s' ),
  2337 		'title_reply_before'   => '<h3 id="reply-title" class="comment-reply-title">',
  2461 		'title_reply_before'   => '<h3 id="reply-title" class="comment-reply-title">',
  2338 		'title_reply_after'    => '</h3>',
  2462 		'title_reply_after'    => '</h3>',
  2339 		'cancel_reply_before'  => ' <small>',
  2463 		'cancel_reply_before'  => ' <small>',
  2340 		'cancel_reply_after'   => '</small>',
  2464 		'cancel_reply_after'   => '</small>',
  2357 	$args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
  2481 	$args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
  2358 
  2482 
  2359 	// Ensure that the filtered args contain all required default values.
  2483 	// Ensure that the filtered args contain all required default values.
  2360 	$args = array_merge( $defaults, $args );
  2484 	$args = array_merge( $defaults, $args );
  2361 
  2485 
       
  2486 	// Remove `aria-describedby` from the email field if there's no associated description.
       
  2487 	if ( isset( $args['fields']['email'] ) && false === strpos( $args['comment_notes_before'], 'id="email-notes"' ) ) {
       
  2488 		$args['fields']['email'] = str_replace(
       
  2489 			' aria-describedby="email-notes"',
       
  2490 			'',
       
  2491 			$args['fields']['email']
       
  2492 		);
       
  2493 	}
       
  2494 
  2362 	/**
  2495 	/**
  2363 	 * Fires before the comment form.
  2496 	 * Fires before the comment form.
  2364 	 *
  2497 	 *
  2365 	 * @since 3.0.0
  2498 	 * @since 3.0.0
  2366 	 */
  2499 	 */
  2367 	do_action( 'comment_form_before' );
  2500 	do_action( 'comment_form_before' );
  2368 	?>
  2501 	?>
  2369 	<div id="respond" class="comment-respond">
  2502 	<div id="respond" class="<?php echo esc_attr( $args['class_container'] ); ?>">
  2370 		<?php
  2503 		<?php
  2371 		echo $args['title_reply_before'];
  2504 		echo $args['title_reply_before'];
  2372 
  2505 
  2373 		comment_form_title( $args['title_reply'], $args['title_reply_to'] );
  2506 		comment_form_title( $args['title_reply'], $args['title_reply_to'] );
  2374 
  2507 
  2379 		echo $args['cancel_reply_after'];
  2512 		echo $args['cancel_reply_after'];
  2380 
  2513 
  2381 		echo $args['title_reply_after'];
  2514 		echo $args['title_reply_after'];
  2382 
  2515 
  2383 		if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) :
  2516 		if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) :
       
  2517 
  2384 			echo $args['must_log_in'];
  2518 			echo $args['must_log_in'];
  2385 			/**
  2519 			/**
  2386 			 * Fires after the HTML-formatted 'must log in after' message in the comment form.
  2520 			 * Fires after the HTML-formatted 'must log in after' message in the comment form.
  2387 			 *
  2521 			 *
  2388 			 * @since 3.0.0
  2522 			 * @since 3.0.0
  2389 			 */
  2523 			 */
  2390 			do_action( 'comment_form_must_log_in_after' );
  2524 			do_action( 'comment_form_must_log_in_after' );
       
  2525 
  2391 		else :
  2526 		else :
  2392 			?>
  2527 
  2393 			<form action="<?php echo esc_url( $args['action'] ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="<?php echo esc_attr( $args['class_form'] ); ?>"<?php echo $html5 ? ' novalidate' : ''; ?>>
  2528 			printf(
  2394 				<?php
  2529 				'<form action="%s" method="post" id="%s" class="%s"%s>',
       
  2530 				esc_url( $args['action'] ),
       
  2531 				esc_attr( $args['id_form'] ),
       
  2532 				esc_attr( $args['class_form'] ),
       
  2533 				( $html5 ? ' novalidate' : '' )
       
  2534 			);
       
  2535 
       
  2536 			/**
       
  2537 			 * Fires at the top of the comment form, inside the form tag.
       
  2538 			 *
       
  2539 			 * @since 3.0.0
       
  2540 			 */
       
  2541 			do_action( 'comment_form_top' );
       
  2542 
       
  2543 			if ( is_user_logged_in() ) :
       
  2544 
  2395 				/**
  2545 				/**
  2396 				 * Fires at the top of the comment form, inside the form tag.
  2546 				 * Filters the 'logged in' message for the comment form for display.
  2397 				 *
  2547 				 *
  2398 				 * @since 3.0.0
  2548 				 * @since 3.0.0
       
  2549 				 *
       
  2550 				 * @param string $args_logged_in The logged-in-as HTML-formatted message.
       
  2551 				 * @param array  $commenter      An array containing the comment author's
       
  2552 				 *                               username, email, and URL.
       
  2553 				 * @param string $user_identity  If the commenter is a registered user,
       
  2554 				 *                               the display name, blank otherwise.
  2399 				 */
  2555 				 */
  2400 				do_action( 'comment_form_top' );
  2556 				echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity );
  2401 
  2557 
  2402 				if ( is_user_logged_in() ) :
  2558 				/**
       
  2559 				 * Fires after the is_user_logged_in() check in the comment form.
       
  2560 				 *
       
  2561 				 * @since 3.0.0
       
  2562 				 *
       
  2563 				 * @param array  $commenter     An array containing the comment author's
       
  2564 				 *                              username, email, and URL.
       
  2565 				 * @param string $user_identity If the commenter is a registered user,
       
  2566 				 *                              the display name, blank otherwise.
       
  2567 				 */
       
  2568 				do_action( 'comment_form_logged_in_after', $commenter, $user_identity );
       
  2569 
       
  2570 			else :
       
  2571 
       
  2572 				echo $args['comment_notes_before'];
       
  2573 
       
  2574 			endif;
       
  2575 
       
  2576 			// Prepare an array of all fields, including the textarea.
       
  2577 			$comment_fields = array( 'comment' => $args['comment_field'] ) + (array) $args['fields'];
       
  2578 
       
  2579 			/**
       
  2580 			 * Filters the comment form fields, including the textarea.
       
  2581 			 *
       
  2582 			 * @since 4.4.0
       
  2583 			 *
       
  2584 			 * @param array $comment_fields The comment fields.
       
  2585 			 */
       
  2586 			$comment_fields = apply_filters( 'comment_form_fields', $comment_fields );
       
  2587 
       
  2588 			// Get an array of field names, excluding the textarea.
       
  2589 			$comment_field_keys = array_diff( array_keys( $comment_fields ), array( 'comment' ) );
       
  2590 
       
  2591 			// Get the first and the last field name, excluding the textarea.
       
  2592 			$first_field = reset( $comment_field_keys );
       
  2593 			$last_field  = end( $comment_field_keys );
       
  2594 
       
  2595 			foreach ( $comment_fields as $name => $field ) {
       
  2596 
       
  2597 				if ( 'comment' === $name ) {
       
  2598 
  2403 					/**
  2599 					/**
  2404 					 * Filters the 'logged in' message for the comment form for display.
  2600 					 * Filters the content of the comment textarea field for display.
  2405 					 *
  2601 					 *
  2406 					 * @since 3.0.0
  2602 					 * @since 3.0.0
  2407 					 *
  2603 					 *
  2408 					 * @param string $args_logged_in The logged-in-as HTML-formatted message.
  2604 					 * @param string $args_comment_field The content of the comment textarea field.
  2409 					 * @param array  $commenter      An array containing the comment author's
       
  2410 					 *                               username, email, and URL.
       
  2411 					 * @param string $user_identity  If the commenter is a registered user,
       
  2412 					 *                               the display name, blank otherwise.
       
  2413 					 */
  2605 					 */
  2414 					echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity );
  2606 					echo apply_filters( 'comment_form_field_comment', $field );
       
  2607 
       
  2608 					echo $args['comment_notes_after'];
       
  2609 
       
  2610 				} elseif ( ! is_user_logged_in() ) {
       
  2611 
       
  2612 					if ( $first_field === $name ) {
       
  2613 						/**
       
  2614 						 * Fires before the comment fields in the comment form, excluding the textarea.
       
  2615 						 *
       
  2616 						 * @since 3.0.0
       
  2617 						 */
       
  2618 						do_action( 'comment_form_before_fields' );
       
  2619 					}
  2415 
  2620 
  2416 					/**
  2621 					/**
  2417 					 * Fires after the is_user_logged_in() check in the comment form.
  2622 					 * Filters a comment form field for display.
       
  2623 					 *
       
  2624 					 * The dynamic portion of the filter hook, `$name`, refers to the name
       
  2625 					 * of the comment form field. Such as 'author', 'email', or 'url'.
  2418 					 *
  2626 					 *
  2419 					 * @since 3.0.0
  2627 					 * @since 3.0.0
  2420 					 *
  2628 					 *
  2421 					 * @param array  $commenter     An array containing the comment author's
  2629 					 * @param string $field The HTML-formatted output of the comment form field.
  2422 					 *                              username, email, and URL.
       
  2423 					 * @param string $user_identity If the commenter is a registered user,
       
  2424 					 *                              the display name, blank otherwise.
       
  2425 					 */
  2630 					 */
  2426 					do_action( 'comment_form_logged_in_after', $commenter, $user_identity );
  2631 					echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
  2427 
  2632 
  2428 				else :
  2633 					if ( $last_field === $name ) {
  2429 
       
  2430 					echo $args['comment_notes_before'];
       
  2431 
       
  2432 				endif;
       
  2433 
       
  2434 				// Prepare an array of all fields, including the textarea
       
  2435 				$comment_fields = array( 'comment' => $args['comment_field'] ) + (array) $args['fields'];
       
  2436 
       
  2437 				/**
       
  2438 				 * Filters the comment form fields, including the textarea.
       
  2439 				 *
       
  2440 				 * @since 4.4.0
       
  2441 				 *
       
  2442 				 * @param array $comment_fields The comment fields.
       
  2443 				 */
       
  2444 				$comment_fields = apply_filters( 'comment_form_fields', $comment_fields );
       
  2445 
       
  2446 				// Get an array of field names, excluding the textarea
       
  2447 				$comment_field_keys = array_diff( array_keys( $comment_fields ), array( 'comment' ) );
       
  2448 
       
  2449 				// Get the first and the last field name, excluding the textarea
       
  2450 				$first_field = reset( $comment_field_keys );
       
  2451 				$last_field  = end( $comment_field_keys );
       
  2452 
       
  2453 				foreach ( $comment_fields as $name => $field ) {
       
  2454 
       
  2455 					if ( 'comment' === $name ) {
       
  2456 
       
  2457 						/**
  2634 						/**
  2458 						 * Filters the content of the comment textarea field for display.
  2635 						 * Fires after the comment fields in the comment form, excluding the textarea.
  2459 						 *
  2636 						 *
  2460 						 * @since 3.0.0
  2637 						 * @since 3.0.0
  2461 						 *
       
  2462 						 * @param string $args_comment_field The content of the comment textarea field.
       
  2463 						 */
  2638 						 */
  2464 						echo apply_filters( 'comment_form_field_comment', $field );
  2639 						do_action( 'comment_form_after_fields' );
  2465 
       
  2466 						echo $args['comment_notes_after'];
       
  2467 
       
  2468 					} elseif ( ! is_user_logged_in() ) {
       
  2469 
       
  2470 						if ( $first_field === $name ) {
       
  2471 							/**
       
  2472 							 * Fires before the comment fields in the comment form, excluding the textarea.
       
  2473 							 *
       
  2474 							 * @since 3.0.0
       
  2475 							 */
       
  2476 							do_action( 'comment_form_before_fields' );
       
  2477 						}
       
  2478 
       
  2479 						/**
       
  2480 						 * Filters a comment form field for display.
       
  2481 						 *
       
  2482 						 * The dynamic portion of the filter hook, `$name`, refers to the name
       
  2483 						 * of the comment form field. Such as 'author', 'email', or 'url'.
       
  2484 						 *
       
  2485 						 * @since 3.0.0
       
  2486 						 *
       
  2487 						 * @param string $field The HTML-formatted output of the comment form field.
       
  2488 						 */
       
  2489 						echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
       
  2490 
       
  2491 						if ( $last_field === $name ) {
       
  2492 							/**
       
  2493 							 * Fires after the comment fields in the comment form, excluding the textarea.
       
  2494 							 *
       
  2495 							 * @since 3.0.0
       
  2496 							 */
       
  2497 							do_action( 'comment_form_after_fields' );
       
  2498 						}
       
  2499 					}
  2640 					}
  2500 				}
  2641 				}
  2501 
  2642 			}
  2502 				$submit_button = sprintf(
  2643 
  2503 					$args['submit_button'],
  2644 			$submit_button = sprintf(
  2504 					esc_attr( $args['name_submit'] ),
  2645 				$args['submit_button'],
  2505 					esc_attr( $args['id_submit'] ),
  2646 				esc_attr( $args['name_submit'] ),
  2506 					esc_attr( $args['class_submit'] ),
  2647 				esc_attr( $args['id_submit'] ),
  2507 					esc_attr( $args['label_submit'] )
  2648 				esc_attr( $args['class_submit'] ),
  2508 				);
  2649 				esc_attr( $args['label_submit'] )
  2509 
  2650 			);
  2510 				/**
  2651 
  2511 				 * Filters the submit button for the comment form to display.
  2652 			/**
  2512 				 *
  2653 			 * Filters the submit button for the comment form to display.
  2513 				 * @since 4.2.0
  2654 			 *
  2514 				 *
  2655 			 * @since 4.2.0
  2515 				 * @param string $submit_button HTML markup for the submit button.
  2656 			 *
  2516 				 * @param array  $args          Arguments passed to comment_form().
  2657 			 * @param string $submit_button HTML markup for the submit button.
  2517 				 */
  2658 			 * @param array  $args          Arguments passed to comment_form().
  2518 				$submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args );
  2659 			 */
  2519 
  2660 			$submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args );
  2520 				$submit_field = sprintf(
  2661 
  2521 					$args['submit_field'],
  2662 			$submit_field = sprintf(
  2522 					$submit_button,
  2663 				$args['submit_field'],
  2523 					get_comment_id_fields( $post_id )
  2664 				$submit_button,
  2524 				);
  2665 				get_comment_id_fields( $post_id )
  2525 
  2666 			);
  2526 				/**
  2667 
  2527 				 * Filters the submit field for the comment form to display.
  2668 			/**
  2528 				 *
  2669 			 * Filters the submit field for the comment form to display.
  2529 				 * The submit field includes the submit button, hidden fields for the
  2670 			 *
  2530 				 * comment form, and any wrapper markup.
  2671 			 * The submit field includes the submit button, hidden fields for the
  2531 				 *
  2672 			 * comment form, and any wrapper markup.
  2532 				 * @since 4.2.0
  2673 			 *
  2533 				 *
  2674 			 * @since 4.2.0
  2534 				 * @param string $submit_field HTML markup for the submit field.
  2675 			 *
  2535 				 * @param array  $args         Arguments passed to comment_form().
  2676 			 * @param string $submit_field HTML markup for the submit field.
  2536 				 */
  2677 			 * @param array  $args         Arguments passed to comment_form().
  2537 				echo apply_filters( 'comment_form_submit_field', $submit_field, $args );
  2678 			 */
  2538 
  2679 			echo apply_filters( 'comment_form_submit_field', $submit_field, $args );
  2539 				/**
  2680 
  2540 				 * Fires at the bottom of the comment form, inside the closing </form> tag.
  2681 			/**
  2541 				 *
  2682 			 * Fires at the bottom of the comment form, inside the closing form tag.
  2542 				 * @since 1.5.0
  2683 			 *
  2543 				 *
  2684 			 * @since 1.5.0
  2544 				 * @param int $post_id The post ID.
  2685 			 *
  2545 				 */
  2686 			 * @param int $post_id The post ID.
  2546 				do_action( 'comment_form', $post_id );
  2687 			 */
  2547 				?>
  2688 			do_action( 'comment_form', $post_id );
  2548 			</form>
  2689 
  2549 		<?php endif; ?>
  2690 			echo '</form>';
       
  2691 
       
  2692 		endif;
       
  2693 		?>
  2550 	</div><!-- #respond -->
  2694 	</div><!-- #respond -->
  2551 	<?php
  2695 	<?php
  2552 
  2696 
  2553 	/**
  2697 	/**
  2554 	 * Fires after the comment form.
  2698 	 * Fires after the comment form.