[wp-trac] [WordPress Trac] #35562: Single post pagination redirect back to page one with nextpage tag - WordPress 4.4.1

WordPress Trac noreply at wordpress.org
Thu Jan 21 18:07:33 UTC 2016


#35562: Single post pagination redirect back to page one with nextpage tag -
WordPress 4.4.1
--------------------------+-----------------------------
 Reporter:  pietergoosen  |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  4.4.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When a single post post content, {{{$post->post_content}}}, does not
 contain the {{{<!--nextpage-->}}} tag, and we append more pages to the
 single post through the {{{content_pagination}}} filter, pagination works
 as expected

 Sample code to test

 {{{
 add_filter( 'content_pagination', function ( $pages )
 {
     $pages[] = 'This is another page we want to append';

     return $pages;
 });
 }}}

 However, when we add the {{{<!--nextpage-->}}} tag inside the post content
 ($post->post_content}}} and run the same sample code, any appended page
 simply redirects back to page one as a 404 header is set on appended
 pages.

 I tracked this down to the following block of code (lines 623 - 628)
 inside the {{{WP}}} class ({{{wp-includes/class-wp.php}}} which seems to
 be introduced in either v4.4.0 or 4.4.1

 {{{
 // check for paged content that exceeds the max number of pages
 $next = '<!--nextpage-->';
 if ( $p && false !== strpos( $p->post_content, $next ) && ! empty(
 $this->query_vars['page'] ) ) {
         $page = trim( $this->query_vars['page'], '/' );
         $success = (int) $page <= ( substr_count( $p->post_content, $next
 ) + 1 );
 }
 }}}

 Removing those lines fixes the issue.

 What I recommend is that instead of simply checking for the
 {{{<!nextpage-->}}} and returning a 404 according to that, we must rather
 have a check that acts on the amount of pages we have counted immediately
 after the {{{content_pagination}}} filter and then return a 404 if the
 current page exceeds the amount of pages after the
 {{{content_pagination}}} filter

--
Ticket URL: <https://core.trac.wordpress.org/ticket/35562>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list