Comments: Modernise JavaScript for comment reply links.
Update the comment reply JavaScript to be unobtrusive and use events rather than inline `onclick` attributes. Along with bringing the code into the 2010s this prevents an edge-case in which `addComment.moveForm()` could be called before the JavaScript has loaded. Props peterwilsoncc, bradparbs. Fixes #31590. Built from https://develop.svn.wordpress.org/trunk@42360 git-svn-id: http://core.svn.wordpress.org/trunk@42189 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -1667,15 +1667,25 @@ function get_comment_reply_link( $args = array(), $comment = null, $post = null
|
||||
$args['login_text']
|
||||
);
|
||||
} else {
|
||||
$onclick = sprintf(
|
||||
'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )',
|
||||
$args['add_below'], $comment->comment_ID, $args['respond_id'], $post->ID
|
||||
$data_attributes = array(
|
||||
'commentid' => $comment->comment_ID,
|
||||
'postid' => $post->ID,
|
||||
'belowelement' => $args['add_below'] . '-' . $comment->comment_ID,
|
||||
'respondelement' => $args['respond_id'],
|
||||
);
|
||||
|
||||
$data_attribute_string = '';
|
||||
|
||||
foreach ( $data_attributes as $name => $value ) {
|
||||
$data_attribute_string .= " data-${name}=\"" . esc_attr( $value ) . "\"";
|
||||
}
|
||||
|
||||
$data_attribute_string = trim( $data_attribute_string );
|
||||
|
||||
$link = sprintf(
|
||||
"<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s' aria-label='%s'>%s</a>",
|
||||
esc_url( add_query_arg( 'replytocom', $comment->comment_ID, get_permalink( $post->ID ) ) ) . '#' . $args['respond_id'],
|
||||
$onclick,
|
||||
"<a rel='nofollow' class='comment-reply-link' href='%s' %s aria-label='%s'>%s</a>",
|
||||
esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $args['respond_id'],
|
||||
$data_attribute_string,
|
||||
esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),
|
||||
$args['reply_text']
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user