Skip to content

Commit c847d7b

Browse files
committed
Comments: Enable using reply_to_text as visible link.
Add an option `show_reply_to_text` as an option to use the current `aria-label` attribute on comment reply links as the visible link. If used, remove the `aria-label`. Also add documentation of the `reply_to_text` parameter to the function documentation. Props halilesen, sabernhardt, snehapatil02, jainil07, joedolson. Fixes #59965. git-svn-id: https://develop.svn.wordpress.org/trunk@59181 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 3d59107 commit c847d7b

File tree

1 file changed

+45
-34
lines changed

1 file changed

+45
-34
lines changed

src/wp-includes/comment-template.php

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,19 +1733,23 @@ function comments_popup_link( $zero = false, $one = false, $more = false, $css_c
17331733
* @param array $args {
17341734
* Optional. Override default arguments.
17351735
*
1736-
* @type string $add_below The first part of the selector used to identify the comment to respond below.
1737-
* The resulting value is passed as the first parameter to addComment.moveForm(),
1738-
* concatenated as $add_below-$comment->comment_ID. Default 'comment'.
1739-
* @type string $respond_id The selector identifying the responding comment. Passed as the third parameter
1740-
* to addComment.moveForm(), and appended to the link URL as a hash value.
1741-
* Default 'respond'.
1742-
* @type string $reply_text The text of the Reply link. Default 'Reply'.
1743-
* @type string $login_text The text of the link to reply if logged out. Default 'Log in to Reply'.
1744-
* @type int $max_depth The max depth of the comment tree. Default 0.
1745-
* @type int $depth The depth of the new comment. Must be greater than 0 and less than the value
1746-
* of the 'thread_comments_depth' option set in Settings > Discussion. Default 0.
1747-
* @type string $before The text or HTML to add before the reply link. Default empty.
1748-
* @type string $after The text or HTML to add after the reply link. Default empty.
1736+
* @type string $add_below The first part of the selector used to identify the comment to respond below.
1737+
* The resulting value is passed as the first parameter to addComment.moveForm(),
1738+
* concatenated as $add_below-$comment->comment_ID. Default 'comment'.
1739+
* @type string $respond_id The selector identifying the responding comment. Passed as the third parameter
1740+
* to addComment.moveForm(), and appended to the link URL as a hash value.
1741+
* Default 'respond'.
1742+
* @type string $reply_text The visible text of the Reply link. Default 'Reply'.
1743+
* @type string $reply_to_text The accessible name of the Reply link, using `%s` as a placeholder
1744+
* for the comment author's name. Default 'Reply to %s'.
1745+
* Should start with the visible `reply_text` value.
1746+
* @type bool $show_reply_to_text Whether to use `reply_to_text` as visible link text. Default false.
1747+
* @type string $login_text The text of the link to reply if logged out. Default 'Log in to Reply'.
1748+
* @type int $max_depth The max depth of the comment tree. Default 0.
1749+
* @type int $depth The depth of the new comment. Must be greater than 0 and less than the value
1750+
* of the 'thread_comments_depth' option set in Settings > Discussion. Default 0.
1751+
* @type string $before The text or HTML to add before the reply link. Default empty.
1752+
* @type string $after The text or HTML to add after the reply link. Default empty.
17491753
* }
17501754
* @param int|WP_Comment $comment Optional. Comment being replied to. Default current comment.
17511755
* @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on.
@@ -1754,16 +1758,17 @@ function comments_popup_link( $zero = false, $one = false, $more = false, $css_c
17541758
*/
17551759
function get_comment_reply_link( $args = array(), $comment = null, $post = null ) {
17561760
$defaults = array(
1757-
'add_below' => 'comment',
1758-
'respond_id' => 'respond',
1759-
'reply_text' => __( 'Reply' ),
1761+
'add_below' => 'comment',
1762+
'respond_id' => 'respond',
1763+
'reply_text' => __( 'Reply' ),
17601764
/* translators: Comment reply button text. %s: Comment author name. */
1761-
'reply_to_text' => __( 'Reply to %s' ),
1762-
'login_text' => __( 'Log in to Reply' ),
1763-
'max_depth' => 0,
1764-
'depth' => 0,
1765-
'before' => '',
1766-
'after' => '',
1765+
'reply_to_text' => __( 'Reply to %s' ),
1766+
'login_text' => __( 'Log in to Reply' ),
1767+
'max_depth' => 0,
1768+
'depth' => 0,
1769+
'before' => '',
1770+
'after' => '',
1771+
'show_reply_to_text' => false,
17671772
);
17681773

17691774
$args = wp_parse_args( $args, $defaults );
@@ -1829,8 +1834,14 @@ function get_comment_reply_link( $args = array(), $comment = null, $post = null
18291834

18301835
$data_attribute_string = trim( $data_attribute_string );
18311836

1837+
$reply_text = $args['show_reply_to_text']
1838+
? sprintf( $args['reply_to_text'], get_comment_author( $comment ) )
1839+
: $args['reply_text'];
1840+
1841+
$aria_label = $args['show_reply_to_text'] ? '' : sprintf( $args['reply_to_text'], get_comment_author( $comment ) );
1842+
18321843
$link = sprintf(
1833-
"<a rel='nofollow' class='comment-reply-link' href='%s' %s aria-label='%s'>%s</a>",
1844+
'<a rel="nofollow" class="comment-reply-link" href="%s" %s%s>%s</a>',
18341845
esc_url(
18351846
add_query_arg(
18361847
array(
@@ -1842,8 +1853,8 @@ function get_comment_reply_link( $args = array(), $comment = null, $post = null
18421853
)
18431854
) . '#' . $args['respond_id'],
18441855
$data_attribute_string,
1845-
esc_attr( sprintf( $args['reply_to_text'], get_comment_author( $comment ) ) ),
1846-
$args['reply_text']
1856+
$aria_label ? ' aria-label="' . esc_attr( $aria_label ) . '"' : '',
1857+
$reply_text
18471858
);
18481859
}
18491860

@@ -2089,15 +2100,15 @@ function comment_id_fields( $post = null ) {
20892100
*
20902101
* @global WP_Comment $comment Global comment object.
20912102
*
2092-
* @param string|false $no_reply_text Optional. Text to display when not replying to a comment.
2093-
* Default false.
2094-
* @param string|false $reply_text Optional. Text to display when replying to a comment.
2095-
* Default false. Accepts "%s" for the author of the comment
2096-
* being replied to.
2097-
* @param bool $link_to_parent Optional. Boolean to control making the author's name a link
2098-
* to their comment. Default true.
2099-
* @param int|WP_Post|null $post Optional. The post that the comment form is being displayed for.
2100-
* Defaults to the current global post.
2103+
* @param string|false $no_reply_text Optional. Text to display when not replying to a comment.
2104+
* Default false.
2105+
* @param string|false $reply_text Optional. Text to display when replying to a comment.
2106+
* Default false. Accepts "%s" for the author of the comment
2107+
* being replied to.
2108+
* @param bool $link_to_parent Optional. Boolean to control making the author's name a link
2109+
* to their comment. Default true.
2110+
* @param int|WP_Post|null $post Optional. The post that the comment form is being displayed for.
2111+
* Defaults to the current global post.
21012112
*/
21022113
function comment_form_title( $no_reply_text = false, $reply_text = false, $link_to_parent = true, $post = null ) {
21032114
global $comment;

0 commit comments

Comments
 (0)