Appending content with <!--nextpage--> broken in 4.4
Update 2016-01-21
All current testing on my end is being done on fresh installs of 4.4.1 with the following settings:
Plain permalinks
Twentysixteen Theme
No plugins activated
If the post only has 1 page (ie !--nextpage--
doesn't appear in the post) then the extra pages are appended successfully (even if you append multiple extra pages).
Welcome to WordPress. This is your first post. Edit or delete it, then start writing!
If the post has 2+ pages then the extra pages 404 and canonical redirect to page 1 of the post.
Welcome to WordPress. This is your first post. Edit or delete it, then start writing!
!--nextpage--
This is page 2
In the second case $wp_query-queried_object
is empty once you hit the extra pages. You'll need to disable the canonical redirect to see this remove_filter('template_redirect', 'redirect_canonical');
Both of the following core fixes have been tried, separately and together, with no change in behavior: https://core.trac.wordpress.org/ticket/35344#comment:16
https://core.trac.wordpress.org/ticket/35344#comment:34
For ease of use this is the code I'm currently testing with:
add_action('template_redirect', 'custom_content_one');
function custom_content_one() {
global $post;
$content = "\n!--nextpage--\nThis is the extra page v1";
$post-post_content .= $content;
}
add_filter('content_pagination', 'custom_content_two', 10, 2);
function custom_content_two($pages, $post) {
if ( in_the_loop() 'post' === $post-post_type ) {
$content = "This is the extra page v2";
$pages[] = $content;
}
return $pages;
}
add_action('the_post', 'custom_content_three');
function custom_content_three() {
global $multipage, $numpages, $pages;
$content = "This is the extra page v3";
$multipage = 1;
$numpages++;
$pages[] = $content;
}
This is the code I used to test multiple extra pages on a single page post
add_action('template_redirect', 'custom_content_one');
function custom_content_one() {
global $post;
$content = "\n!--nextpage--\nThis is the extra page v1-1\n!--nextpage--\nThis is the extra page v1-2\n!--nextpage--\nThis is the extra page v1-3";
$post-post_content .= $content;
}
Original Question
Prior to 4.4 I was able to append an additional page to a mutlipage post with the following:
add_action('template_redirect', 'custom_content');
function custom_content() {
global $post;
$content = html_entity_decode(stripslashes(get_option('custom_content')));
$post-post_content .= $content;
}
With get_option('custom_content') being something like:
!--nextpage--
Hello World
Since upgrading to 4.4 the code has not worked; navigating to the additional page triggers a 404 error and redirect_canonical sends them back to the permalink of the post. Disabling redirect_canonical allows me to view the extra page and the additonal content is there, but it still triggers a 404 error.
I've tried a number of workarounds, none of which resolve the 404 error, including:
add_action('the_post', 'custom_content');
function custom_content() {
global $multipage, $numpages, $pages;
$content = html_entity_decode(stripslashes(get_option('custom_content')));
$multipage = 1; // ensure post is considered multipage: needed for single page posts
$numpages++; // increment number of pages
$pages[] = $content;
}
Also tried leveraging the new content_pagination filter that was added in 4.4:
add_filter('content_pagination', 'custom_content', 10, 2);
function custom_content($pages, $post) {
$content = html_entity_decode(stripslashes(get_option('custom_content')));
$pages[] = $content;
return $pages;
}
At this point I'm out of ideas on how to restore this functionality and any assistance would be appreciated.