Make WordPress Core

Opened 12 years ago

Closed 5 years ago

Last modified 5 years ago

#21213 closed defect (bug) (fixed)

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

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

Description

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 12 years ago.
proposed patch for the bug
21213.patch (419 bytes) - added by SergeyBiryukov 11 years ago.

Download all attachments as: .zip

Change History (16)

@rinatkhaziev
12 years ago

proposed patch for the bug

#1 @scribu
12 years ago

  • Cc scribu added

#2 follow-up: @SergeyBiryukov
12 years ago

Also mentioned in ticket:15337:9.

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

Replying to SergeyBiryukov:

Also mentioned in ticket:15337:9.

This is related to the ticket you mentioned 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.

Last edited 12 years ago by rinatkhaziev (previous) (diff)

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

  • Version changed from trunk to 2.5

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

#7 @kovshenin
11 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
11 years ago

  • Milestone changed from 3.6 to Future Release

Punting for now, as it breaks stuff.

#9 @nacin
10 years ago

  • Component changed from Template to Themes
  • Focuses template added

#10 @chipbennett
10 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
8 years ago

Patch still applies, needs unit tests still

#14 @SergeyBiryukov
5 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new 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
5 years ago

  • Keywords bulk-reopened added
  • Milestone set to 5.2

#16 @rinatkhaziev
5 years 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.