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.
Built from https://develop.svn.wordpress.org/trunk@59181


git-svn-id: http://core.svn.wordpress.org/trunk@58576 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
joedolson 2024-10-05 23:04:11 +00:00
parent 847bac4a16
commit 449c91edb7
2 changed files with 46 additions and 35 deletions

View File

@ -1733,19 +1733,23 @@ function comments_popup_link( $zero = false, $one = false, $more = false, $css_c
* @param array $args { * @param array $args {
* Optional. Override default arguments. * Optional. Override default arguments.
* *
* @type string $add_below The first part of the selector used to identify the comment to respond below. * @type string $add_below The first part of the selector used to identify the comment to respond below.
* The resulting value is passed as the first parameter to addComment.moveForm(), * The resulting value is passed as the first parameter to addComment.moveForm(),
* concatenated as $add_below-$comment->comment_ID. Default 'comment'. * concatenated as $add_below-$comment->comment_ID. Default 'comment'.
* @type string $respond_id The selector identifying the responding comment. Passed as the third parameter * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter
* to addComment.moveForm(), and appended to the link URL as a hash value. * to addComment.moveForm(), and appended to the link URL as a hash value.
* Default 'respond'. * Default 'respond'.
* @type string $reply_text The text of the Reply link. Default 'Reply'. * @type string $reply_text The visible text of the Reply link. Default 'Reply'.
* @type string $login_text The text of the link to reply if logged out. Default 'Log in to Reply'. * @type string $reply_to_text The accessible name of the Reply link, using `%s` as a placeholder
* @type int $max_depth The max depth of the comment tree. Default 0. * for the comment author's name. Default 'Reply to %s'.
* @type int $depth The depth of the new comment. Must be greater than 0 and less than the value * Should start with the visible `reply_text` value.
* of the 'thread_comments_depth' option set in Settings > Discussion. Default 0. * @type bool $show_reply_to_text Whether to use `reply_to_text` as visible link text. Default false.
* @type string $before The text or HTML to add before the reply link. Default empty. * @type string $login_text The text of the link to reply if logged out. Default 'Log in to Reply'.
* @type string $after The text or HTML to add after the reply link. Default empty. * @type int $max_depth The max depth of the comment tree. Default 0.
* @type int $depth The depth of the new comment. Must be greater than 0 and less than the value
* of the 'thread_comments_depth' option set in Settings > Discussion. Default 0.
* @type string $before The text or HTML to add before the reply link. Default empty.
* @type string $after The text or HTML to add after the reply link. Default empty.
* } * }
* @param int|WP_Comment $comment Optional. Comment being replied to. Default current comment. * @param int|WP_Comment $comment Optional. Comment being replied to. Default current comment.
* @param int|WP_Post $post Optional. Post ID or WP_Post object the comment is going to be displayed on. * @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
*/ */
function get_comment_reply_link( $args = array(), $comment = null, $post = null ) { function get_comment_reply_link( $args = array(), $comment = null, $post = null ) {
$defaults = array( $defaults = array(
'add_below' => 'comment', 'add_below' => 'comment',
'respond_id' => 'respond', 'respond_id' => 'respond',
'reply_text' => __( 'Reply' ), 'reply_text' => __( 'Reply' ),
/* translators: Comment reply button text. %s: Comment author name. */ /* translators: Comment reply button text. %s: Comment author name. */
'reply_to_text' => __( 'Reply to %s' ), 'reply_to_text' => __( 'Reply to %s' ),
'login_text' => __( 'Log in to Reply' ), 'login_text' => __( 'Log in to Reply' ),
'max_depth' => 0, 'max_depth' => 0,
'depth' => 0, 'depth' => 0,
'before' => '', 'before' => '',
'after' => '', 'after' => '',
'show_reply_to_text' => false,
); );
$args = wp_parse_args( $args, $defaults ); $args = wp_parse_args( $args, $defaults );
@ -1829,8 +1834,14 @@ function get_comment_reply_link( $args = array(), $comment = null, $post = null
$data_attribute_string = trim( $data_attribute_string ); $data_attribute_string = trim( $data_attribute_string );
$reply_text = $args['show_reply_to_text']
? sprintf( $args['reply_to_text'], get_comment_author( $comment ) )
: $args['reply_text'];
$aria_label = $args['show_reply_to_text'] ? '' : sprintf( $args['reply_to_text'], get_comment_author( $comment ) );
$link = sprintf( $link = sprintf(
"<a rel='nofollow' class='comment-reply-link' href='%s' %s aria-label='%s'>%s</a>", '<a rel="nofollow" class="comment-reply-link" href="%s" %s%s>%s</a>',
esc_url( esc_url(
add_query_arg( add_query_arg(
array( array(
@ -1842,8 +1853,8 @@ function get_comment_reply_link( $args = array(), $comment = null, $post = null
) )
) . '#' . $args['respond_id'], ) . '#' . $args['respond_id'],
$data_attribute_string, $data_attribute_string,
esc_attr( sprintf( $args['reply_to_text'], get_comment_author( $comment ) ) ), $aria_label ? ' aria-label="' . esc_attr( $aria_label ) . '"' : '',
$args['reply_text'] $reply_text
); );
} }
@ -2089,15 +2100,15 @@ function comment_id_fields( $post = null ) {
* *
* @global WP_Comment $comment Global comment object. * @global WP_Comment $comment Global comment object.
* *
* @param string|false $no_reply_text Optional. Text to display when not replying to a comment. * @param string|false $no_reply_text Optional. Text to display when not replying to a comment.
* Default false. * Default false.
* @param string|false $reply_text Optional. Text to display when replying to a comment. * @param string|false $reply_text Optional. Text to display when replying to a comment.
* Default false. Accepts "%s" for the author of the comment * Default false. Accepts "%s" for the author of the comment
* being replied to. * being replied to.
* @param bool $link_to_parent Optional. Boolean to control making the author's name a link * @param bool $link_to_parent Optional. Boolean to control making the author's name a link
* to their comment. Default true. * to their comment. Default true.
* @param int|WP_Post|null $post Optional. The post that the comment form is being displayed for. * @param int|WP_Post|null $post Optional. The post that the comment form is being displayed for.
* Defaults to the current global post. * Defaults to the current global post.
*/ */
function comment_form_title( $no_reply_text = false, $reply_text = false, $link_to_parent = true, $post = null ) { function comment_form_title( $no_reply_text = false, $reply_text = false, $link_to_parent = true, $post = null ) {
global $comment; global $comment;

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.7-beta1-59180'; $wp_version = '6.7-beta1-59181';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.