Skip to:
Content

bbPress.org

Opened 14 years ago

Closed 14 years ago

#1524 closed defect (bug) (fixed)

Use template_include instead of template_redirect for template loading

Reported by: greenshady's profile greenshady Owned by:
Milestone: 2.0 Priority: normal
Severity: normal Version:
Component: Front-end Keywords:
Cc:

Description

In bbp-core-hooks.php, we have this line of code:

add_action( 'template_redirect', 'bbp_custom_template', 999 );

This function is for locating the template to use for the page. It calls bbp_load_template() to actually load the template. If a template is found, it calls exit(). If the priority wasn't set to 999, I'd say we'd have a big issue there. But, it's likely this won't mess up anything with that priority.

Nevertheless, WordPress has a filter hook in wp-includes/template-loader.php for overwriting the included template for the page. This functionality should be changed to use this hook rather than template_redirect.

Using template_redirect and exiting causes conflicts with plugins/themes that use the template filter hooks as the correct template won't be loaded.

I'll see about writing a patch if no one can get to this in the next few days.

Attachments (1)

filter-template_include.diff (628 bytes) - added by greenshady 14 years ago.
add_filter() for 'template_include'

Download all attachments as: .zip

Change History (7)

#1 @johnjamesjacoby
14 years ago

I meant to revisit this code in the future, but if you're noticing incompatibilities already, I've got a fix on the way.

It shouldn't cause any conflicts unless there's some other kind of slug collision. What was happening that was causing you issues?

#2 @greenshady
14 years ago

I work on a site that has a unique template hierarchy, which I'm integrating bbPress into. We use various template-loading filter hooks to load specific templates. The templates I expected to load were not loading because my filters never had a chance to execute.

The bbPress function isn't a major problem because it only changes things in very specific scenarios (based on the conditional tags). Plus, it has the bbp_custom_template hook, which I can easily filter to handle my needs.

WP already has hooks in place for this type of thing though, so we might as well use them. It'll probably save some headaches later.

#3 @johnjamesjacoby
14 years ago

(In [3169]) Consolidate theme compat functions and add more verbose phpdoc where appropriate. Use template_include filter instead of template_redirect action, and add support for incorrect usage of add_theme_support( 'bbpress' ). See #1524.

#4 @johnjamesjacoby
14 years ago

There's probably more consolidation and clean-up that can be done here, but this first round of clean-up should alleviate your woes.

@greenshady
14 years ago

add_filter() for 'template_include'

#5 @greenshady
14 years ago

Awesome! That should work much better.

I've attached a patch that should use add_filter instead of add_action for the template_include filter hook.

#6 @johnjamesjacoby
14 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [3173]) Switch bbp_template_include action into a filter, and move it down into the filters section of bbp-core-hooks.php. Also add more verbose descriptions to bbp_template_include and bbp_request_feed_trap filters. Fixes #1524. Props greenshady.

Note: See TracTickets for help on using tickets.