Make WordPress Core

Opened 7 years ago

Closed 6 days ago

Last modified 6 days ago

#21213 closed defect (bug) (fixed)

Underscores get stripped out in $type ( get_query_template() )

Reported by: rinatkhaziev Owned by: SergeyBiryukov
Milestone: 5.2 Priority: normal
Severity: normal Version: 2.5
Component: Themes Keywords: needs-testing has-patch bulk-reopened
Focuses: template Cc:


What happens is:

$type = preg_replace( '|[^a-z0-9-]+|', '', $type );

strips underscore. Effectively, incoming "front_page" becomes frontpage, which leads to not working (but documented) hook front_page_template.

I tested this on: nginx 1.2.1/php-fpm 5.4.3 (homebrew macos) and nginx 1.0/php-fpm 5.3.3 with the latest revision ATM

The fix is as simple as

$type = preg_replace( '|[^a-z0-9-_]+|', '', $type );

Patch is attached.

Attachments (2)

template_php.patch (491 bytes) - added by rinatkhaziev 7 years ago.
proposed patch for the bug
21213.patch (419 bytes) - added by SergeyBiryukov 6 years ago.

Download all attachments as: .zip

Change History (18)

7 years ago

proposed patch for the bug

#1 @scribu
7 years ago

  • Cc scribu added

#2 follow-up: @SergeyBiryukov
7 years ago

Also mentioned in ticket:15337:9.

#3 in reply to: ↑ 2 @rinatkhaziev
7 years ago

Replying to SergeyBiryukov:

Also mentioned in ticket:15337:9.

This is related to your link for sure, the only thing is that front page would be left as "front-page" instead of "front_page". front_page_template is the hook for modifying template hierarchy.

Version 1, edited 7 years ago by rinatkhaziev (previous) (next) (diff)

#4 @SergeyBiryukov
6 years ago

  • Milestone changed from Awaiting Review to 3.6
  • Version changed from 3.4.1 to 2.5

Related: [7223], [7224]. template_php.patch seems sane.

An alternative would be to rename the filter to front-page_template: 21213.patch.

$type[0]_$type[1]_template filter would need the same change for consistency, see #15337.

#5 @retire2maui
6 years ago

  • Version changed from 2.5 to trunk

I was getting ready to report this same bug for the attachment page template file $mimetype_$subtype.php. For example, template files text_plain.php and image_jpeg.php will not work but textplain.php and imagejpeg.php do work. The template_php.patch fix will resolve this issue also, but 21213.patch obviously won't.

#6 @SergeyBiryukov
6 years ago

  • Version changed from trunk to 2.5

Version number indicates when the bug was initially introduced/reported.

#7 @kovshenin
6 years ago

Note that both patches change the name of the filter fired for the front page template. I did a quick check on the plugins directory, this can break at least one plugin which filters frontpage_template: http://plugins.trac.wordpress.org/browser/page-transitions/trunk/main.php#L33

Haven't found any others, but I did find three plugins that filter on front_page_template:

  • app-your-wordpress-uppsite/themes/webapp/functions.php
  • commentpress-core/themes/commentpress-theme/functions.php
  • wparty/wparty-theme.php

#8 @markjaquith
6 years ago

  • Milestone changed from 3.6 to Future Release

Punting for now, as it breaks stuff.

#9 @nacin
5 years ago

  • Component changed from Template to Themes
  • Focuses template added

#10 @chipbennett
5 years ago

I was just about to write a patch for this. The RegEx is clearly inconsistent with the intent of get_front_page_template():

function get_front_page_template() {
	$templates = array('front-page.php');

	return get_query_template( 'front_page', $templates );

What is the point of passing front_page as $type, if the underscore gets stripped? Either pass frontpage instead of front_page, or fix the RegEx.

This is very confusing for Theme developers.

#11 @chriscct7
3 years ago

Patch still applies, needs unit tests still

#12 @iseulde
4 months ago

  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from new to closed

This ticket has not seen any activity in over *two* years, so I'm closing it as "wontfix".

The ticket may lack decisiveness, may have become irrelevant, or may not have gathered enough interest.

If you think this ticket does deserve some attention again, feel free to reopen.

For bugs, it would be great if you could provide updated steps to reproduce against the latest version of WordPress (5.0.2 at the time of writing). Remember images or a video can be superior to explain a problem. At the very least, quickly test again to make sure the bug still exists.

If it’s an enhancement or feature, some extra motivation may help.

Thank you for your contributions to WordPress! <3

#13 @JeffPaul
8 weeks ago

  • Keywords bulk-reopened added
  • Milestone set to Awaiting Review
  • Resolution wontfix deleted
  • Status changed from closed to reopened

A decision was made to reopen tickets that were closed in the bulk edit that this ticket was affected by. This ticket is being placed back into the Awaiting Review milestone so it can be individually evaluated and verified to determine if it is still relevant/valid or reproducible.

#14 @SergeyBiryukov
6 days ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from reopened to closed

In 45231:

Themes: Standardize on passing frontpage and privacypolicy as the $type parameter to get_query_template().

These keys are used in {$type}_template_hierarchy and {$type}_template filters.

Previously, front_page and privacy_policy were passed, but get_query_template() stripped the underscores before passing the values to the filters.

Props rinatkhaziev, tmatsuur, johnbillion.
Fixes #21213, #46958.

#15 @SergeyBiryukov
6 days ago

  • Keywords changed from needs-testing, has-patch, bulk-reopened to needs-testing has-patch bulk-reopened
  • Milestone changed from Awaiting Review to 5.2

#16 @rinatkhaziev
6 days ago

Thanks! I missed the bulk closing message, otherwise, I would've re-opened myself. Glad to see it finally being merged.

Note: See TracTickets for help on using tickets.