Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/wp-includes/post-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ function _wp_link_page( $i ) {
if ( 1 === $i ) {
$url = get_permalink();
} else {
if ( ! get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending' ), true ) ) {
if ( ! get_option( 'permalink_structure' ) || in_array( $post->post_status, array( 'draft', 'pending', 'future' ), true ) ) {
$url = add_query_arg( 'page', $i, get_permalink() );
} elseif ( 'page' === get_option( 'show_on_front' ) && (int) get_option( 'page_on_front' ) === $post->ID ) {
$url = trailingslashit( get_permalink() ) . user_trailingslashit( "$wp_rewrite->pagination_base/" . $i, 'single_paged' );
Expand Down
59 changes: 59 additions & 0 deletions tests/phpunit/tests/post/wpLinkPages.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,63 @@ public function test_wp_link_pages() {

$this->assertSame( $pagelink, $output );
}

/**
* Tests the URL of a subpage of a post that is split with the nextpage tag.
*
* The permalink of a post that is not published is a plain `?p=ID` URL,
* so the page number must be added as a query argument as well.
*
* @ticket 32295
*
* @dataProvider data_post_statuses
*
* @param string $post_status Post status.
* @param bool $uses_query_arg Whether the page number is expected as a query argument.
*/
public function test_subpage_url_with_pretty_permalinks( $post_status, $uses_query_arg ) {
$this->set_permalink_structure( '/%postname%/' );

$post_args = array(
'post_status' => $post_status,
'post_content' => 'One<!--nextpage-->Two<!--nextpage-->Three',
);

// A post is only scheduled when its date is in the future.
if ( 'future' === $post_status ) {
$post_args['post_date'] = gmdate( 'Y-m-d H:i:s', strtotime( '+1 day' ) );
$post_args['post_date_gmt'] = $post_args['post_date'];
}

$post_id = self::factory()->post->create( $post_args );

$this->assertSame( $post_status, get_post_status( $post_id ), 'The post should have the expected status.' );

$GLOBALS['post'] = get_post( $post_id );
setup_postdata( $GLOBALS['post'] );

$permalink = get_permalink( $post_id );

if ( $uses_query_arg ) {
$expected_url = add_query_arg( 'page', 2, $permalink );
} else {
$expected_url = trailingslashit( $permalink ) . user_trailingslashit( 2, 'single_paged' );
}

$this->assertSame( '<a href="' . esc_url( $expected_url ) . '" class="post-page-numbers">', _wp_link_page( 2 ) );
}

/**
* Data provider.
*
* @return array[]
*/
public static function data_post_statuses() {
return array(
'draft' => array( 'draft', true ),
'pending' => array( 'pending', true ),
'scheduled' => array( 'future', true ),
'published' => array( 'publish', false ),
);
}
}
Loading