Skip to content
Closed
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
3 changes: 2 additions & 1 deletion src/wp-includes/link-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -2649,7 +2649,8 @@ function get_previous_posts_page_link() {
* @return string|null The previous posts page link if `$display = false`.
*/
function previous_posts( $display = true ) {
$output = esc_url( get_previous_posts_page_link() );
$link = get_previous_posts_page_link();
$output = $link ? esc_url( $link ) : '';

if ( $display ) {
echo $output;
Expand Down
25 changes: 25 additions & 0 deletions tests/phpunit/tests/link/previousPosts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* Tests the `previous_posts()` function.
*
* @since 7.0.0
*
* @group link
*
* @covers ::previous_posts
*/
class Tests_Link_PreviousPosts extends WP_UnitTestCase {

/**
* The absence of a deprecation notice on PHP 8.1+ also shows that the issue is resolved.
*
* @ticket 64864
*/
public function test_should_return_empty_string_on_singular() {
$post_id = self::factory()->post->create();
$this->go_to( get_permalink( $post_id ) );

$this->assertSame( '', previous_posts( false ) );
}
}
Loading