--- a/wp/wp-includes/comment-template.php Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-includes/comment-template.php Tue Sep 27 16:37:53 2022 +0200
@@ -22,10 +22,11 @@
* @return string The comment author
*/
function get_comment_author( $comment_ID = 0 ) {
- $comment = get_comment( $comment_ID );
+ $comment = get_comment( $comment_ID );
+ $comment_ID = ! empty( $comment->comment_ID ) ? $comment->comment_ID : $comment_ID;
if ( empty( $comment->comment_author ) ) {
- $user = $comment->user_id ? get_userdata( $comment->user_id ) : false;
+ $user = ! empty( $comment->user_id ) ? get_userdata( $comment->user_id ) : false;
if ( $user ) {
$author = $user->display_name;
} else {
@@ -42,10 +43,10 @@
* @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
*
* @param string $author The comment author's username.
- * @param int $comment_ID The comment ID.
+ * @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->comment_ID, $comment );
+ return apply_filters( 'get_comment_author', $author, $comment_ID, $comment );
}
/**
@@ -68,7 +69,7 @@
* @since 4.1.0 The `$comment_ID` parameter was added.
*
* @param string $author The comment author's username.
- * @param int $comment_ID The comment ID.
+ * @param string $comment_ID The comment ID as a numeric string.
*/
echo apply_filters( 'comment_author', $author, $comment->comment_ID );
}
@@ -93,7 +94,7 @@
* @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
*
* @param string $comment_author_email The comment author's email address.
- * @param int $comment_ID The comment ID.
+ * @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 );
@@ -125,7 +126,7 @@
* @since 4.1.0 The `$comment_ID` parameter was added.
*
* @param string $author_email The comment author's email address.
- * @param int $comment_ID The comment ID.
+ * @param string $comment_ID The comment ID as a numeric string.
*/
echo apply_filters( 'author_email', $author_email, $comment->comment_ID );
}
@@ -236,7 +237,7 @@
* @param string $return The HTML-formatted comment author link.
* Empty for an invalid URL.
* @param string $author The comment author's username.
- * @param int $comment_ID The comment ID.
+ * @param string $comment_ID The comment ID as a numeric string.
*/
return apply_filters( 'get_comment_author_link', $return, $author, $comment->comment_ID );
}
@@ -255,14 +256,14 @@
}
/**
- * Retrieve the IP address of the author of the current comment.
+ * 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.
*
* @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.
+ * @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 );
@@ -273,8 +274,8 @@
* @since 1.5.0
* @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
*
- * @param string $comment_author_IP The comment author's IP address.
- * @param int $comment_ID The comment ID.
+ * @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
@@ -320,9 +321,9 @@
* @since 1.5.0
* @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
*
- * @param string $url The comment author's URL.
- * @param int $comment_ID The comment ID.
- * @param WP_Comment $comment The comment object.
+ * @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.
*/
return apply_filters( 'get_comment_author_url', $url, $id, $comment );
}
@@ -347,7 +348,7 @@
* @since 4.1.0 The `$comment_ID` parameter was added.
*
* @param string $author_url The comment author's URL.
- * @param int $comment_ID The comment ID.
+ * @param string $comment_ID The comment ID as a numeric string.
*/
echo apply_filters( 'comment_url', $author_url, $comment->comment_ID );
}
@@ -422,22 +423,22 @@
* @since 2.7.0
* @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object.
*
- * @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.
+ * @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 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( $class = '', $comment = null, $post_id = null, $echo = true ) {
+function comment_class( $css_class = '', $comment = null, $post_id = null, $display = true ) {
// Separates classes with a single space, collates classes for comment DIV.
- $class = 'class="' . implode( ' ', get_comment_class( $class, $comment, $post_id ) ) . '"';
+ $css_class = 'class="' . implode( ' ', get_comment_class( $css_class, $comment, $post_id ) ) . '"';
- if ( $echo ) {
- echo $class;
+ if ( $display ) {
+ echo $css_class;
} else {
- return $class;
+ return $css_class;
}
}
@@ -451,12 +452,12 @@
* @global int $comment_depth
* @global int $comment_thread_alt
*
- * @param string|string[] $class Optional. One or more classes to add to the class list. Default empty.
+ * @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.
* @return string[] An array of classes.
*/
-function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
+function get_comment_class( $css_class = '', $comment_id = null, $post_id = null ) {
global $comment_alt, $comment_depth, $comment_thread_alt;
$classes = array();
@@ -515,11 +516,11 @@
$classes[] = "depth-$comment_depth";
- if ( ! empty( $class ) ) {
- if ( ! is_array( $class ) ) {
- $class = preg_split( '#\s+#', $class );
+ if ( ! empty( $css_class ) ) {
+ if ( ! is_array( $css_class ) ) {
+ $css_class = preg_split( '#\s+#', $css_class );
}
- $classes = array_merge( $classes, $class );
+ $classes = array_merge( $classes, $css_class );
}
$classes = array_map( 'esc_attr', $classes );
@@ -530,12 +531,12 @@
* @since 2.7.0
*
* @param string[] $classes An array of comment classes.
- * @param string[] $class An array of additional classes added to the list.
- * @param int $comment_id The comment ID.
+ * @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.
*/
- return apply_filters( 'comment_class', $classes, $class, $comment->comment_ID, $comment, $post_id );
+ return apply_filters( 'comment_class', $classes, $css_class, $comment->comment_ID, $comment, $post_id );
}
/**
@@ -624,7 +625,7 @@
* @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
*
* @param string $excerpt The comment excerpt text.
- * @param int $comment_ID The comment ID.
+ * @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 );
@@ -650,7 +651,7 @@
* @since 4.1.0 The `$comment_ID` parameter was added.
*
* @param string $comment_excerpt The comment excerpt text.
- * @param int $comment_ID The comment ID.
+ * @param string $comment_ID The comment ID as a numeric string.
*/
echo apply_filters( 'comment_excerpt', $comment_excerpt, $comment->comment_ID );
}
@@ -660,21 +661,22 @@
*
* @since 1.5.0
*
- * @return int The comment ID.
+ * @return string The comment ID as a numeric string.
*/
function get_comment_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
- $comment = get_comment();
+ $comment = get_comment();
+ $comment_ID = ! empty( $comment->comment_ID ) ? $comment->comment_ID : '0';
/**
* Filters the returned comment ID.
*
* @since 1.5.0
- * @since 4.1.0 The `$comment_ID` parameter was added.
+ * @since 4.1.0 The `$comment` parameter was added.
*
- * @param int $comment_ID The current comment ID.
+ * @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->comment_ID, $comment ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
+ return apply_filters( 'get_comment_ID', $comment_ID, $comment ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
}
/**
@@ -1097,7 +1099,7 @@
* @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 int $comment_ID The comment ID.
+ * @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 );
@@ -1241,7 +1243,7 @@
$_post = get_post( $post_id );
$post_id = $_post ? $_post->ID : 0;
- $open = ( 'open' === $_post->comment_status );
+ $open = ( $_post && ( 'open' === $_post->comment_status ) );
/**
* Filters whether the current post is open for comments.
@@ -1271,7 +1273,7 @@
$_post = get_post( $post_id );
$post_id = $_post ? $_post->ID : 0;
- $open = ( 'open' === $_post->ping_status );
+ $open = ( $_post && ( 'open' === $_post->ping_status ) );
/**
* Filters whether the current post is open for pings.
@@ -1736,7 +1738,7 @@
'postid' => $post->ID,
'belowelement' => $args['add_below'] . '-' . $comment->comment_ID,
'respondelement' => $args['respond_id'],
- 'replyto' => sprintf( $args['reply_to_text'], $comment->comment_author ),
+ 'replyto' => sprintf( $args['reply_to_text'], get_comment_author( $comment ) ),
);
$data_attribute_string = '';
@@ -1760,7 +1762,7 @@
)
) . '#' . $args['respond_id'],
$data_attribute_string,
- esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),
+ esc_attr( sprintf( $args['reply_to_text'], get_comment_author( $comment ) ) ),
$args['reply_text']
);
}
@@ -2350,9 +2352,15 @@
$args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';
}
- $req = get_option( 'require_name_email' );
- $html_req = ( $req ? " required='required'" : '' );
- $html5 = 'html5' === $args['format'];
+ $req = get_option( 'require_name_email' );
+ $html5 = 'html5' === $args['format'];
+
+ // Define attributes in HTML5 or XHTML syntax.
+ $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>';
$fields = array(
'author' => sprintf(
@@ -2360,12 +2368,12 @@
sprintf(
'<label for="author">%s%s</label>',
__( 'Name' ),
- ( $req ? ' <span class="required">*</span>' : '' )
+ ( $req ? $required_indicator : '' )
),
sprintf(
'<input id="author" name="author" type="text" value="%s" size="30" maxlength="245"%s />',
esc_attr( $commenter['comment_author'] ),
- $html_req
+ ( $req ? $required_attribute : '' )
)
),
'email' => sprintf(
@@ -2373,13 +2381,13 @@
sprintf(
'<label for="email">%s%s</label>',
__( 'Email' ),
- ( $req ? ' <span class="required">*</span>' : '' )
+ ( $req ? $required_indicator : '' )
),
sprintf(
'<input id="email" name="email" %s value="%s" size="30" maxlength="100" aria-describedby="email-notes"%s />',
( $html5 ? 'type="email"' : 'type="text"' ),
esc_attr( $commenter['comment_author_email'] ),
- $html_req
+ ( $req ? $required_attribute : '' )
)
),
'url' => sprintf(
@@ -2397,7 +2405,7 @@
);
if ( has_action( 'set_comment_cookies', 'wp_set_comment_cookies' ) && get_option( 'show_comments_cookies_opt_in' ) ) {
- $consent = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';
+ $consent = empty( $commenter['comment_author_email'] ) ? '' : $checked_attribute;
$fields['cookies'] = sprintf(
'<p class="comment-form-cookies-consent">%s %s</p>',
@@ -2419,8 +2427,8 @@
$required_text = sprintf(
/* translators: %s: Asterisk symbol (*). */
- ' ' . __( 'Required fields are marked %s' ),
- '<span class="required">*</span>'
+ ' <span class="required-field-message" aria-hidden="true">' . __( 'Required fields are marked %s' ) . '</span>',
+ trim( $required_indicator )
);
/**
@@ -2437,10 +2445,11 @@
'comment_field' => sprintf(
'<p class="comment-form-comment">%s %s</p>',
sprintf(
- '<label for="comment">%s</label>',
- _x( 'Comment', 'noun' )
+ '<label for="comment">%s%s</label>',
+ _x( 'Comment', 'noun' ),
+ $required_indicator
),
- '<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required="required"></textarea>'
+ '<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525"' . $required_attribute . '></textarea>'
),
'must_log_in' => sprintf(
'<p class="must-log-in">%s</p>',
@@ -2452,7 +2461,7 @@
)
),
'logged_in_as' => sprintf(
- '<p class="logged-in-as">%s</p>',
+ '<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>' ),
@@ -2462,7 +2471,8 @@
$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 ) )
- )
+ ),
+ $required_text
),
'comment_notes_before' => sprintf(
'<p class="comment-notes">%s%s</p>',
@@ -2470,7 +2480,7 @@
'<span id="email-notes">%s</span>',
__( 'Your email address will not be published.' )
),
- ( $req ? $required_text : '' )
+ $required_text
),
'comment_notes_after' => '',
'action' => site_url( '/wp-comments-post.php' ),
@@ -2530,11 +2540,13 @@
comment_form_title( $args['title_reply'], $args['title_reply_to'] );
- echo $args['cancel_reply_before'];
+ if ( get_option( 'thread_comments' ) ) {
+ echo $args['cancel_reply_before'];
- cancel_comment_reply_link( $args['cancel_reply_link'] );
+ cancel_comment_reply_link( $args['cancel_reply_link'] );
- echo $args['cancel_reply_after'];
+ echo $args['cancel_reply_after'];
+ }
echo $args['title_reply_after'];
@@ -2646,8 +2658,16 @@
/**
* Filters a comment form field for display.
*
- * The dynamic portion of the filter hook, `$name`, refers to the name
- * of the comment form field. Such as 'author', 'email', or 'url'.
+ * The dynamic portion of the hook name, `$name`, refers to the name
+ * of the comment form field.
+ *
+ * Possible hook names include:
+ *
+ * - `comment_form_field_comment`
+ * - `comment_form_field_author`
+ * - `comment_form_field_email`
+ * - `comment_form_field_url`
+ * - `comment_form_field_cookies`
*
* @since 3.0.0
*