From 6d0f2dcf1108681c04ac3947cffdd6214bae0baa Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 2 Oct 2014 20:45:16 +0000 Subject: [PATCH] Make link construction in get_comment_reply_link() and get_post_reply_link() more readable. see #16433. Built from https://develop.svn.wordpress.org/trunk@29823 git-svn-id: http://core.svn.wordpress.org/trunk@29589 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment-template.php | 41 +++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index 026498821e..20da50a23a 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -1321,14 +1321,12 @@ function get_comment_reply_link( $args = array(), $comment = null, $post = null return; } - $add_below = $args['add_below']; - $respond_id = $args['respond_id']; - $reply_text = $args['reply_text']; - $comment = get_comment( $comment ); + if ( empty( $post ) ) { $post = $comment->comment_post_ID; } + $post = get_post( $post ); if ( ! comments_open( $post->ID ) ) { @@ -1336,9 +1334,21 @@ function get_comment_reply_link( $args = array(), $comment = null, $post = null } if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) { - $link = '' . $args['login_text'] . ''; + $link = sprintf( '%s', + esc_url( wp_login_url( get_permalink() ) ), + $args['login_text'] + ); } else { - $link = "comment_ID ) ) . "#" . $respond_id . "' onclick='return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\")' aria-label='" . esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ) . "'>$reply_text"; + $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 + ); + + $link = sprintf( "%s", + esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $args['respond_id'], + $onclick, + esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ), + $args['reply_text'] + ); } /** * Filter the comment reply link. @@ -1404,9 +1414,7 @@ function get_post_reply_link($args = array(), $post = null) { ); $args = wp_parse_args($args, $defaults); - $add_below = $args['add_below']; - $respond_id = $args['respond_id']; - $reply_text = $args['reply_text']; + $post = get_post($post); if ( ! comments_open( $post->ID ) ) { @@ -1414,9 +1422,20 @@ function get_post_reply_link($args = array(), $post = null) { } if ( get_option('comment_registration') && ! is_user_logged_in() ) { - $link = '' . $args['login_text'] . ''; + $link = sprintf( '%s', + wp_login_url( get_permalink() ), + $args['login_text'] + ); } else { - $link = "$reply_text"; + $onclick = sprintf( 'return addComment.moveForm( "%1$s-%2$s", "0", "%3$s", "%2$s" )', + $args['add_below'], $post->ID, $args['respond_id'] + ); + + $link = sprintf( "%s", + get_permalink( $post->ID ) . '#' . $args['respond_id'], + $onclick, + $args['reply_text'] + ); } $formatted_link = $args['before'] . $link . $args['after']; /**