diff -r 48c4eec2b7e6 -r 8c2e4d02f4ef wp/wp-includes/comment-template.php --- a/wp/wp-includes/comment-template.php Fri Sep 05 18:40:08 2025 +0200 +++ b/wp/wp-includes/comment-template.php Fri Sep 05 18:52:52 2025 +0200 @@ -29,7 +29,7 @@ } elseif ( is_scalar( $comment_id ) ) { $comment_id = (string) $comment_id; } else { - $comment_id = ''; + $comment_id = '0'; } if ( empty( $comment->comment_author ) ) { @@ -233,7 +233,13 @@ 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; + if ( ! empty( $comment->comment_ID ) ) { + $comment_id = $comment->comment_ID; + } elseif ( is_scalar( $comment_id ) ) { + $comment_id = (string) $comment_id; + } else { + $comment_id = '0'; + } $comment_author_url = get_comment_author_url( $comment ); $comment_author = get_comment_author( $comment ); @@ -558,7 +564,7 @@ ++$comment_alt; // Alt for top-level comments. - if ( 1 == $comment_depth ) { + if ( 1 === $comment_depth ) { if ( $comment_thread_alt % 2 ) { $classes[] = 'thread-odd'; $classes[] = 'thread-alt'; @@ -808,9 +814,9 @@ $cpage = $args['page']; - if ( '' == $cpage ) { + if ( '' === $cpage ) { if ( ! empty( $in_comment_loop ) ) { - $cpage = get_query_var( 'cpage' ); + $cpage = (int) get_query_var( 'cpage' ); } else { // Requires a database hit, so we only do it when we can't figure out from context. $cpage = get_page_of_comment( $comment->comment_ID, $args ); @@ -955,7 +961,7 @@ * @return string Language string for the number of comments a post has. */ function get_comments_number_text( $zero = false, $one = false, $more = false, $post = 0 ) { - $comments_number = get_comments_number( $post ); + $comments_number = (int) get_comments_number( $post ); if ( $comments_number > 1 ) { if ( false === $more ) { @@ -990,7 +996,7 @@ $comments_number_text = str_replace( '%', number_format_i18n( $comments_number ), $more ); } - } elseif ( 0 == $comments_number ) { + } elseif ( 0 === $comments_number ) { $comments_number_text = ( false === $zero ) ? __( 'No Comments' ) : $zero; } else { // Must be one. $comments_number_text = ( false === $one ) ? __( '1 Comment' ) : $one; @@ -1599,7 +1605,7 @@ $overridden_cpage = false; - if ( '' == get_query_var( 'cpage' ) && $wp_query->max_num_comment_pages > 1 ) { + if ( '' === get_query_var( 'cpage' ) && $wp_query->max_num_comment_pages > 1 ) { set_query_var( 'cpage', 'newest' === get_option( 'default_comments_page' ) ? get_comment_pages_count() : 1 ); $overridden_cpage = true; } @@ -1642,7 +1648,7 @@ function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) { $post_id = get_the_ID(); $post_title = get_the_title(); - $comments_number = get_comments_number( $post_id ); + $comments_number = (int) get_comments_number( $post_id ); if ( false === $zero ) { /* translators: %s: Post title. */ @@ -1669,7 +1675,7 @@ $none = sprintf( __( 'Comments Off on %s' ), $post_title ); } - if ( 0 == $comments_number && ! comments_open() && ! pings_open() ) { + if ( 0 === $comments_number && ! comments_open() && ! pings_open() ) { printf( '%2$s', ! empty( $css_class ) ? ' class="' . esc_attr( $css_class ) . '"' : '', @@ -1683,7 +1689,7 @@ return; } - if ( 0 == $comments_number ) { + if ( 0 === $comments_number ) { $respond_link = get_permalink() . '#respond'; /** * Filters the respond link when a post has no comments. @@ -1727,19 +1733,23 @@ * @param array $args { * Optional. Override default arguments. * - * @type string $add_below The first part of the selector used to identify the comment to respond below. - * The resulting value is passed as the first parameter to addComment.moveForm(), - * concatenated as $add_below-$comment->comment_ID. Default 'comment'. - * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter - * to addComment.moveForm(), and appended to the link URL as a hash value. - * Default 'respond'. - * @type string $reply_text The text of the Reply link. Default 'Reply'. - * @type string $login_text The text of the link to reply if logged out. Default 'Log in to Reply'. - * @type int $max_depth The max depth of the comment tree. Default 0. - * @type int $depth The depth of the new comment. Must be greater than 0 and less than the value - * of the 'thread_comments_depth' option set in Settings > Discussion. Default 0. - * @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. + * @type string $add_below The first part of the selector used to identify the comment to respond below. + * The resulting value is passed as the first parameter to addComment.moveForm(), + * concatenated as $add_below-$comment->comment_ID. Default 'comment'. + * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter + * to addComment.moveForm(), and appended to the link URL as a hash value. + * Default 'respond'. + * @type string $reply_text The visible text of the Reply link. Default 'Reply'. + * @type string $reply_to_text The accessible name of the Reply link, using `%s` as a placeholder + * for the comment author's name. Default 'Reply to %s'. + * Should start with the visible `reply_text` value. + * @type bool $show_reply_to_text Whether to use `reply_to_text` as visible link text. Default false. + * @type string $login_text The text of the link to reply if logged out. Default 'Log in to Reply'. + * @type int $max_depth The max depth of the comment tree. Default 0. + * @type int $depth The depth of the new comment. Must be greater than 0 and less than the value + * of the 'thread_comments_depth' option set in Settings > Discussion. Default 0. + * @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 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. @@ -1748,21 +1758,25 @@ */ function get_comment_reply_link( $args = array(), $comment = null, $post = null ) { $defaults = array( - 'add_below' => 'comment', - 'respond_id' => 'respond', - 'reply_text' => __( 'Reply' ), + 'add_below' => 'comment', + 'respond_id' => 'respond', + 'reply_text' => __( 'Reply' ), /* translators: Comment reply button text. %s: Comment author name. */ - 'reply_to_text' => __( 'Reply to %s' ), - 'login_text' => __( 'Log in to Reply' ), - 'max_depth' => 0, - 'depth' => 0, - 'before' => '', - 'after' => '', + 'reply_to_text' => __( 'Reply to %s' ), + 'login_text' => __( 'Log in to Reply' ), + 'max_depth' => 0, + 'depth' => 0, + 'before' => '', + 'after' => '', + 'show_reply_to_text' => false, ); $args = wp_parse_args( $args, $defaults ); - if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) { + $args['max_depth'] = (int) $args['max_depth']; + $args['depth'] = (int) $args['depth']; + + if ( 0 === $args['depth'] || $args['max_depth'] <= $args['depth'] ) { return; } @@ -1823,8 +1837,14 @@ $data_attribute_string = trim( $data_attribute_string ); + $reply_text = $args['show_reply_to_text'] + ? sprintf( $args['reply_to_text'], get_comment_author( $comment ) ) + : $args['reply_text']; + + $aria_label = $args['show_reply_to_text'] ? '' : sprintf( $args['reply_to_text'], get_comment_author( $comment ) ); + $link = sprintf( - "%s", + '%s', esc_url( add_query_arg( array( @@ -1836,8 +1856,8 @@ ) ) . '#' . $args['respond_id'], $data_attribute_string, - esc_attr( sprintf( $args['reply_to_text'], get_comment_author( $comment ) ) ), - $args['reply_text'] + $aria_label ? ' aria-label="' . esc_attr( $aria_label ) . '"' : '', + $reply_text ); } @@ -2083,15 +2103,15 @@ * * @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 int|WP_Post|null $post Optional. The post that the comment form is being displayed for. - * Defaults to the current global post. + * @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, $post = null ) { global $comment; @@ -2274,13 +2294,13 @@ * perform a separate comment query and allow Walker_Comment to paginate. */ if ( $parsed_args['page'] || $parsed_args['per_page'] ) { - $current_cpage = get_query_var( 'cpage' ); + $current_cpage = (int) get_query_var( 'cpage' ); if ( ! $current_cpage ) { $current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages; } - $current_per_page = get_query_var( 'comments_per_page' ); - if ( $parsed_args['page'] != $current_cpage || $parsed_args['per_page'] != $current_per_page ) { + $current_per_page = (int) get_query_var( 'comments_per_page' ); + if ( (int) $parsed_args['page'] !== $current_cpage || (int) $parsed_args['per_page'] !== $current_per_page ) { $comment_args = array( 'post_id' => get_the_ID(), 'orderby' => 'comment_date_gmt', @@ -2331,15 +2351,15 @@ if ( $wp_query->max_num_comment_pages ) { $default_comments_page = get_option( 'default_comments_page' ); - $cpage = get_query_var( 'cpage' ); + $cpage = (int) get_query_var( 'cpage' ); + if ( 'newest' === $default_comments_page ) { $parsed_args['cpage'] = $cpage; - + } elseif ( 1 === $cpage ) { /* - * When first page shows oldest comments, post permalink is the same as - * the comment permalink. - */ - } elseif ( 1 == $cpage ) { + * When the first page shows the oldest comments, + * post permalink is the same as the comment permalink. + */ $parsed_args['cpage'] = ''; } else { $parsed_args['cpage'] = $cpage; @@ -2372,14 +2392,16 @@ if ( empty( $overridden_cpage ) ) { $parsed_args['page'] = get_query_var( 'cpage' ); } else { - $threaded = ( -1 != $parsed_args['max_depth'] ); + $threaded = ( -1 !== (int) $parsed_args['max_depth'] ); $parsed_args['page'] = ( 'newest' === get_option( 'default_comments_page' ) ) ? get_comment_pages_count( $_comments, $parsed_args['per_page'], $threaded ) : 1; set_query_var( 'cpage', $parsed_args['page'] ); } } + // Validation check. - $parsed_args['page'] = (int) $parsed_args['page']; - if ( 0 == $parsed_args['page'] && 0 != $parsed_args['per_page'] ) { + $parsed_args['page'] = (int) $parsed_args['page']; + $parsed_args['per_page'] = (int) $parsed_args['per_page']; + if ( 0 === $parsed_args['page'] && 0 !== $parsed_args['per_page'] ) { $parsed_args['page'] = 1; } @@ -2424,6 +2446,7 @@ * @since 4.6.0 Introduced the 'action' argument. * @since 4.9.6 Introduced the 'cookies' default comment field. * @since 5.5.0 Introduced the 'class_container' argument. + * @since 6.8.2 Introduced the 'novalidate' argument. * * @param array $args { * Optional. Default arguments and form fields to override. @@ -2445,6 +2468,7 @@ * Default 'Your email address will not be published.'. * @type string $comment_notes_after HTML element for a message displayed after the textarea field. * @type string $action The comment form element action attribute. Default '/wp-comments-post.php'. + * @type bool $novalidate Whether the novalidate attribute is added to the comment form. Default false. * @type string $id_form The comment form element id attribute. Default 'commentform'. * @type string $id_submit The comment submit element id attribute. Default 'submit'. * @type string $class_container The comment form container class attribute. Default 'comment-respond'. @@ -2624,6 +2648,7 @@ ), 'comment_notes_after' => '', 'action' => site_url( '/wp-comments-post.php' ), + 'novalidate' => false, 'id_form' => 'commentform', 'id_submit' => 'submit', 'class_container' => 'comment-respond', @@ -2707,7 +2732,7 @@ esc_url( $args['action'] ), esc_attr( $args['id_form'] ), esc_attr( $args['class_form'] ), - ( $html5 ? ' novalidate' : '' ) + ( $args['novalidate'] ? ' novalidate' : '' ) ); /**