WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/03/2017 10:36:15 PM (3 years ago)
Author:
peterwilsoncc
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment-template.php

    r42343 r42360  
    16681668        );
    16691669    } else {
    1670         $onclick = sprintf(
    1671             'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )',
    1672             $args['add_below'], $comment->comment_ID, $args['respond_id'], $post->ID
     1670        $data_attributes = array(
     1671            'commentid'        => $comment->comment_ID,
     1672            'postid'           => $post->ID,
     1673            'belowelement'     => $args['add_below'] . '-' . $comment->comment_ID,
     1674            'respondelement'   => $args['respond_id'],
    16731675        );
    16741676
     1677        $data_attribute_string = '';
     1678
     1679        foreach ( $data_attributes as $name => $value ) {
     1680            $data_attribute_string .= " data-${name}=\"" . esc_attr( $value ) . "\"";
     1681        }
     1682
     1683        $data_attribute_string = trim( $data_attribute_string );
     1684
    16751685        $link = sprintf(
    1676             "<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s' aria-label='%s'>%s</a>",
    1677             esc_url( add_query_arg( 'replytocom', $comment->comment_ID, get_permalink( $post->ID ) ) ) . '#' . $args['respond_id'],
    1678             $onclick,
     1686            "<a rel='nofollow' class='comment-reply-link' href='%s' %s aria-label='%s'>%s</a>",
     1687            esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $args['respond_id'],
     1688            $data_attribute_string,
    16791689            esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),
    16801690            $args['reply_text']
Note: See TracChangeset for help on using the changeset viewer.