wp/wp-includes/comment-template.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
--- a/wp/wp-includes/comment-template.php	Tue Dec 15 15:52:01 2020 +0100
+++ b/wp/wp-includes/comment-template.php	Wed Sep 21 18:19:35 2022 +0200
@@ -422,17 +422,17 @@
  * @since 2.7.0
  * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object.
  *
- * @param string|array   $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 bool           $echo     Optional. Whether to echo or return the output.
- *                                 Default true.
+ * @param string|string[] $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 bool            $echo     Optional. Whether to echo or return the output.
+ *                                  Default true.
  * @return void|string Void if `$echo` argument is true, comment classes if `$echo` is false.
  */
 function comment_class( $class = '', $comment = null, $post_id = null, $echo = true ) {
 	// Separates classes with a single space, collates classes for comment DIV.
-	$class = 'class="' . join( ' ', get_comment_class( $class, $comment, $post_id ) ) . '"';
+	$class = 'class="' . implode( ' ', get_comment_class( $class, $comment, $post_id ) ) . '"';
 
 	if ( $echo ) {
 		echo $class;
@@ -451,9 +451,9 @@
  * @global int $comment_depth
  * @global int $comment_thread_alt
  *
- * @param string|array   $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[] $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.
  * @return string[] An array of classes.
  */
 function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
@@ -530,7 +530,7 @@
 	 * @since 2.7.0
 	 *
 	 * @param string[]    $classes    An array of comment classes.
-	 * @param string      $class      A comma-separated list of additional classes added to the list.
+	 * @param string[]    $class      An array of additional classes added to the list.
 	 * @param int         $comment_id The comment ID.
 	 * @param WP_Comment  $comment    The comment object.
 	 * @param int|WP_Post $post_id    The post ID or WP_Post object.
@@ -544,7 +544,7 @@
  * @since 1.5.0
  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
  *
- * @param string         $format     Optional. The format of the date. Default user's setting.
+ * @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.
  *                                   Default current comment.
  * @return string The comment's date.
@@ -562,7 +562,7 @@
 	 * @since 1.5.0
 	 *
 	 * @param string|int $date    Formatted date string or Unix timestamp.
-	 * @param string     $format  The format of the date.
+	 * @param string     $format  PHP date format.
 	 * @param WP_Comment $comment The comment object.
 	 */
 	return apply_filters( 'get_comment_date', $date, $format, $comment );
@@ -574,7 +574,7 @@
  * @since 0.71
  * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
  *
- * @param string         $format     Optional. The format of the date. Default user's settings.
+ * @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.
  *                                   Default current comment.
  */
@@ -604,7 +604,7 @@
 	}
 
 	/* translators: Maximum number of words used in a comment excerpt. */
-	$comment_excerpt_length = intval( _x( '20', 'comment_excerpt_length' ) );
+	$comment_excerpt_length = (int) _x( '20', 'comment_excerpt_length' );
 
 	/**
 	 * Filters the maximum number of words used in the comment excerpt.
@@ -878,10 +878,10 @@
  * @since 0.71
  * @since 5.4.0 The `$deprecated` parameter was changed to `$post_id`.
  *
- * @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|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`.
  */
 function comments_number( $zero = false, $one = false, $more = false, $post_id = 0 ) {
 	echo get_comments_number_text( $zero, $one, $more, $post_id );
@@ -1033,7 +1033,7 @@
  *
  * @since 1.5.0
  *
- * @param string $format    Optional. The format of the time. Default user's settings.
+ * @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.
@@ -1054,7 +1054,7 @@
 	 * @since 1.5.0
 	 *
 	 * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
-	 * @param string     $format    Date format.
+	 * @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.
@@ -1067,7 +1067,7 @@
  *
  * @since 0.71
  *
- * @param string $format Optional. The format of the time. Default user's settings.
+ * @param string $format Optional. PHP time format. Defaults to the 'time_format' option.
  */
 function comment_time( $format = '' ) {
 	echo get_comment_time( $format );
@@ -1108,9 +1108,9 @@
  *
  * @since 0.71
  *
- * @param string $commenttxt   Optional. String to display for comment type. Default false.
- * @param string $trackbacktxt Optional. String to display for trackback type. Default false.
- * @param string $pingbacktxt  Optional. String to display for pingback type. Default false.
+ * @param string|false $commenttxt   Optional. String to display for comment type. Default false.
+ * @param string|false $trackbacktxt Optional. String to display for trackback type. Default false.
+ * @param string|false $pingbacktxt  Optional. String to display for pingback type. Default false.
  */
 function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) {
 	if ( false === $commenttxt ) {
@@ -1199,7 +1199,7 @@
  *
  * @since 0.71
  *
- * @param int $deprecated Not used (Was $timezone = 0).
+ * @param int|string $deprecated Not used (Was $timezone = 0).
  */
 function trackback_rdf( $deprecated = '' ) {
 	if ( ! empty( $deprecated ) ) {
@@ -1434,6 +1434,24 @@
 				$top_level_args['include_unapproved'] = $comment_args['include_unapproved'];
 			}
 
+			/**
+			 * Filters the arguments used in the top level comments query.
+			 *
+			 * @since 5.6.0
+			 *
+			 * @see WP_Comment_Query::__construct()
+			 *
+			 * @param array $top_level_args {
+			 *     The top level query arguments for the comments template.
+			 *
+			 *     @type bool         $count   Whether to return a comment count.
+			 *     @type string|array $orderby The field(s) to order by.
+			 *     @type int          $post_id The post ID.
+			 *     @type string|array $status  The comment status to limit results by.
+			 * }
+			 */
+			$top_level_args = apply_filters( 'comments_template_top_level_query_args', $top_level_args );
+
 			$top_level_count = $top_level_query->query( $top_level_args );
 
 			$comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
@@ -1463,7 +1481,8 @@
 	 *     @type int          $number                    Number of comments to fetch.
 	 * }
 	 */
-	$comment_args  = apply_filters( 'comments_template_query_args', $comment_args );
+	$comment_args = apply_filters( 'comments_template_query_args', $comment_args );
+
 	$comment_query = new WP_Comment_Query( $comment_args );
 	$_comments     = $comment_query->comments;
 
@@ -1687,6 +1706,12 @@
 		return false;
 	}
 
+	if ( get_option( 'page_comments' ) ) {
+		$permalink = str_replace( '#comment-' . $comment->comment_ID, '', get_comment_link( $comment ) );
+	} else {
+		$permalink = get_permalink( $post->ID );
+	}
+
 	/**
 	 * Filters the comment reply link arguments.
 	 *
@@ -1731,7 +1756,7 @@
 						'unapproved'      => false,
 						'moderation-hash' => false,
 					),
-					get_permalink( $post->ID )
+					$permalink
 				)
 			) . '#' . $args['respond_id'],
 			$data_attribute_string,
@@ -1961,13 +1986,13 @@
  *
  * @global WP_Comment $comment Global comment object.
  *
- * @param string $no_reply_text  Optional. Text to display when not replying to a comment.
- *                               Default false.
- * @param string $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 string $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.
  */
 function comment_form_title( $no_reply_text = false, $reply_text = false, $link_to_parent = true ) {
 	global $comment;
@@ -2205,7 +2230,7 @@
 		}
 	}
 	// Validation check.
-	$parsed_args['page'] = intval( $parsed_args['page'] );
+	$parsed_args['page'] = (int) $parsed_args['page'];
 	if ( 0 == $parsed_args['page'] && 0 != $parsed_args['per_page'] ) {
 		$parsed_args['page'] = 1;
 	}
@@ -2236,11 +2261,11 @@
 /**
  * Outputs a complete commenting form for use within a template.
  *
- * Most strings and form fields may be controlled through the $args array passed
+ * Most strings and form fields may be controlled through the `$args` array passed
  * into the function, while you may also choose to use the {@see 'comment_form_default_fields'}
  * filter to modify the array of default fields if you'd just like to add a new
  * one or remove a single field. All fields are also individually passed through
- * a filter of the {@see 'comment_form_field_$name'} where $name is the key used
+ * a filter of the {@see 'comment_form_field_$name'} where `$name` is the key used
  * in the array of fields.
  *
  * @since 3.0.0
@@ -2480,7 +2505,7 @@
 	 */
 	$args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
 
-	// Ensure that the filtered args contain all required default values.
+	// Ensure that the filtered arguments contain all required default values.
 	$args = array_merge( $defaults, $args );
 
 	// Remove `aria-describedby` from the email field if there's no associated description.