wp/wp-includes/comment-template.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
--- a/wp/wp-includes/comment-template.php	Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-includes/comment-template.php	Fri Sep 05 18:40:08 2025 +0200
@@ -15,86 +15,94 @@
  * assumed.
  *
  * @since 1.5.0
- * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
+ * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
  *
- * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to retrieve the author.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or the ID of the comment for which to retrieve the author.
  *                                   Default current comment.
  * @return string The comment author
  */
-function get_comment_author( $comment_ID = 0 ) {
-	$comment    = get_comment( $comment_ID );
-	$comment_ID = ! empty( $comment->comment_ID ) ? $comment->comment_ID : $comment_ID;
+function get_comment_author( $comment_id = 0 ) {
+	$comment = get_comment( $comment_id );
+
+	if ( ! empty( $comment->comment_ID ) ) {
+		$comment_id = $comment->comment_ID;
+	} elseif ( is_scalar( $comment_id ) ) {
+		$comment_id = (string) $comment_id;
+	} else {
+		$comment_id = '';
+	}
 
 	if ( empty( $comment->comment_author ) ) {
 		$user = ! empty( $comment->user_id ) ? get_userdata( $comment->user_id ) : false;
 		if ( $user ) {
-			$author = $user->display_name;
+			$comment_author = $user->display_name;
 		} else {
-			$author = __( 'Anonymous' );
+			$comment_author = __( 'Anonymous' );
 		}
 	} else {
-		$author = $comment->comment_author;
+		$comment_author = $comment->comment_author;
 	}
 
 	/**
 	 * Filters the returned comment author name.
 	 *
 	 * @since 1.5.0
-	 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
+	 * @since 4.1.0 The `$comment_id` and `$comment` parameters were added.
 	 *
-	 * @param string     $author     The comment author's username.
-	 * @param string     $comment_ID The comment ID as a numeric string.
-	 * @param WP_Comment $comment    The comment object.
+	 * @param string     $comment_author The comment author's username.
+	 * @param string     $comment_id     The comment ID as a numeric string.
+	 * @param WP_Comment $comment        The comment object.
 	 */
-	return apply_filters( 'get_comment_author', $author, $comment_ID, $comment );
+	return apply_filters( 'get_comment_author', $comment_author, $comment_id, $comment );
 }
 
 /**
  * Displays the author of the current comment.
  *
  * @since 0.71
- * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
+ * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
  *
- * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or the ID of the comment for which to print the author.
  *                                   Default current comment.
  */
-function comment_author( $comment_ID = 0 ) {
-	$comment = get_comment( $comment_ID );
-	$author  = get_comment_author( $comment );
+function comment_author( $comment_id = 0 ) {
+	$comment = get_comment( $comment_id );
+
+	$comment_author = get_comment_author( $comment );
 
 	/**
 	 * Filters the comment author's name for display.
 	 *
 	 * @since 1.2.0
-	 * @since 4.1.0 The `$comment_ID` parameter was added.
+	 * @since 4.1.0 The `$comment_id` parameter was added.
 	 *
-	 * @param string $author     The comment author's username.
-	 * @param string $comment_ID The comment ID as a numeric string.
+	 * @param string $comment_author The comment author's username.
+	 * @param string $comment_id     The comment ID as a numeric string.
 	 */
-	echo apply_filters( 'comment_author', $author, $comment->comment_ID );
+	echo apply_filters( 'comment_author', $comment_author, $comment->comment_ID );
 }
 
 /**
  * Retrieves the email of the author of the current comment.
  *
  * @since 1.5.0
- * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
+ * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
  *
- * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's email.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or the ID of the comment for which to get the author's email.
  *                                   Default current comment.
  * @return string The current comment author's email
  */
-function get_comment_author_email( $comment_ID = 0 ) {
-	$comment = get_comment( $comment_ID );
+function get_comment_author_email( $comment_id = 0 ) {
+	$comment = get_comment( $comment_id );
 
 	/**
 	 * Filters the comment author's returned email address.
 	 *
 	 * @since 1.5.0
-	 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
+	 * @since 4.1.0 The `$comment_id` and `$comment` parameters were added.
 	 *
 	 * @param string     $comment_author_email The comment author's email address.
-	 * @param string     $comment_ID           The comment ID as a numeric string.
+	 * @param string     $comment_id           The comment ID as a numeric string.
 	 * @param WP_Comment $comment              The comment object.
 	 */
 	return apply_filters( 'get_comment_author_email', $comment->comment_author_email, $comment->comment_ID, $comment );
@@ -110,25 +118,26 @@
  * address and use it for their own means good and bad.
  *
  * @since 0.71
- * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
+ * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
  *
- * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's email.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or the ID of the comment for which to print the author's email.
  *                                   Default current comment.
  */
-function comment_author_email( $comment_ID = 0 ) {
-	$comment      = get_comment( $comment_ID );
-	$author_email = get_comment_author_email( $comment );
+function comment_author_email( $comment_id = 0 ) {
+	$comment = get_comment( $comment_id );
+
+	$comment_author_email = get_comment_author_email( $comment );
 
 	/**
 	 * Filters the comment author's email for display.
 	 *
 	 * @since 1.2.0
-	 * @since 4.1.0 The `$comment_ID` parameter was added.
+	 * @since 4.1.0 The `$comment_id` parameter was added.
 	 *
-	 * @param string $author_email The comment author's email address.
-	 * @param string $comment_ID   The comment ID as a numeric string.
+	 * @param string $comment_author_email The comment author's email address.
+	 * @param string $comment_id           The comment ID as a numeric string.
 	 */
-	echo apply_filters( 'author_email', $author_email, $comment->comment_ID );
+	echo apply_filters( 'author_email', $comment_author_email, $comment->comment_ID );
 }
 
 /**
@@ -143,14 +152,14 @@
  * @since 0.71
  * @since 4.6.0 Added the `$comment` parameter.
  *
- * @param string         $linktext Optional. Text to display instead of the comment author's email address.
- *                                 Default empty.
- * @param string         $before   Optional. Text or HTML to display before the email link. Default empty.
- * @param string         $after    Optional. Text or HTML to display after the email link. Default empty.
- * @param int|WP_Comment $comment  Optional. Comment ID or WP_Comment object. Default is the current comment.
+ * @param string         $link_text Optional. Text to display instead of the comment author's email address.
+ *                                  Default empty.
+ * @param string         $before    Optional. Text or HTML to display before the email link. Default empty.
+ * @param string         $after     Optional. Text or HTML to display after the email link. Default empty.
+ * @param int|WP_Comment $comment   Optional. Comment ID or WP_Comment object. Default is the current comment.
  */
-function comment_author_email_link( $linktext = '', $before = '', $after = '', $comment = null ) {
-	$link = get_comment_author_email_link( $linktext, $before, $after, $comment );
+function comment_author_email_link( $link_text = '', $before = '', $after = '', $comment = null ) {
+	$link = get_comment_author_email_link( $link_text, $before, $after, $comment );
 	if ( $link ) {
 		echo $link;
 	}
@@ -168,15 +177,15 @@
  * @since 2.7.0
  * @since 4.6.0 Added the `$comment` parameter.
  *
- * @param string         $linktext Optional. Text to display instead of the comment author's email address.
- *                                 Default empty.
- * @param string         $before   Optional. Text or HTML to display before the email link. Default empty.
- * @param string         $after    Optional. Text or HTML to display after the email link. Default empty.
- * @param int|WP_Comment $comment  Optional. Comment ID or WP_Comment object. Default is the current comment.
+ * @param string         $link_text Optional. Text to display instead of the comment author's email address.
+ *                                  Default empty.
+ * @param string         $before    Optional. Text or HTML to display before the email link. Default empty.
+ * @param string         $after     Optional. Text or HTML to display after the email link. Default empty.
+ * @param int|WP_Comment $comment   Optional. Comment ID or WP_Comment object. Default is the current comment.
  * @return string HTML markup for the comment author email link. By default, the email address is obfuscated
  *                via the {@see 'comment_email'} filter with antispambot().
  */
-function get_comment_author_email_link( $linktext = '', $before = '', $after = '', $comment = null ) {
+function get_comment_author_email_link( $link_text = '', $before = '', $after = '', $comment = null ) {
 	$comment = get_comment( $comment );
 
 	/**
@@ -191,14 +200,18 @@
 	 * @param string     $comment_author_email The comment author's email address.
 	 * @param WP_Comment $comment              The comment object.
 	 */
-	$email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );
+	$comment_author_email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );
+
+	if ( ( ! empty( $comment_author_email ) ) && ( '@' !== $comment_author_email ) ) {
+		$display = ( '' !== $link_text ) ? $link_text : $comment_author_email;
 
-	if ( ( ! empty( $email ) ) && ( '@' !== $email ) ) {
-		$display = ( '' !== $linktext ) ? $linktext : $email;
-		$return  = $before;
-		$return .= sprintf( '<a href="%1$s">%2$s</a>', esc_url( 'mailto:' . $email ), esc_html( $display ) );
-		$return .= $after;
-		return $return;
+		$comment_author_email_link = $before . sprintf(
+			'<a href="%1$s">%2$s</a>',
+			esc_url( 'mailto:' . $comment_author_email ),
+			esc_html( $display )
+		) . $after;
+
+		return $comment_author_email_link;
 	} else {
 		return '';
 	}
@@ -208,74 +221,106 @@
  * Retrieves the HTML link to the URL of the author of the current comment.
  *
  * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
- * which falls back to the global comment variable if the $comment_ID argument is empty.
+ * which falls back to the global comment variable if the $comment_id argument is empty.
  *
  * @since 1.5.0
- * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
+ * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
  *
- * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's link.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or the ID of the comment for which to get the author's link.
  *                                   Default current comment.
  * @return string The comment author name or HTML link for author's URL.
  */
-function get_comment_author_link( $comment_ID = 0 ) {
-	$comment = get_comment( $comment_ID );
-	$url     = get_comment_author_url( $comment );
-	$author  = get_comment_author( $comment );
+function get_comment_author_link( $comment_id = 0 ) {
+	$comment = get_comment( $comment_id );
+
+	$comment_id = ! empty( $comment->comment_ID ) ? $comment->comment_ID : (string) $comment_id;
+
+	$comment_author_url = get_comment_author_url( $comment );
+	$comment_author     = get_comment_author( $comment );
+
+	if ( empty( $comment_author_url ) || 'http://' === $comment_author_url ) {
+		$comment_author_link = $comment_author;
+	} else {
+		$rel_parts = array( 'ugc' );
+		if ( ! wp_is_internal_link( $comment_author_url ) ) {
+			$rel_parts = array_merge(
+				$rel_parts,
+				array( 'external', 'nofollow' )
+			);
+		}
 
-	if ( empty( $url ) || 'http://' === $url ) {
-		$return = $author;
-	} else {
-		$return = "<a href='$url' rel='external nofollow ugc' class='url'>$author</a>";
+		/**
+		 * Filters the rel attributes of the comment author's link.
+		 *
+		 * @since 6.2.0
+		 *
+		 * @param string[]   $rel_parts An array of strings representing the rel tags
+		 *                              which will be joined into the anchor's rel attribute.
+		 * @param WP_Comment $comment   The comment object.
+		 */
+		$rel_parts = apply_filters( 'comment_author_link_rel', $rel_parts, $comment );
+
+		$rel = implode( ' ', $rel_parts );
+		$rel = esc_attr( $rel );
+		// Empty space before 'rel' is necessary for later sprintf().
+		$rel = ! empty( $rel ) ? sprintf( ' rel="%s"', $rel ) : '';
+
+		$comment_author_link = sprintf(
+			'<a href="%1$s" class="url"%2$s>%3$s</a>',
+			$comment_author_url,
+			$rel,
+			$comment_author
+		);
 	}
 
 	/**
 	 * Filters the comment author's link for display.
 	 *
 	 * @since 1.5.0
-	 * @since 4.1.0 The `$author` and `$comment_ID` parameters were added.
+	 * @since 4.1.0 The `$comment_author` and `$comment_id` parameters were added.
 	 *
-	 * @param string $return     The HTML-formatted comment author link.
-	 *                           Empty for an invalid URL.
-	 * @param string $author     The comment author's username.
-	 * @param string $comment_ID The comment ID as a numeric string.
+	 * @param string $comment_author_link The HTML-formatted comment author link.
+	 *                                    Empty for an invalid URL.
+	 * @param string $comment_author      The comment author's username.
+	 * @param string $comment_id          The comment ID as a numeric string.
 	 */
-	return apply_filters( 'get_comment_author_link', $return, $author, $comment->comment_ID );
+	return apply_filters( 'get_comment_author_link', $comment_author_link, $comment_author, $comment_id );
 }
 
 /**
  * Displays the HTML link to the URL of the author of the current comment.
  *
  * @since 0.71
- * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
+ * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
  *
- * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's link.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or the ID of the comment for which to print the author's link.
  *                                   Default current comment.
  */
-function comment_author_link( $comment_ID = 0 ) {
-	echo get_comment_author_link( $comment_ID );
+function comment_author_link( $comment_id = 0 ) {
+	echo get_comment_author_link( $comment_id );
 }
 
 /**
  * Retrieves the IP address of the author of the current comment.
  *
  * @since 1.5.0
- * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
+ * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
  *
- * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's IP address.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or the ID of the comment for which to get the author's IP address.
  *                                   Default current comment.
  * @return string Comment author's IP address, or an empty string if it's not available.
  */
-function get_comment_author_IP( $comment_ID = 0 ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
-	$comment = get_comment( $comment_ID );
+function get_comment_author_IP( $comment_id = 0 ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
+	$comment = get_comment( $comment_id );
 
 	/**
 	 * Filters the comment author's returned IP address.
 	 *
 	 * @since 1.5.0
-	 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
+	 * @since 4.1.0 The `$comment_id` and `$comment` parameters were added.
 	 *
-	 * @param string     $comment_author_IP The comment author's IP address, or an empty string if it's not available.
-	 * @param string     $comment_ID        The comment ID as a numeric string.
+	 * @param string     $comment_author_ip The comment author's IP address, or an empty string if it's not available.
+	 * @param string     $comment_id        The comment ID as a numeric string.
 	 * @param WP_Comment $comment           The comment object.
 	 */
 	return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP, $comment->comment_ID, $comment );  // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
@@ -285,79 +330,82 @@
  * Displays the IP address of the author of the current comment.
  *
  * @since 0.71
- * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
+ * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
  *
- * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's IP address.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or the ID of the comment for which to print the author's IP address.
  *                                   Default current comment.
  */
-function comment_author_IP( $comment_ID = 0 ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
-	echo esc_html( get_comment_author_IP( $comment_ID ) );
+function comment_author_IP( $comment_id = 0 ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
+	echo esc_html( get_comment_author_IP( $comment_id ) );
 }
 
 /**
  * Retrieves the URL of the author of the current comment, not linked.
  *
  * @since 1.5.0
- * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
+ * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
  *
- * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's URL.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or the ID of the comment for which to get the author's URL.
  *                                   Default current comment.
  * @return string Comment author URL, if provided, an empty string otherwise.
  */
-function get_comment_author_url( $comment_ID = 0 ) {
-	$comment = get_comment( $comment_ID );
-	$url     = '';
-	$id      = 0;
+function get_comment_author_url( $comment_id = 0 ) {
+	$comment = get_comment( $comment_id );
+
+	$comment_author_url = '';
+	$comment_id         = 0;
 
 	if ( ! empty( $comment ) ) {
-		$author_url = ( 'http://' === $comment->comment_author_url ) ? '' : $comment->comment_author_url;
-		$url        = esc_url( $author_url, array( 'http', 'https' ) );
-		$id         = $comment->comment_ID;
+		$comment_author_url = ( 'http://' === $comment->comment_author_url ) ? '' : $comment->comment_author_url;
+		$comment_author_url = esc_url( $comment_author_url, array( 'http', 'https' ) );
+
+		$comment_id = $comment->comment_ID;
 	}
 
 	/**
 	 * Filters the comment author's URL.
 	 *
 	 * @since 1.5.0
-	 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
+	 * @since 4.1.0 The `$comment_id` and `$comment` parameters were added.
 	 *
-	 * @param string          $url        The comment author's URL, or an empty string.
-	 * @param string|int      $comment_ID The comment ID as a numeric string, or 0 if not found.
-	 * @param WP_Comment|null $comment    The comment object, or null if not found.
+	 * @param string          $comment_author_url The comment author's URL, or an empty string.
+	 * @param string|int      $comment_id         The comment ID as a numeric string, or 0 if not found.
+	 * @param WP_Comment|null $comment            The comment object, or null if not found.
 	 */
-	return apply_filters( 'get_comment_author_url', $url, $id, $comment );
+	return apply_filters( 'get_comment_author_url', $comment_author_url, $comment_id, $comment );
 }
 
 /**
  * Displays the URL of the author of the current comment, not linked.
  *
  * @since 0.71
- * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
+ * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
  *
- * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to print the author's URL.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or the ID of the comment for which to print the author's URL.
  *                                   Default current comment.
  */
-function comment_author_url( $comment_ID = 0 ) {
-	$comment    = get_comment( $comment_ID );
-	$author_url = get_comment_author_url( $comment );
+function comment_author_url( $comment_id = 0 ) {
+	$comment = get_comment( $comment_id );
+
+	$comment_author_url = get_comment_author_url( $comment );
 
 	/**
 	 * Filters the comment author's URL for display.
 	 *
 	 * @since 1.2.0
-	 * @since 4.1.0 The `$comment_ID` parameter was added.
+	 * @since 4.1.0 The `$comment_id` parameter was added.
 	 *
-	 * @param string $author_url The comment author's URL.
-	 * @param string $comment_ID The comment ID as a numeric string.
+	 * @param string $comment_author_url The comment author's URL.
+	 * @param string $comment_id         The comment ID as a numeric string.
 	 */
-	echo apply_filters( 'comment_url', $author_url, $comment->comment_ID );
+	echo apply_filters( 'comment_url', $comment_author_url, $comment->comment_ID );
 }
 
 /**
  * Retrieves the HTML link of the URL of the author of the current comment.
  *
- * $linktext parameter is only used if the URL does not exist for the comment
- * author. If the URL does exist then the URL will be used and the $linktext
+ * $link_text parameter is only used if the URL does not exist for the comment
+ * author. If the URL does exist then the URL will be used and the $link_text
  * will be ignored.
  *
  * Encapsulate the HTML link between the $before and $after. So it will appear
@@ -366,36 +414,41 @@
  * @since 1.5.0
  * @since 4.6.0 Added the `$comment` parameter.
  *
- * @param string         $linktext Optional. The text to display instead of the comment
- *                                 author's email address. Default empty.
- * @param string         $before   Optional. The text or HTML to display before the email link.
- *                                 Default empty.
- * @param string         $after    Optional. The text or HTML to display after the email link.
- *                                 Default empty.
- * @param int|WP_Comment $comment  Optional. Comment ID or WP_Comment object.
- *                                 Default is the current comment.
+ * @param string         $link_text Optional. The text to display instead of the comment
+ *                                  author's email address. Default empty.
+ * @param string         $before    Optional. The text or HTML to display before the email link.
+ *                                  Default empty.
+ * @param string         $after     Optional. The text or HTML to display after the email link.
+ *                                  Default empty.
+ * @param int|WP_Comment $comment   Optional. Comment ID or WP_Comment object.
+ *                                  Default is the current comment.
  * @return string The HTML link between the $before and $after parameters.
  */
-function get_comment_author_url_link( $linktext = '', $before = '', $after = '', $comment = 0 ) {
-	$url     = get_comment_author_url( $comment );
-	$display = ( '' !== $linktext ) ? $linktext : $url;
+function get_comment_author_url_link( $link_text = '', $before = '', $after = '', $comment = 0 ) {
+	$comment_author_url = get_comment_author_url( $comment );
+
+	$display = ( '' !== $link_text ) ? $link_text : $comment_author_url;
 	$display = str_replace( 'http://www.', '', $display );
 	$display = str_replace( 'http://', '', $display );
 
-	if ( '/' === substr( $display, -1 ) ) {
+	if ( str_ends_with( $display, '/' ) ) {
 		$display = substr( $display, 0, -1 );
 	}
 
-	$return = "$before<a href='$url' rel='external'>$display</a>$after";
+	$comment_author_url_link = $before . sprintf(
+		'<a href="%1$s" rel="external">%2$s</a>',
+		$comment_author_url,
+		$display
+	) . $after;
 
 	/**
 	 * Filters the comment author's returned URL link.
 	 *
 	 * @since 1.5.0
 	 *
-	 * @param string $return The HTML-formatted comment author URL link.
+	 * @param string $comment_author_url_link The HTML-formatted comment author URL link.
 	 */
-	return apply_filters( 'get_comment_author_url_link', $return );
+	return apply_filters( 'get_comment_author_url_link', $comment_author_url_link );
 }
 
 /**
@@ -404,17 +457,17 @@
  * @since 0.71
  * @since 4.6.0 Added the `$comment` parameter.
  *
- * @param string         $linktext Optional. Text to display instead of the comment author's
- *                                 email address. Default empty.
- * @param string         $before   Optional. Text or HTML to display before the email link.
- *                                 Default empty.
- * @param string         $after    Optional. Text or HTML to display after the email link.
- *                                 Default empty.
- * @param int|WP_Comment $comment  Optional. Comment ID or WP_Comment object.
- *                                 Default is the current comment.
+ * @param string         $link_text Optional. Text to display instead of the comment author's
+ *                                  email address. Default empty.
+ * @param string         $before    Optional. Text or HTML to display before the email link.
+ *                                  Default empty.
+ * @param string         $after     Optional. Text or HTML to display after the email link.
+ *                                  Default empty.
+ * @param int|WP_Comment $comment   Optional. Comment ID or WP_Comment object.
+ *                                  Default is the current comment.
  */
-function comment_author_url_link( $linktext = '', $before = '', $after = '', $comment = 0 ) {
-	echo get_comment_author_url_link( $linktext, $before, $after, $comment );
+function comment_author_url_link( $link_text = '', $before = '', $after = '', $comment = 0 ) {
+	echo get_comment_author_url_link( $link_text, $before, $after, $comment );
 }
 
 /**
@@ -425,15 +478,15 @@
  *
  * @param string|string[] $css_class Optional. One or more classes to add to the class list.
  *                                   Default empty.
- * @param int|WP_Comment  $comment   Comment ID or WP_Comment object. Default current comment.
- * @param int|WP_Post     $post_id   Post ID or WP_Post object. Default current post.
+ * @param int|WP_Comment  $comment   Optional. Comment ID or WP_Comment object. Default current comment.
+ * @param int|WP_Post     $post      Optional. Post ID or WP_Post object. Default current post.
  * @param bool            $display   Optional. Whether to print or return the output.
  *                                   Default true.
  * @return void|string Void if `$display` argument is true, comment classes if `$display` is false.
  */
-function comment_class( $css_class = '', $comment = null, $post_id = null, $display = true ) {
+function comment_class( $css_class = '', $comment = null, $post = null, $display = true ) {
 	// Separates classes with a single space, collates classes for comment DIV.
-	$css_class = 'class="' . implode( ' ', get_comment_class( $css_class, $comment, $post_id ) ) . '"';
+	$css_class = 'class="' . implode( ' ', get_comment_class( $css_class, $comment, $post ) ) . '"';
 
 	if ( $display ) {
 		echo $css_class;
@@ -452,12 +505,13 @@
  * @global int $comment_depth
  * @global int $comment_thread_alt
  *
- * @param string|string[] $css_class  Optional. One or more classes to add to the class list. Default empty.
- * @param int|WP_Comment  $comment_id Comment ID or WP_Comment object. Default current comment.
- * @param int|WP_Post     $post_id    Post ID or WP_Post object. Default current post.
+ * @param string|string[] $css_class  Optional. One or more classes to add to the class list.
+ *                                    Default empty.
+ * @param int|WP_Comment  $comment_id Optional. Comment ID or WP_Comment object. Default current comment.
+ * @param int|WP_Post     $post       Optional. Post ID or WP_Post object. Default current post.
  * @return string[] An array of classes.
  */
-function get_comment_class( $css_class = '', $comment_id = null, $post_id = null ) {
+function get_comment_class( $css_class = '', $comment_id = null, $post = null ) {
 	global $comment_alt, $comment_depth, $comment_thread_alt;
 
 	$classes = array();
@@ -476,9 +530,9 @@
 		$classes[] = 'byuser';
 		$classes[] = 'comment-author-' . sanitize_html_class( $user->user_nicename, $comment->user_id );
 		// For comment authors who are the author of the post.
-		$post = get_post( $post_id );
-		if ( $post ) {
-			if ( $comment->user_id === $post->post_author ) {
+		$_post = get_post( $post );
+		if ( $_post ) {
+			if ( $comment->user_id === $_post->post_author ) {
 				$classes[] = 'bypostauthor';
 			}
 		}
@@ -501,7 +555,7 @@
 		$classes[] = 'even';
 	}
 
-	$comment_alt++;
+	++$comment_alt;
 
 	// Alt for top-level comments.
 	if ( 1 == $comment_depth ) {
@@ -511,7 +565,7 @@
 		} else {
 			$classes[] = 'thread-even';
 		}
-		$comment_thread_alt++;
+		++$comment_thread_alt;
 	}
 
 	$classes[] = "depth-$comment_depth";
@@ -534,53 +588,53 @@
 	 * @param string[]    $css_class  An array of additional classes added to the list.
 	 * @param string      $comment_id The comment ID as a numeric string.
 	 * @param WP_Comment  $comment    The comment object.
-	 * @param int|WP_Post $post_id    The post ID or WP_Post object.
+	 * @param int|WP_Post $post       The post ID or WP_Post object.
 	 */
-	return apply_filters( 'comment_class', $classes, $css_class, $comment->comment_ID, $comment, $post_id );
+	return apply_filters( 'comment_class', $classes, $css_class, $comment->comment_ID, $comment, $post );
 }
 
 /**
  * Retrieves the comment date of the current comment.
  *
  * @since 1.5.0
- * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
+ * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
  *
  * @param string         $format     Optional. PHP date format. Defaults to the 'date_format' option.
- * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the date.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or ID of the comment for which to get the date.
  *                                   Default current comment.
  * @return string The comment's date.
  */
-function get_comment_date( $format = '', $comment_ID = 0 ) {
-	$comment = get_comment( $comment_ID );
+function get_comment_date( $format = '', $comment_id = 0 ) {
+	$comment = get_comment( $comment_id );
 
 	$_format = ! empty( $format ) ? $format : get_option( 'date_format' );
 
-	$date = mysql2date( $_format, $comment->comment_date );
+	$comment_date = mysql2date( $_format, $comment->comment_date );
 
 	/**
 	 * Filters the returned comment date.
 	 *
 	 * @since 1.5.0
 	 *
-	 * @param string|int $date    Formatted date string or Unix timestamp.
-	 * @param string     $format  PHP date format.
-	 * @param WP_Comment $comment The comment object.
+	 * @param string|int $comment_date Formatted date string or Unix timestamp.
+	 * @param string     $format       PHP date format.
+	 * @param WP_Comment $comment      The comment object.
 	 */
-	return apply_filters( 'get_comment_date', $date, $format, $comment );
+	return apply_filters( 'get_comment_date', $comment_date, $format, $comment );
 }
 
 /**
  * Displays the comment date of the current comment.
  *
  * @since 0.71
- * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
+ * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
  *
  * @param string         $format     Optional. PHP date format. Defaults to the 'date_format' option.
- * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the date.
+ * @param int|WP_Comment $comment_id WP_Comment or ID of the comment for which to print the date.
  *                                   Default current comment.
  */
-function comment_date( $format = '', $comment_ID = 0 ) {
-	echo get_comment_date( $format, $comment_ID );
+function comment_date( $format = '', $comment_id = 0 ) {
+	echo get_comment_date( $format, $comment_id );
 }
 
 /**
@@ -589,14 +643,14 @@
  * Returns a maximum of 20 words with an ellipsis appended if necessary.
  *
  * @since 1.5.0
- * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
+ * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
  *
- * @param int|WP_Comment $comment_ID  WP_Comment or ID of the comment for which to get the excerpt.
- *                                    Default current comment.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or ID of the comment for which to get the excerpt.
+ *                                   Default current comment.
  * @return string The possibly truncated comment excerpt.
  */
-function get_comment_excerpt( $comment_ID = 0 ) {
-	$comment = get_comment( $comment_ID );
+function get_comment_excerpt( $comment_id = 0 ) {
+	$comment = get_comment( $comment_id );
 
 	if ( ! post_password_required( $comment->comment_post_ID ) ) {
 		$comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
@@ -616,42 +670,43 @@
 	 */
 	$comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length );
 
-	$excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '&hellip;' );
+	$comment_excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '&hellip;' );
 
 	/**
 	 * Filters the retrieved comment excerpt.
 	 *
 	 * @since 1.5.0
-	 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
+	 * @since 4.1.0 The `$comment_id` and `$comment` parameters were added.
 	 *
-	 * @param string     $excerpt    The comment excerpt text.
-	 * @param string     $comment_ID The comment ID as a numeric string.
-	 * @param WP_Comment $comment    The comment object.
+	 * @param string     $comment_excerpt The comment excerpt text.
+	 * @param string     $comment_id      The comment ID as a numeric string.
+	 * @param WP_Comment $comment         The comment object.
 	 */
-	return apply_filters( 'get_comment_excerpt', $excerpt, $comment->comment_ID, $comment );
+	return apply_filters( 'get_comment_excerpt', $comment_excerpt, $comment->comment_ID, $comment );
 }
 
 /**
  * Displays the excerpt of the current comment.
  *
  * @since 1.2.0
- * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
+ * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
  *
- * @param int|WP_Comment $comment_ID  WP_Comment or ID of the comment for which to print the excerpt.
- *                                    Default current comment.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or ID of the comment for which to print the excerpt.
+ *                                   Default current comment.
  */
-function comment_excerpt( $comment_ID = 0 ) {
-	$comment         = get_comment( $comment_ID );
+function comment_excerpt( $comment_id = 0 ) {
+	$comment = get_comment( $comment_id );
+
 	$comment_excerpt = get_comment_excerpt( $comment );
 
 	/**
 	 * Filters the comment excerpt for display.
 	 *
 	 * @since 1.2.0
-	 * @since 4.1.0 The `$comment_ID` parameter was added.
+	 * @since 4.1.0 The `$comment_id` parameter was added.
 	 *
 	 * @param string $comment_excerpt The comment excerpt text.
-	 * @param string $comment_ID      The comment ID as a numeric string.
+	 * @param string $comment_id      The comment ID as a numeric string.
 	 */
 	echo apply_filters( 'comment_excerpt', $comment_excerpt, $comment->comment_ID );
 }
@@ -664,8 +719,9 @@
  * @return string The comment ID as a numeric string.
  */
 function get_comment_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
-	$comment    = get_comment();
-	$comment_ID = ! empty( $comment->comment_ID ) ? $comment->comment_ID : '0';
+	$comment = get_comment();
+
+	$comment_id = ! empty( $comment->comment_ID ) ? $comment->comment_ID : '0';
 
 	/**
 	 * Filters the returned comment ID.
@@ -673,10 +729,10 @@
 	 * @since 1.5.0
 	 * @since 4.1.0 The `$comment` parameter was added.
 	 *
-	 * @param string     $comment_ID The current comment ID as a numeric string.
+	 * @param string     $comment_id The current comment ID as a numeric string.
 	 * @param WP_Comment $comment    The comment object.
 	 */
-	return apply_filters( 'get_comment_ID', $comment_ID, $comment );  // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
+	return apply_filters( 'get_comment_ID', $comment_id, $comment );  // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
 }
 
 /**
@@ -699,7 +755,7 @@
  * @global WP_Rewrite $wp_rewrite      WordPress rewrite component.
  * @global bool       $in_comment_loop
  *
- * @param WP_Comment|int|null $comment Comment to retrieve. Default current comment.
+ * @param WP_Comment|int|null $comment Optional. Comment to retrieve. Default current comment.
  * @param array               $args {
  *     An array of optional arguments to override the defaults.
  *
@@ -730,9 +786,10 @@
 		'max_depth' => '',
 		'cpage'     => null,
 	);
-	$args     = wp_parse_args( $args, $defaults );
 
-	$link = get_permalink( $comment->comment_post_ID );
+	$args = wp_parse_args( $args, $defaults );
+
+	$comment_link = get_permalink( $comment->comment_post_ID );
 
 	// The 'cpage' param takes precedence.
 	if ( ! is_null( $args['cpage'] ) ) {
@@ -772,20 +829,20 @@
 	if ( $cpage && get_option( 'page_comments' ) ) {
 		if ( $wp_rewrite->using_permalinks() ) {
 			if ( $cpage ) {
-				$link = trailingslashit( $link ) . $wp_rewrite->comments_pagination_base . '-' . $cpage;
+				$comment_link = trailingslashit( $comment_link ) . $wp_rewrite->comments_pagination_base . '-' . $cpage;
 			}
 
-			$link = user_trailingslashit( $link, 'comment' );
+			$comment_link = user_trailingslashit( $comment_link, 'comment' );
 		} elseif ( $cpage ) {
-			$link = add_query_arg( 'cpage', $cpage, $link );
+			$comment_link = add_query_arg( 'cpage', $cpage, $comment_link );
 		}
 	}
 
 	if ( $wp_rewrite->using_permalinks() ) {
-		$link = user_trailingslashit( $link, 'comment' );
+		$comment_link = user_trailingslashit( $comment_link, 'comment' );
 	}
 
-	$link = $link . '#comment-' . $comment->comment_ID;
+	$comment_link = $comment_link . '#comment-' . $comment->comment_ID;
 
 	/**
 	 * Filters the returned single comment permalink.
@@ -795,12 +852,12 @@
 	 *
 	 * @see get_page_of_comment()
 	 *
-	 * @param string     $link    The comment permalink with '#comment-$id' appended.
-	 * @param WP_Comment $comment The current comment object.
-	 * @param array      $args    An array of arguments to override the defaults.
-	 * @param int        $cpage   The calculated 'cpage' value.
+	 * @param string     $comment_link The comment permalink with '#comment-$id' appended.
+	 * @param WP_Comment $comment      The current comment object.
+	 * @param array      $args         An array of arguments to override the defaults.
+	 * @param int        $cpage        The calculated 'cpage' value.
 	 */
-	return apply_filters( 'get_comment_link', $link, $comment, $args, $cpage );
+	return apply_filters( 'get_comment_link', $comment_link, $comment, $args, $cpage );
 }
 
 /**
@@ -808,12 +865,12 @@
  *
  * @since 1.5.0
  *
- * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
+ * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
  * @return string The link to the comments.
  */
-function get_comments_link( $post_id = 0 ) {
-	$hash          = get_comments_number( $post_id ) ? '#comments' : '#respond';
-	$comments_link = get_permalink( $post_id ) . $hash;
+function get_comments_link( $post = 0 ) {
+	$hash          = get_comments_number( $post ) ? '#comments' : '#respond';
+	$comments_link = get_permalink( $post ) . $hash;
 
 	/**
 	 * Filters the returned post comments permalink.
@@ -821,9 +878,9 @@
 	 * @since 3.6.0
 	 *
 	 * @param string      $comments_link Post comments permalink with '#comments' appended.
-	 * @param int|WP_Post $post_id       Post ID or WP_Post object.
+	 * @param int|WP_Post $post          Post ID or WP_Post object.
 	 */
-	return apply_filters( 'get_comments_link', $comments_link, $post_id );
+	return apply_filters( 'get_comments_link', $comments_link, $post );
 }
 
 /**
@@ -849,65 +906,64 @@
  *
  * @since 1.5.0
  *
- * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`.
+ * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is the global `$post`.
  * @return string|int If the post exists, a numeric string representing the number of comments
  *                    the post has, otherwise 0.
  */
-function get_comments_number( $post_id = 0 ) {
-	$post = get_post( $post_id );
+function get_comments_number( $post = 0 ) {
+	$post = get_post( $post );
 
-	if ( ! $post ) {
-		$count = 0;
-	} else {
-		$count   = $post->comment_count;
-		$post_id = $post->ID;
-	}
+	$comments_number = $post ? $post->comment_count : 0;
+	$post_id         = $post ? $post->ID : 0;
 
 	/**
 	 * Filters the returned comment count for a post.
 	 *
 	 * @since 1.5.0
 	 *
-	 * @param string|int $count   A string representing the number of comments a post has, otherwise 0.
+	 * @param string|int $comments_number A string representing the number of comments a post has, otherwise 0.
 	 * @param int        $post_id Post ID.
 	 */
-	return apply_filters( 'get_comments_number', $count, $post_id );
+	return apply_filters( 'get_comments_number', $comments_number, $post_id );
 }
 
 /**
  * Displays the language string for the number of comments the current post has.
  *
  * @since 0.71
- * @since 5.4.0 The `$deprecated` parameter was changed to `$post_id`.
+ * @since 5.4.0 The `$deprecated` parameter was changed to `$post`.
  *
- * @param string|false $zero    Optional. Text for no comments. Default false.
- * @param string|false $one     Optional. Text for one comment. Default false.
- * @param string|false $more    Optional. Text for more than one comment. Default false.
- * @param int|WP_Post  $post_id Optional. Post ID or WP_Post object. Default is the global `$post`.
+ * @param string|false $zero Optional. Text for no comments. Default false.
+ * @param string|false $one  Optional. Text for one comment. Default false.
+ * @param string|false $more Optional. Text for more than one comment. Default false.
+ * @param int|WP_Post  $post Optional. Post ID or WP_Post object. Default is the global `$post`.
  */
-function comments_number( $zero = false, $one = false, $more = false, $post_id = 0 ) {
-	echo get_comments_number_text( $zero, $one, $more, $post_id );
+function comments_number( $zero = false, $one = false, $more = false, $post = 0 ) {
+	echo get_comments_number_text( $zero, $one, $more, $post );
 }
 
 /**
  * Displays the language string for the number of comments the current post has.
  *
  * @since 4.0.0
- * @since 5.4.0 Added the `$post_id` parameter to allow using the function outside of the loop.
+ * @since 5.4.0 Added the `$post` parameter to allow using the function outside of the loop.
  *
- * @param string      $zero    Optional. Text for no comments. Default false.
- * @param string      $one     Optional. Text for one comment. Default false.
- * @param string      $more    Optional. Text for more than one comment. Default false.
- * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is the global `$post`.
+ * @param string      $zero Optional. Text for no comments. Default false.
+ * @param string      $one  Optional. Text for one comment. Default false.
+ * @param string      $more Optional. Text for more than one comment. Default false.
+ * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is the global `$post`.
  * @return string Language string for the number of comments a post has.
  */
-function get_comments_number_text( $zero = false, $one = false, $more = false, $post_id = 0 ) {
-	$number = get_comments_number( $post_id );
+function get_comments_number_text( $zero = false, $one = false, $more = false, $post = 0 ) {
+	$comments_number = get_comments_number( $post );
 
-	if ( $number > 1 ) {
+	if ( $comments_number > 1 ) {
 		if ( false === $more ) {
-			/* translators: %s: Number of comments. */
-			$output = sprintf( _n( '%s Comment', '%s Comments', $number ), number_format_i18n( $number ) );
+			$comments_number_text = sprintf(
+				/* translators: %s: Number of comments. */
+				_n( '%s Comment', '%s Comments', $comments_number ),
+				number_format_i18n( $comments_number )
+			);
 		} else {
 			// % Comments
 			/*
@@ -916,29 +972,30 @@
 			 */
 			if ( 'on' === _x( 'off', 'Comment number declension: on or off' ) ) {
 				$text = preg_replace( '#<span class="screen-reader-text">.+?</span>#', '', $more );
-				$text = preg_replace( '/&.+?;/', '', $text ); // Kill entities.
+				$text = preg_replace( '/&.+?;/', '', $text ); // Remove HTML entities.
 				$text = trim( strip_tags( $text ), '% ' );
 
 				// Replace '% Comments' with a proper plural form.
-				if ( $text && ! preg_match( '/[0-9]+/', $text ) && false !== strpos( $more, '%' ) ) {
+				if ( $text && ! preg_match( '/[0-9]+/', $text ) && str_contains( $more, '%' ) ) {
 					/* translators: %s: Number of comments. */
-					$new_text = _n( '%s Comment', '%s Comments', $number );
+					$new_text = _n( '%s Comment', '%s Comments', $comments_number );
 					$new_text = trim( sprintf( $new_text, '' ) );
 
 					$more = str_replace( $text, $new_text, $more );
-					if ( false === strpos( $more, '%' ) ) {
+					if ( ! str_contains( $more, '%' ) ) {
 						$more = '% ' . $more;
 					}
 				}
 			}
 
-			$output = str_replace( '%', number_format_i18n( $number ), $more );
+			$comments_number_text = str_replace( '%', number_format_i18n( $comments_number ), $more );
 		}
-	} elseif ( 0 == $number ) {
-		$output = ( false === $zero ) ? __( 'No Comments' ) : $zero;
+	} elseif ( 0 == $comments_number ) {
+		$comments_number_text = ( false === $zero ) ? __( 'No Comments' ) : $zero;
 	} else { // Must be one.
-		$output = ( false === $one ) ? __( '1 Comment' ) : $one;
+		$comments_number_text = ( false === $one ) ? __( '1 Comment' ) : $one;
 	}
+
 	/**
 	 * Filters the comments count for display.
 	 *
@@ -946,31 +1003,31 @@
 	 *
 	 * @see _n()
 	 *
-	 * @param string $output A translatable string formatted based on whether the count
-	 *                       is equal to 0, 1, or 1+.
-	 * @param int    $number The number of post comments.
+	 * @param string $comments_number_text A translatable string formatted based on whether the count
+	 *                                     is equal to 0, 1, or 1+.
+	 * @param int    $comments_number      The number of post comments.
 	 */
-	return apply_filters( 'comments_number', $output, $number );
+	return apply_filters( 'comments_number', $comments_number_text, $comments_number );
 }
 
 /**
  * Retrieves the text of the current comment.
  *
  * @since 1.5.0
- * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
+ * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
  * @since 5.4.0 Added 'In reply to %s.' prefix to child comments in comments feed.
  *
  * @see Walker_Comment::comment()
  *
- * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the text.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or ID of the comment for which to get the text.
  *                                   Default current comment.
  * @param array          $args       Optional. An array of arguments. Default empty array.
  * @return string The comment content.
  */
-function get_comment_text( $comment_ID = 0, $args = array() ) {
-	$comment = get_comment( $comment_ID );
+function get_comment_text( $comment_id = 0, $args = array() ) {
+	$comment = get_comment( $comment_id );
 
-	$comment_content = $comment->comment_content;
+	$comment_text = $comment->comment_content;
 
 	if ( is_comment_feed() && $comment->comment_parent ) {
 		$parent = get_comment( $comment->comment_parent );
@@ -978,11 +1035,11 @@
 			$parent_link = esc_url( get_comment_link( $parent ) );
 			$name        = get_comment_author( $parent );
 
-			$comment_content = sprintf(
+			$comment_text = sprintf(
 				/* translators: %s: Comment link. */
 				ent2ncr( __( 'In reply to %s.' ) ),
 				'<a href="' . $parent_link . '">' . $name . '</a>'
-			) . "\n\n" . $comment_content;
+			) . "\n\n" . $comment_text;
 		}
 	}
 
@@ -993,29 +1050,30 @@
 	 *
 	 * @see Walker_Comment::comment()
 	 *
-	 * @param string     $comment_content Text of the comment.
-	 * @param WP_Comment $comment         The comment object.
-	 * @param array      $args            An array of arguments.
+	 * @param string     $comment_text Text of the comment.
+	 * @param WP_Comment $comment      The comment object.
+	 * @param array      $args         An array of arguments.
 	 */
-	return apply_filters( 'get_comment_text', $comment_content, $comment, $args );
+	return apply_filters( 'get_comment_text', $comment_text, $comment, $args );
 }
 
 /**
  * Displays the text of the current comment.
  *
  * @since 0.71
- * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
+ * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
  *
  * @see Walker_Comment::comment()
  *
- * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the text.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or ID of the comment for which to print the text.
  *                                   Default current comment.
  * @param array          $args       Optional. An array of arguments. Default empty array.
  */
-function comment_text( $comment_ID = 0, $args = array() ) {
-	$comment = get_comment( $comment_ID );
+function comment_text( $comment_id = 0, $args = array() ) {
+	$comment = get_comment( $comment_id );
 
 	$comment_text = get_comment_text( $comment, $args );
+
 	/**
 	 * Filters the text of a comment to be displayed.
 	 *
@@ -1023,7 +1081,7 @@
 	 *
 	 * @see Walker_Comment::comment()
 	 *
-	 * @param string          $comment_text Text of the current comment.
+	 * @param string          $comment_text Text of the comment.
 	 * @param WP_Comment|null $comment      The comment object. Null if not found.
 	 * @param array           $args         An array of arguments.
 	 */
@@ -1034,59 +1092,69 @@
  * Retrieves the comment time of the current comment.
  *
  * @since 1.5.0
+ * @since 6.2.0 Added the `$comment_id` parameter.
  *
- * @param string $format    Optional. PHP time format. Defaults to the 'time_format' option.
- * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
- * @param bool   $translate Optional. Whether to translate the time (for use in feeds).
- *                          Default true.
+ * @param string         $format     Optional. PHP date format. Defaults to the 'time_format' option.
+ * @param bool           $gmt        Optional. Whether to use the GMT date. Default false.
+ * @param bool           $translate  Optional. Whether to translate the time (for use in feeds).
+ *                                   Default true.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or ID of the comment for which to get the time.
+ *                                   Default current comment.
  * @return string The formatted time.
  */
-function get_comment_time( $format = '', $gmt = false, $translate = true ) {
-	$comment = get_comment();
+function get_comment_time( $format = '', $gmt = false, $translate = true, $comment_id = 0 ) {
+	$comment = get_comment( $comment_id );
+
+	if ( null === $comment ) {
+		return '';
+	}
 
 	$comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
 
 	$_format = ! empty( $format ) ? $format : get_option( 'time_format' );
 
-	$date = mysql2date( $_format, $comment_date, $translate );
+	$comment_time = mysql2date( $_format, $comment_date, $translate );
 
 	/**
 	 * Filters the returned comment time.
 	 *
 	 * @since 1.5.0
 	 *
-	 * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
-	 * @param string     $format    PHP date format.
-	 * @param bool       $gmt       Whether the GMT date is in use.
-	 * @param bool       $translate Whether the time is translated.
-	 * @param WP_Comment $comment   The comment object.
+	 * @param string|int $comment_time The comment time, formatted as a date string or Unix timestamp.
+	 * @param string     $format       PHP date format.
+	 * @param bool       $gmt          Whether the GMT date is in use.
+	 * @param bool       $translate    Whether the time is translated.
+	 * @param WP_Comment $comment      The comment object.
 	 */
-	return apply_filters( 'get_comment_time', $date, $format, $gmt, $translate, $comment );
+	return apply_filters( 'get_comment_time', $comment_time, $format, $gmt, $translate, $comment );
 }
 
 /**
  * Displays the comment time of the current comment.
  *
  * @since 0.71
+ * @since 6.2.0 Added the `$comment_id` parameter.
  *
- * @param string $format Optional. PHP time format. Defaults to the 'time_format' option.
+ * @param string         $format     Optional. PHP time format. Defaults to the 'time_format' option.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or ID of the comment for which to print the time.
+ *                                   Default current comment.
  */
-function comment_time( $format = '' ) {
-	echo get_comment_time( $format );
+function comment_time( $format = '', $comment_id = 0 ) {
+	echo get_comment_time( $format, false, true, $comment_id );
 }
 
 /**
  * Retrieves the comment type of the current comment.
  *
  * @since 1.5.0
- * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
+ * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
  *
- * @param int|WP_Comment $comment_ID Optional. WP_Comment or ID of the comment for which to get the type.
+ * @param int|WP_Comment $comment_id Optional. WP_Comment or ID of the comment for which to get the type.
  *                                   Default current comment.
  * @return string The comment type.
  */
-function get_comment_type( $comment_ID = 0 ) {
-	$comment = get_comment( $comment_ID );
+function get_comment_type( $comment_id = 0 ) {
+	$comment = get_comment( $comment_id );
 
 	if ( '' === $comment->comment_type ) {
 		$comment->comment_type = 'comment';
@@ -1096,10 +1164,10 @@
 	 * Filters the returned comment type.
 	 *
 	 * @since 1.5.0
-	 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
+	 * @since 4.1.0 The `$comment_id` and `$comment` parameters were added.
 	 *
 	 * @param string     $comment_type The type of comment, such as 'comment', 'pingback', or 'trackback'.
-	 * @param string     $comment_ID   The comment ID as a numeric string.
+	 * @param string     $comment_id   The comment ID as a numeric string.
 	 * @param WP_Comment $comment      The comment object.
 	 */
 	return apply_filters( 'get_comment_type', $comment->comment_type, $comment->comment_ID, $comment );
@@ -1150,9 +1218,9 @@
  */
 function get_trackback_url() {
 	if ( get_option( 'permalink_structure' ) ) {
-		$tb_url = trailingslashit( get_permalink() ) . user_trailingslashit( 'trackback', 'single_trackback' );
+		$trackback_url = trailingslashit( get_permalink() ) . user_trailingslashit( 'trackback', 'single_trackback' );
 	} else {
-		$tb_url = get_option( 'siteurl' ) . '/wp-trackback.php?p=' . get_the_ID();
+		$trackback_url = get_option( 'siteurl' ) . '/wp-trackback.php?p=' . get_the_ID();
 	}
 
 	/**
@@ -1160,9 +1228,9 @@
 	 *
 	 * @since 2.2.0
 	 *
-	 * @param string $tb_url The trackback URL.
+	 * @param string $trackback_url The trackback URL.
 	 */
-	return apply_filters( 'trackback_url', $tb_url );
+	return apply_filters( 'trackback_url', $trackback_url );
 }
 
 /**
@@ -1235,25 +1303,24 @@
  *
  * @since 1.5.0
  *
- * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
+ * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
  * @return bool True if the comments are open.
  */
-function comments_open( $post_id = null ) {
+function comments_open( $post = null ) {
+	$_post = get_post( $post );
 
-	$_post = get_post( $post_id );
-
-	$post_id = $_post ? $_post->ID : 0;
-	$open    = ( $_post && ( 'open' === $_post->comment_status ) );
+	$post_id       = $_post ? $_post->ID : 0;
+	$comments_open = ( $_post && ( 'open' === $_post->comment_status ) );
 
 	/**
 	 * Filters whether the current post is open for comments.
 	 *
 	 * @since 2.5.0
 	 *
-	 * @param bool $open    Whether the current post is open for comments.
-	 * @param int  $post_id The post ID.
+	 * @param bool $comments_open Whether the current post is open for comments.
+	 * @param int  $post_id       The post ID.
 	 */
-	return apply_filters( 'comments_open', $open, $post_id );
+	return apply_filters( 'comments_open', $comments_open, $post_id );
 }
 
 /**
@@ -1265,25 +1332,24 @@
  *
  * @since 1.5.0
  *
- * @param int|WP_Post $post_id Post ID or WP_Post object. Default current post.
+ * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
  * @return bool True if pings are accepted
  */
-function pings_open( $post_id = null ) {
+function pings_open( $post = null ) {
+	$_post = get_post( $post );
 
-	$_post = get_post( $post_id );
-
-	$post_id = $_post ? $_post->ID : 0;
-	$open    = ( $_post && ( 'open' === $_post->ping_status ) );
+	$post_id    = $_post ? $_post->ID : 0;
+	$pings_open = ( $_post && ( 'open' === $_post->ping_status ) );
 
 	/**
 	 * Filters whether the current post is open for pings.
 	 *
 	 * @since 2.5.0
 	 *
-	 * @param bool $open    Whether the current post is open for pings.
-	 * @param int  $post_id The post ID.
+	 * @param bool $pings_open Whether the current post is open for pings.
+	 * @param int  $post_id    The post ID.
 	 */
-	return apply_filters( 'pings_open', $open, $post_id );
+	return apply_filters( 'pings_open', $pings_open, $post_id );
 }
 
 /**
@@ -1306,7 +1372,7 @@
 
 	if ( current_user_can( 'unfiltered_html' ) ) {
 		wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false );
-		echo "<script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>\n";
+		wp_print_inline_script_tag( "(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();" );
 	}
 }
 
@@ -1321,7 +1387,7 @@
  * and the post ID respectively.
  *
  * The `$file` path is passed through a filter hook called {@see 'comments_template'},
- * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path
+ * which includes the template directory and $file combined. Tries the $filtered path
  * first and if it fails it will require the default comment template from the
  * default theme. If either does not exist, then the WordPress process will be
  * halted. It is advised for that reason, that the default theme is not deleted.
@@ -1330,22 +1396,24 @@
  *
  * @since 1.5.0
  *
- * @global WP_Query   $wp_query         WordPress Query object.
- * @global WP_Post    $post             Global post object.
- * @global wpdb       $wpdb             WordPress database abstraction object.
+ * @global WP_Query   $wp_query           WordPress Query object.
+ * @global WP_Post    $post               Global post object.
+ * @global wpdb       $wpdb               WordPress database abstraction object.
  * @global int        $id
- * @global WP_Comment $comment          Global comment object.
+ * @global WP_Comment $comment            Global comment object.
  * @global string     $user_login
  * @global string     $user_identity
  * @global bool       $overridden_cpage
  * @global bool       $withcomments
+ * @global string     $wp_stylesheet_path Path to current theme's stylesheet directory.
+ * @global string     $wp_template_path   Path to current theme's template directory.
  *
  * @param string $file              Optional. The file to load. Default '/comments.php'.
  * @param bool   $separate_comments Optional. Whether to separate the comments by comment type.
  *                                  Default false.
  */
 function comments_template( $file = '/comments.php', $separate_comments = false ) {
-	global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage;
+	global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage, $wp_stylesheet_path, $wp_template_path;
 
 	if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) {
 		return;
@@ -1380,12 +1448,11 @@
 	$comment_author_url = esc_url( $commenter['comment_author_url'] );
 
 	$comment_args = array(
-		'orderby'                   => 'comment_date_gmt',
-		'order'                     => 'ASC',
-		'status'                    => 'approve',
-		'post_id'                   => $post->ID,
-		'no_found_rows'             => false,
-		'update_comment_meta_cache' => false, // We lazy-load comment meta for performance.
+		'orderby'       => 'comment_date_gmt',
+		'order'         => 'ASC',
+		'status'        => 'approve',
+		'post_id'       => $post->ID,
+		'no_found_rows' => false,
 	);
 
 	if ( get_option( 'thread_comments' ) ) {
@@ -1456,7 +1523,7 @@
 
 			$top_level_count = $top_level_query->query( $top_level_args );
 
-			$comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
+			$comment_args['offset'] = ( (int) ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
 		}
 	}
 
@@ -1515,7 +1582,7 @@
 	 * @since 2.1.0
 	 *
 	 * @param array $comments Array of comments supplied to the comments template.
-	 * @param int   $post_ID  Post ID.
+	 * @param int   $post_id  Post ID.
 	 */
 	$wp_query->comments = apply_filters( 'comments_array', $comments_flat, $post->ID );
 
@@ -1541,7 +1608,7 @@
 		define( 'COMMENTS_TEMPLATE', true );
 	}
 
-	$theme_template = STYLESHEETPATH . $file;
+	$theme_template = trailingslashit( $wp_stylesheet_path ) . $file;
 
 	/**
 	 * Filters the path to the theme template file used for the comments template.
@@ -1554,8 +1621,8 @@
 
 	if ( file_exists( $include ) ) {
 		require $include;
-	} elseif ( file_exists( TEMPLATEPATH . $file ) ) {
-		require TEMPLATEPATH . $file;
+	} elseif ( file_exists( trailingslashit( $wp_template_path ) . $file ) ) {
+		require trailingslashit( $wp_template_path ) . $file;
 	} else { // Backward compat code will be removed in a future release.
 		require ABSPATH . WPINC . '/theme-compat/comments.php';
 	}
@@ -1573,9 +1640,9 @@
  * @param false|string $none      Optional. String to display when comments have been turned off. Default false.
  */
 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
-	$post_id    = get_the_ID();
-	$post_title = get_the_title();
-	$number     = get_comments_number( $post_id );
+	$post_id         = get_the_ID();
+	$post_title      = get_the_title();
+	$comments_number = get_comments_number( $post_id );
 
 	if ( false === $zero ) {
 		/* translators: %s: Post title. */
@@ -1589,8 +1656,12 @@
 
 	if ( false === $more ) {
 		/* translators: 1: Number of comments, 2: Post title. */
-		$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 );
-		$more = sprintf( $more, number_format_i18n( $number ), $post_title );
+		$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>',
+			$comments_number
+		);
+		$more = sprintf( $more, number_format_i18n( $comments_number ), $post_title );
 	}
 
 	if ( false === $none ) {
@@ -1598,8 +1669,12 @@
 		$none = sprintf( __( 'Comments Off<span class="screen-reader-text"> on %s</span>' ), $post_title );
 	}
 
-	if ( 0 == $number && ! comments_open() && ! pings_open() ) {
-		echo '<span' . ( ( ! empty( $css_class ) ) ? ' class="' . esc_attr( $css_class ) . '"' : '' ) . '>' . $none . '</span>';
+	if ( 0 == $comments_number && ! comments_open() && ! pings_open() ) {
+		printf(
+			'<span%1$s>%2$s</span>',
+			! empty( $css_class ) ? ' class="' . esc_attr( $css_class ) . '"' : '',
+			$none
+		);
 		return;
 	}
 
@@ -1608,8 +1683,7 @@
 		return;
 	}
 
-	echo '<a href="';
-	if ( 0 == $number ) {
+	if ( 0 == $comments_number ) {
 		$respond_link = get_permalink() . '#respond';
 		/**
 		 * Filters the respond link when a post has no comments.
@@ -1619,29 +1693,29 @@
 		 * @param string $respond_link The default response link.
 		 * @param int    $post_id      The post ID.
 		 */
-		echo apply_filters( 'respond_link', $respond_link, $post_id );
+		$comments_link = apply_filters( 'respond_link', $respond_link, $post_id );
 	} else {
-		comments_link();
-	}
-	echo '"';
-
-	if ( ! empty( $css_class ) ) {
-		echo ' class="' . $css_class . '" ';
+		$comments_link = get_comments_link();
 	}
 
-	$attributes = '';
+	$link_attributes = '';
+
 	/**
 	 * Filters the comments link attributes for display.
 	 *
 	 * @since 2.5.0
 	 *
-	 * @param string $attributes The comments link attributes. Default empty.
+	 * @param string $link_attributes The comments link attributes. Default empty.
 	 */
-	echo apply_filters( 'comments_popup_link_attributes', $attributes );
+	$link_attributes = apply_filters( 'comments_popup_link_attributes', $link_attributes );
 
-	echo '>';
-	comments_number( $zero, $one, $more );
-	echo '</a>';
+	printf(
+		'<a href="%1$s"%2$s%3$s>%4$s</a>',
+		esc_url( $comments_link ),
+		! empty( $css_class ) ? ' class="' . $css_class . '" ' : '',
+		$link_attributes,
+		get_comments_number_text( $zero, $one, $more )
+	);
 }
 
 /**
@@ -1667,8 +1741,8 @@
  *     @type string $before     The text or HTML to add before the reply link. Default empty.
  *     @type string $after      The text or HTML to add after the reply link. Default empty.
  * }
- * @param int|WP_Comment $comment Comment being replied to. Default current comment.
- * @param int|WP_Post    $post    Post ID or WP_Post object the comment is going to be displayed on.
+ * @param int|WP_Comment $comment Optional. Comment being replied to. Default current comment.
+ * @param int|WP_Post    $post    Optional. Post ID or WP_Post object the comment is going to be displayed on.
  *                                Default current post.
  * @return string|false|null Link to show comment form, if successful. False, if comments are closed.
  */
@@ -1744,7 +1818,7 @@
 		$data_attribute_string = '';
 
 		foreach ( $data_attributes as $name => $value ) {
-			$data_attribute_string .= " data-${name}=\"" . esc_attr( $value ) . '"';
+			$data_attribute_string .= " data-{$name}=\"" . esc_attr( $value ) . '"';
 		}
 
 		$data_attribute_string = trim( $data_attribute_string );
@@ -1767,17 +1841,19 @@
 		);
 	}
 
+	$comment_reply_link = $args['before'] . $link . $args['after'];
+
 	/**
 	 * Filters the comment reply link.
 	 *
 	 * @since 2.7.0
 	 *
-	 * @param string     $link    The HTML markup for the comment reply link.
-	 * @param array      $args    An array of arguments overriding the defaults.
-	 * @param WP_Comment $comment The object of the comment being replied.
-	 * @param WP_Post    $post    The WP_Post object.
+	 * @param string     $comment_reply_link The HTML markup for the comment reply link.
+	 * @param array      $args               An array of arguments overriding the defaults.
+	 * @param WP_Comment $comment            The object of the comment being replied.
+	 * @param WP_Post    $post               The WP_Post object.
 	 */
-	return apply_filters( 'comment_reply_link', $args['before'] . $link . $args['after'], $args, $comment, $post );
+	return apply_filters( 'comment_reply_link', $comment_reply_link, $args, $comment, $post );
 }
 
 /**
@@ -1788,8 +1864,8 @@
  * @see get_comment_reply_link()
  *
  * @param array          $args    Optional. Override default options. Default empty array.
- * @param int|WP_Comment $comment Comment being replied to. Default current comment.
- * @param int|WP_Post    $post    Post ID or WP_Post object the comment is going to be displayed on.
+ * @param int|WP_Comment $comment Optional. Comment being replied to. Default current comment.
+ * @param int|WP_Post    $post    Optional. Post ID or WP_Post object the comment is going to be displayed on.
  *                                Default current post.
  */
 function comment_reply_link( $args = array(), $comment = null, $post = null ) {
@@ -1858,17 +1934,18 @@
 			$args['reply_text']
 		);
 	}
-	$formatted_link = $args['before'] . $link . $args['after'];
+
+	$post_reply_link = $args['before'] . $link . $args['after'];
 
 	/**
 	 * Filters the formatted post comments link HTML.
 	 *
 	 * @since 2.7.0
 	 *
-	 * @param string      $formatted The HTML-formatted post comments link.
-	 * @param int|WP_Post $post      The post ID or WP_Post object.
+	 * @param string      $post_reply_link The HTML-formatted post comments link.
+	 * @param int|WP_Post $post            The post ID or WP_Post object.
 	 */
-	return apply_filters( 'post_comments_link', $formatted_link, $post );
+	return apply_filters( 'post_comments_link', $post_reply_link, $post );
 }
 
 /**
@@ -1879,7 +1956,7 @@
  * @see get_post_reply_link()
  *
  * @param array       $args Optional. Override default options. Default empty array.
- * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on.
+ * @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on.
  *                          Default current post.
  */
 function post_reply_link( $args = array(), $post = null ) {
@@ -1890,31 +1967,41 @@
  * Retrieves HTML content for cancel comment reply link.
  *
  * @since 2.7.0
+ * @since 6.2.0 Added the `$post` parameter.
  *
- * @param string $text Optional. Text to display for cancel reply link. If empty,
- *                     defaults to 'Click here to cancel reply'. Default empty.
+ * @param string           $link_text Optional. Text to display for cancel reply link. If empty,
+ *                                    defaults to 'Click here to cancel reply'. Default empty.
+ * @param int|WP_Post|null $post      Optional. The post the comment thread is being
+ *                                    displayed for. Defaults to the current global post.
  * @return string
  */
-function get_cancel_comment_reply_link( $text = '' ) {
-	if ( empty( $text ) ) {
-		$text = __( 'Click here to cancel reply.' );
+function get_cancel_comment_reply_link( $link_text = '', $post = null ) {
+	if ( empty( $link_text ) ) {
+		$link_text = __( 'Click here to cancel reply.' );
 	}
 
-	$style = isset( $_GET['replytocom'] ) ? '' : ' style="display:none;"';
-	$link  = esc_html( remove_query_arg( array( 'replytocom', 'unapproved', 'moderation-hash' ) ) ) . '#respond';
+	$post        = get_post( $post );
+	$reply_to_id = $post ? _get_comment_reply_id( $post->ID ) : 0;
+	$link_style  = 0 !== $reply_to_id ? '' : ' style="display:none;"';
+	$link_url    = esc_url( remove_query_arg( array( 'replytocom', 'unapproved', 'moderation-hash' ) ) ) . '#respond';
 
-	$formatted_link = '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>';
+	$cancel_comment_reply_link = sprintf(
+		'<a rel="nofollow" id="cancel-comment-reply-link" href="%1$s"%2$s>%3$s</a>',
+		$link_url,
+		$link_style,
+		$link_text
+	);
 
 	/**
 	 * Filters the cancel comment reply link HTML.
 	 *
 	 * @since 2.7.0
 	 *
-	 * @param string $formatted_link The HTML-formatted cancel comment reply link.
-	 * @param string $link           Cancel comment reply link URL.
-	 * @param string $text           Cancel comment reply link text.
+	 * @param string $cancel_comment_reply_link The HTML-formatted cancel comment reply link.
+	 * @param string $link_url                  Cancel comment reply link URL.
+	 * @param string $link_text                 Cancel comment reply link text.
 	 */
-	return apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text );
+	return apply_filters( 'cancel_comment_reply_link', $cancel_comment_reply_link, $link_url, $link_text );
 }
 
 /**
@@ -1922,40 +2009,45 @@
  *
  * @since 2.7.0
  *
- * @param string $text Optional. Text to display for cancel reply link. If empty,
+ * @param string $link_text Optional. Text to display for cancel reply link. If empty,
  *                     defaults to 'Click here to cancel reply'. Default empty.
  */
-function cancel_comment_reply_link( $text = '' ) {
-	echo get_cancel_comment_reply_link( $text );
+function cancel_comment_reply_link( $link_text = '' ) {
+	echo get_cancel_comment_reply_link( $link_text );
 }
 
 /**
  * Retrieves hidden input HTML for replying to comments.
  *
  * @since 3.0.0
+ * @since 6.2.0 Renamed `$post_id` to `$post` and added WP_Post support.
  *
- * @param int $post_id Optional. Post ID. Defaults to the current post ID.
+ * @param int|WP_Post|null $post Optional. The post the comment is being displayed for.
+ *                               Defaults to the current global post.
  * @return string Hidden input HTML for replying to comments.
  */
-function get_comment_id_fields( $post_id = 0 ) {
-	if ( empty( $post_id ) ) {
-		$post_id = get_the_ID();
+function get_comment_id_fields( $post = null ) {
+	$post = get_post( $post );
+	if ( ! $post ) {
+		return '';
 	}
 
-	$reply_to_id = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0;
-	$result      = "<input type='hidden' name='comment_post_ID' value='$post_id' id='comment_post_ID' />\n";
-	$result     .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$reply_to_id' />\n";
+	$post_id     = $post->ID;
+	$reply_to_id = _get_comment_reply_id( $post_id );
+
+	$comment_id_fields  = "<input type='hidden' name='comment_post_ID' value='$post_id' id='comment_post_ID' />\n";
+	$comment_id_fields .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$reply_to_id' />\n";
 
 	/**
 	 * Filters the returned comment ID fields.
 	 *
 	 * @since 3.0.0
 	 *
-	 * @param string $result      The HTML-formatted hidden ID field comment elements.
-	 * @param int    $post_id     The post ID.
-	 * @param int    $reply_to_id The ID of the comment being replied to.
+	 * @param string $comment_id_fields The HTML-formatted hidden ID field comment elements.
+	 * @param int    $post_id           The post ID.
+	 * @param int    $reply_to_id       The ID of the comment being replied to.
 	 */
-	return apply_filters( 'comment_id_fields', $result, $post_id, $reply_to_id );
+	return apply_filters( 'comment_id_fields', $comment_id_fields, $post_id, $reply_to_id );
 }
 
 /**
@@ -1967,13 +2059,15 @@
  * This tag must be within the `<form>` section of the `comments.php` template.
  *
  * @since 2.7.0
+ * @since 6.2.0 Renamed `$post_id` to `$post` and added WP_Post support.
  *
  * @see get_comment_id_fields()
  *
- * @param int $post_id Optional. Post ID. Defaults to the current post ID.
+ * @param int|WP_Post|null $post Optional. The post the comment is being displayed for.
+ *                               Defaults to the current global post.
  */
-function comment_id_fields( $post_id = 0 ) {
-	echo get_comment_id_fields( $post_id );
+function comment_id_fields( $post = null ) {
+	echo get_comment_id_fields( $post );
 }
 
 /**
@@ -1985,18 +2079,21 @@
  *           comment. See https://core.trac.wordpress.org/changeset/36512.
  *
  * @since 2.7.0
+ * @since 6.2.0 Added the `$post` parameter.
  *
  * @global WP_Comment $comment Global comment object.
  *
- * @param string|false $no_reply_text  Optional. Text to display when not replying to a comment.
- *                                     Default false.
- * @param string|false $reply_text     Optional. Text to display when replying to a comment.
- *                                     Default false. Accepts "%s" for the author of the comment
- *                                     being replied to.
- * @param bool         $link_to_parent Optional. Boolean to control making the author's name a link
- *                                     to their comment. Default true.
+ * @param string|false      $no_reply_text  Optional. Text to display when not replying to a comment.
+ *                                          Default false.
+ * @param string|false      $reply_text     Optional. Text to display when replying to a comment.
+ *                                          Default false. Accepts "%s" for the author of the comment
+ *                                          being replied to.
+ * @param bool              $link_to_parent Optional. Boolean to control making the author's name a link
+ *                                          to their comment. Default true.
+ * @param int|WP_Post|null  $post           Optional. The post that the comment form is being displayed for.
+ *                                          Defaults to the current global post.
  */
-function comment_form_title( $no_reply_text = false, $reply_text = false, $link_to_parent = true ) {
+function comment_form_title( $no_reply_text = false, $reply_text = false, $link_to_parent = true, $post = null ) {
 	global $comment;
 
 	if ( false === $no_reply_text ) {
@@ -2008,22 +2105,71 @@
 		$reply_text = __( 'Leave a Reply to %s' );
 	}
 
-	$reply_to_id = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0;
+	$post = get_post( $post );
+	if ( ! $post ) {
+		echo $no_reply_text;
+		return;
+	}
 
-	if ( 0 == $reply_to_id ) {
+	$reply_to_id = _get_comment_reply_id( $post->ID );
+
+	if ( 0 === $reply_to_id ) {
 		echo $no_reply_text;
+		return;
+	}
+
+	// Sets the global so that template tags can be used in the comment form.
+	$comment = get_comment( $reply_to_id );
+
+	if ( $link_to_parent ) {
+		$comment_author = sprintf(
+			'<a href="#comment-%1$s">%2$s</a>',
+			get_comment_ID(),
+			get_comment_author( $reply_to_id )
+		);
 	} else {
-		// Sets the global so that template tags can be used in the comment form.
-		$comment = get_comment( $reply_to_id );
+		$comment_author = get_comment_author( $reply_to_id );
+	}
+
+	printf( $reply_text, $comment_author );
+}
 
-		if ( $link_to_parent ) {
-			$author = '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $comment ) . '</a>';
-		} else {
-			$author = get_comment_author( $comment );
-		}
+/**
+ * Gets the comment's reply to ID from the $_GET['replytocom'].
+ *
+ * @since 6.2.0
+ *
+ * @access private
+ *
+ * @param int|WP_Post $post The post the comment is being displayed for.
+ *                          Defaults to the current global post.
+ * @return int Comment's reply to ID.
+ */
+function _get_comment_reply_id( $post = null ) {
+	$post = get_post( $post );
+
+	if ( ! $post || ! isset( $_GET['replytocom'] ) || ! is_numeric( $_GET['replytocom'] ) ) {
+		return 0;
+	}
 
-		printf( $reply_text, $author );
+	$reply_to_id = (int) $_GET['replytocom'];
+
+	/*
+	 * Validate the comment.
+	 * Bail out if it does not exist, is not approved, or its
+	 * `comment_post_ID` does not match the given post ID.
+	 */
+	$comment = get_comment( $reply_to_id );
+
+	if (
+		! $comment instanceof WP_Comment ||
+		0 === (int) $comment->comment_approved ||
+		$post->ID !== (int) $comment->comment_post_ID
+	) {
+		return 0;
 	}
+
+	return $reply_to_id;
 }
 
 /**
@@ -2033,7 +2179,7 @@
  *
  * @since 2.7.0
  *
- * @see WP_Query->comments
+ * @see WP_Query::$comments
  *
  * @global WP_Query $wp_query           WordPress Query object.
  * @global int      $comment_alt
@@ -2064,7 +2210,7 @@
  *     @type bool     $short_ping        Whether to output short pings. Default false.
  *     @type bool     $echo              Whether to echo the output or return it. Default true.
  * }
- * @param WP_Comment[] $comments Optional. Array of WP_Comment objects.
+ * @param WP_Comment[] $comments Optional. Array of WP_Comment objects. Default null.
  * @return void|string Void if 'echo' argument is true, or no comments to list.
  *                     Otherwise, HTML list of comments.
  */
@@ -2241,10 +2387,8 @@
 		$parsed_args['reverse_top_level'] = ( 'desc' === get_option( 'comment_order' ) );
 	}
 
-	wp_queue_comments_for_comment_meta_lazyload( $_comments );
-
 	if ( empty( $parsed_args['walker'] ) ) {
-		$walker = new Walker_Comment;
+		$walker = new Walker_Comment();
 	} else {
 		$walker = $parsed_args['walker'];
 	}
@@ -2294,7 +2438,8 @@
  *     }
  *     @type string $comment_field        The comment textarea field HTML.
  *     @type string $must_log_in          HTML element for a 'must be logged in to comment' message.
- *     @type string $logged_in_as         HTML element for a 'logged in as [user]' message.
+ *     @type string $logged_in_as         The HTML for the 'logged in as [user]' message, the Edit profile link,
+ *                                        and the Log out link.
  *     @type string $comment_notes_before HTML element for a message displayed before the comment fields
  *                                        if the user is not logged in.
  *                                        Default 'Your email address will not be published.'.
@@ -2324,18 +2469,19 @@
  *                                        submit button markup and %2$s is the comment hidden fields.
  *     @type string $format               The comment form format. Default 'xhtml'. Accepts 'xhtml', 'html5'.
  * }
- * @param int|WP_Post $post_id Post ID or WP_Post object to generate the form for. Default current post.
+ * @param int|WP_Post $post Optional. Post ID or WP_Post object to generate the form for. Default current post.
  */
-function comment_form( $args = array(), $post_id = null ) {
-	if ( null === $post_id ) {
-		$post_id = get_the_ID();
-	}
+function comment_form( $args = array(), $post = null ) {
+	$post = get_post( $post );
 
-	// Exit the function when comments for the post are closed.
-	if ( ! comments_open( $post_id ) ) {
+	// Exit the function if the post is invalid or comments are closed.
+	if ( ! $post || ! comments_open( $post ) ) {
 		/**
 		 * Fires after the comment form if comments are closed.
 		 *
+		 * For backward compatibility, this action also fires if comment_form()
+		 * is called with an invalid post object or ID.
+		 *
 		 * @since 3.0.0
 		 */
 		do_action( 'comment_form_comments_closed' );
@@ -2343,6 +2489,7 @@
 		return;
 	}
 
+	$post_id       = $post->ID;
 	$commenter     = wp_get_current_commenter();
 	$user          = wp_get_current_user();
 	$user_identity = $user->exists() ? $user->display_name : '';
@@ -2359,8 +2506,9 @@
 	$required_attribute = ( $html5 ? ' required' : ' required="required"' );
 	$checked_attribute  = ( $html5 ? ' checked' : ' checked="checked"' );
 
-	// Identify required fields visually.
-	$required_indicator = ' <span class="required" aria-hidden="true">*</span>';
+	// Identify required fields visually and create a message about the indicator.
+	$required_indicator = ' ' . wp_required_field_indicator();
+	$required_text      = ' ' . wp_required_field_message();
 
 	$fields = array(
 		'author' => sprintf(
@@ -2371,7 +2519,7 @@
 				( $req ? $required_indicator : '' )
 			),
 			sprintf(
-				'<input id="author" name="author" type="text" value="%s" size="30" maxlength="245"%s />',
+				'<input id="author" name="author" type="text" value="%s" size="30" maxlength="245" autocomplete="name"%s />',
 				esc_attr( $commenter['comment_author'] ),
 				( $req ? $required_attribute : '' )
 			)
@@ -2384,7 +2532,7 @@
 				( $req ? $required_indicator : '' )
 			),
 			sprintf(
-				'<input id="email" name="email" %s value="%s" size="30" maxlength="100" aria-describedby="email-notes"%s />',
+				'<input id="email" name="email" %s value="%s" size="30" maxlength="100" aria-describedby="email-notes" autocomplete="email"%s />',
 				( $html5 ? 'type="email"' : 'type="text"' ),
 				esc_attr( $commenter['comment_author_email'] ),
 				( $req ? $required_attribute : '' )
@@ -2397,7 +2545,7 @@
 				__( 'Website' )
 			),
 			sprintf(
-				'<input id="url" name="url" %s value="%s" size="30" maxlength="200" />',
+				'<input id="url" name="url" %s value="%s" size="30" maxlength="200" autocomplete="url" />',
 				( $html5 ? 'type="url"' : 'type="text"' ),
 				esc_attr( $commenter['comment_author_url'] )
 			)
@@ -2425,12 +2573,6 @@
 		}
 	}
 
-	$required_text = sprintf(
-		/* translators: %s: Asterisk symbol (*). */
-		' <span class="required-field-message" aria-hidden="true">' . __( 'Required fields are marked %s' ) . '</span>',
-		trim( $required_indicator )
-	);
-
 	/**
 	 * Filters the default comment form fields.
 	 *
@@ -2463,12 +2605,10 @@
 		'logged_in_as'         => sprintf(
 			'<p class="logged-in-as">%s%s</p>',
 			sprintf(
-				/* translators: 1: Edit user link, 2: Accessibility text, 3: User name, 4: Logout URL. */
-				__( '<a href="%1$s" aria-label="%2$s">Logged in as %3$s</a>. <a href="%4$s">Log out?</a>' ),
+				/* translators: 1: User name, 2: Edit user link, 3: Logout URL. */
+				__( 'Logged in as %1$s. <a href="%2$s">Edit your profile</a>. <a href="%3$s">Log out?</a>' ),
+				$user_identity,
 				get_edit_user_link(),
-				/* translators: %s: User name. */
-				esc_attr( sprintf( __( 'Logged in as %s. Edit your profile.' ), $user_identity ) ),
-				$user_identity,
 				/** This filter is documented in wp-includes/link-template.php */
 				wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) )
 			),
@@ -2519,7 +2659,7 @@
 	$args = array_merge( $defaults, $args );
 
 	// Remove `aria-describedby` from the email field if there's no associated description.
-	if ( isset( $args['fields']['email'] ) && false === strpos( $args['comment_notes_before'], 'id="email-notes"' ) ) {
+	if ( isset( $args['fields']['email'] ) && ! str_contains( $args['comment_notes_before'], 'id="email-notes"' ) ) {
 		$args['fields']['email'] = str_replace(
 			' aria-describedby="email-notes"',
 			'',
@@ -2538,7 +2678,7 @@
 		<?php
 		echo $args['title_reply_before'];
 
-		comment_form_title( $args['title_reply'], $args['title_reply_to'] );
+		comment_form_title( $args['title_reply'], $args['title_reply_to'], true, $post_id );
 
 		if ( get_option( 'thread_comments' ) ) {
 			echo $args['cancel_reply_before'];
@@ -2584,7 +2724,8 @@
 				 *
 				 * @since 3.0.0
 				 *
-				 * @param string $args_logged_in The logged-in-as HTML-formatted message.
+				 * @param string $args_logged_in The HTML for the 'logged in as [user]' message,
+				 *                               the Edit profile link, and the Log out link.
 				 * @param array  $commenter      An array containing the comment author's
 				 *                               username, email, and URL.
 				 * @param string $user_identity  If the commenter is a registered user,