WordPress.org

Make WordPress Core

Opened 13 months ago

Last modified 4 weeks ago

#23867 new defect (bug)

add_rewrite_endpoint causes front-page.php template to be ignored

Reported by: lumpysimon Owned by:
Milestone: Awaiting Review Priority: normal
Severity: major Version: 3.5.1
Component: Rewrite Rules Keywords: reporter-feedback
Focuses: Cc:

Description

I have a front-page.php template in my theme folder, as per the template hierarchy this is used regardless of whether I am showing posts or a page as the front page.

However, when I add a rewrite endpoint (on the init hook), index.php is used for the front page template when I add my query var to the URL. It makes no difference if I set the front page to show posts or a page. If I do not add the query var, front-page.php is correctly used.

i.e. http://domain.com correctly uses front-page.php, http://domain.com/nl wrongly uses index.php

This happens whether I use EP_ALL or EP_ROOT as the places parameter.

All other template files are fine, it's only the homepage with the problem as far as I can see.

Change History (6)

comment:1 toscho13 months ago

  • Cc info@… added

comment:2 SergeyBiryukov13 months ago

  • Keywords reporter-feedback added

Could you provide a piece of code to reproduce the issue?

comment:3 lumpysimon13 months ago

  • Keywords reporter-feedback removed
add_action( 'init', 'my_add_rewrite_endpoint' );

function my_add_rewrite_endpoint() {
	add_rewrite_endpoint( 'nl', EP_ALL );
}

that's pretty much it. if there's a front-page.php template in the theme folder it then gets ignored when visiting http://domain.com/nl.

comment:4 SergeyBiryukov12 months ago

  • Keywords reporter-feedback added

Could not reproduce. My steps:

  1. Added your code to theme's functions.php.
  2. Flushed rewrite rules by visiting Permalink Settings screen.
  3. http://trunk.wordpress/ and http://trunk.wordpress/nl/ are displayed using front-page.php.
  • Have you flushed rewrite rules after adding the code?
  • What is you permalink structure?

comment:5 justnorris5 months ago

  • Cc justnorris added
  • Severity changed from normal to major
  1. Add the code to theme's functions.php
add_action( 'init', 'my_add_rewrite_endpoint' );

function my_add_rewrite_endpoint() {
	add_rewrite_endpoint( 'nl', EP_ALL );
}
  1. Flush rewrite rules
  2. Create a page called "My front page" and add content "Testing Things and Stuff"
  3. Go to "Settings -> Reading", set "Front page displays: -> A static page: "My front page"
  4. Open http://trunk.wordpress/ -> expected: "Testing Things and Stuff".
  5. Open http://trunk.wordpress/nl -> expected: "Testing Things and Stuff", failed, 404 loaded instead.

Does that count as the same bug or should I create a separate ticket ?

Edit
On top of that:

  1. Add Function, Flush Rules:

index.php generates regular index.php ( and not "My front page" Page )

  1. Remove Function, DO NOT FLUSH RULES:

index.php generates "My front page" page (unexpected), but doesn't utilize the "nl" query_var ( expected, because there is no function that would register "nl" query var

  1. Flush Rewrite rules, 404 page is generated (expected)

Wordpress 3.7.1

Last edited 5 months ago by justnorris (previous) (diff)

comment:6 fabrizim4 weeks ago

I think the issue occurs during the parse_vars in WP_Query. See the code here:

https://core.trac.wordpress.org/browser/tags/3.8.1/src/wp-includes/query.php#L1655

This test does not take into account custom endpoints, only a hardcoded set of query args - any additional args result in a failing test. I think this should be expanded to include any user defined endpoints. I wrote a plugin for using a custom post type as the front page and during some development, added a filter to fix this, now endpoints can be used on a static front page. See the following for the specific function that I wrote. It would only be 2 lines of code to add to the core, but I don't know how to add a "pull request" in svn :/

https://plugins.trac.wordpress.org/browser/cpt-on-front-page/tags/1.0.1/plugin.php#L33

Note: See TracTickets for help on using tickets.