Skip to:
Content

BuddyPress.org

Opened 15 years ago

Closed 15 years ago

#2198 closed defect (bug) (fixed)

bp_core_load_template does not load plugin's sub-templates

Reported by: djpaul's profile DJPaul Owned by:
Milestone: 1.5 Priority: minor
Severity: Version:
Component: Core Keywords:
Cc: has-patch, tested

Description

You use bp_core_load_template() in a plugin to load a theme file, using the filter 'bp_located_template'.

If you're modelling your plugin on the default BuddyPress components, or even the skeleton component, you could use the above to load an index page for your directory, and use a "loop" file to display each item within your directory index page.

However, the whole purposes of the 'bp_located_template' filter is that it allows theme authors to override your plugin's theme file by adding it to their WordPress theme's directory. The problem is that you cannot use bp_located_template() to include your loop file (henceforth referred to as a "plugin sub-template").

Why? Because bp_core_load_template() just sets up the data for the template to load; nothing happens until the WordPress 'template_redirect' action is called, which only happens once on page load (.e. when it loads your index page).

Attachments (1)

patch-2198.patch (417 bytes) - added by DJPaul 15 years ago.
Made against tag 1.2.2.1

Download all attachments as: .zip

Change History (7)

@DJPaul
15 years ago

Made against tag 1.2.2.1

#1 @DJPaul
15 years ago

I believe it is safe to call bp_core_do_catch_uri() in this way as I can't see where/how any of the $wp_query variables will be changed.

#2 @MrMaz
15 years ago

Its my understanding that bp_core_load_template() was not intended for sub-templates. I believe that all of the core templates use locate_template() to load sub-templates.

I wrote my own custom locate_template method to check the plugin path instead of the template path, which does not rely on any of the catch uri stuff.

#3 @DJPaul
15 years ago

Indeed, but BuddyPress is able to use locate_template because its template files are, of course, in the actual theme.

#4 @DJPaul
15 years ago

This appears it may not work with multiple calls to bp_core_load_template in the same template.

#5 @DJPaul
15 years ago

  • Owner DJPaul deleted
  • Status changed from new to assigned

What actually happens is that after even a single call to load a subtemplate, execution/output of the page stops. I've given up for now and am just including files directly.

#6 @DJPaul
15 years ago

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

To load a template within a template from a plugin rather than from the theme -- a sub-template -- you need to do something like:

function load_sub_template( $template ) {
	if ( $located_template = apply_filters( 'bp_located_template', locate_template( $template , false ), $template ) )	
		load_template( apply_filters( 'bp_load_template', $located_template ) );
}
load_sub_template( array( 'achievements/_addedit.php' ) );
Note: See TracTickets for help on using tickets.