Make WordPress Core

Changeset 59181


Ignore:
Timestamp:
10/05/2024 11:02:53 PM (4 months ago)
Author:
joedolson
Message:

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.

File:
1 edited

Legend:

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

    r58809 r59181  
    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.
     
    17551759function 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
     
    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(
     
    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    }
     
    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 */
    21022113function comment_form_title( $no_reply_text = false, $reply_text = false, $link_to_parent = true, $post = null ) {
Note: See TracChangeset for help on using the changeset viewer.