WordPress.org

Make WordPress Core

Opened 21 months ago

Last modified 3 hours ago

#21213 new defect (bug)

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

Reported by: rinatkhaziev Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 2.5
Component: Themes Keywords: needs-testing has-patch
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 21 months ago.
proposed patch for the bug
21213.patch (419 bytes) - added by SergeyBiryukov 15 months ago.

Download all attachments as: .zip

Change History (12)

rinatkhaziev21 months ago

proposed patch for the bug

comment:1 scribu21 months ago

  • Cc scribu added

comment:2 follow-up: SergeyBiryukov21 months ago

Also mentioned in ticket:15337:9.

comment:3 in reply to: ↑ 2 rinatkhaziev21 months 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 0, edited 21 months ago by rinatkhaziev (next)

SergeyBiryukov15 months ago

comment:4 SergeyBiryukov15 months 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.

comment:5 retire2maui11 months 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.

comment:6 SergeyBiryukov11 months ago

  • Version changed from trunk to 2.5

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

comment:7 kovshenin11 months 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

comment:8 markjaquith10 months ago

  • Milestone changed from 3.6 to Future Release

Punting for now, as it breaks stuff.

comment:9 nacin2 months ago

  • Component changed from Template to Themes
  • Focuses template added

comment:10 chipbennett3 hours 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.

Note: See TracTickets for help on using tickets.