Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/wp-includes/comment-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -1657,13 +1657,16 @@ function comments_popup_link( $zero = false, $one = false, $more = false, $css_c
}

if ( false === $more ) {
// Replace '%' characters with a placeholder to prevent them from being replaced with the comments number.
$_post_title = str_replace( '%', '__PERCENT__', $post_title );

/* translators: 1: Number of comments, 2: Post title. */
$more = _n(
'%1$s Comment<span class="screen-reader-text"> on %2$s</span>',
'%1$s Comments<span class="screen-reader-text"> on %2$s</span>',
$comments_number
);
$more = sprintf( $more, number_format_i18n( $comments_number ), $post_title );
$more = sprintf( $more, number_format_i18n( $comments_number ), $_post_title );
}

if ( false === $none ) {
Expand Down Expand Up @@ -1711,12 +1714,19 @@ function comments_popup_link( $zero = false, $one = false, $more = false, $css_c
*/
$link_attributes = apply_filters( 'comments_popup_link_attributes', $link_attributes );

$_comments_number_text = get_comments_number_text( $zero, $one, $more );

// Restore the '%' characters in the post title.
if ( isset( $_post_title ) ) {
$_comments_number_text = str_replace( '__PERCENT__', '%', $_comments_number_text );
}

printf(
'<a href="%1$s"%2$s%3$s>%4$s</a>',
esc_url( $comments_link ),
! empty( $css_class ) ? ' class="' . $css_class . '" ' : '',
$link_attributes,
get_comments_number_text( $zero, $one, $more )
$_comments_number_text
);
}

Expand Down
19 changes: 19 additions & 0 deletions tests/phpunit/tests/comment/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ public function test_get_comments_number_text_with_post_id() {
$this->assertSame( sprintf( _n( '%s Comment', '%s Comments', 6 ), '6' ), $comments_number_text );
}

/**
* @ticket 37103
*
* @covers ::comments_popup_link
*/
public function test_comments_popup_link_should_not_replace_percent_sign_in_post_title() {
$post_id = self::factory()->post->create( array( 'post_title' => '%Hello %% World%' ) );
$permalink = get_permalink( $post_id );

self::factory()->comment->create_post_comments( $post_id, 2 );
$this->go_to( $permalink );

ob_start();
comments_popup_link();
$comments_link = ob_get_clean();

$this->assertStringContainsString( '%Hello %% World%', $comments_link );
}

/**
* @ticket 13651
*
Expand Down
Loading