Make WordPress Core

Opened 11 years ago

Last modified 5 years ago

#23867 new defect (bug)

add_rewrite_endpoint causes front-page.php template to be ignored

Reported by: lumpysimon's profile lumpysimon Owned by:
Milestone: Priority: normal
Severity: normal 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 (10)

#1 @toscho
11 years ago

  • Cc info@… added

#2 @SergeyBiryukov
11 years ago

  • Keywords reporter-feedback added

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

#3 @lumpysimon
11 years 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.

#4 @SergeyBiryukov
11 years 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?

#5 @justnorris
10 years 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 10 years ago by justnorris (previous) (diff)

#6 @fabrizim
10 years 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

#7 @paddelboot
10 years ago

Any news when this will be fixed?

#9 @swissspidy
8 years ago

#31438 was marked as a duplicate.

Note: See TracTickets for help on using tickets.