bp_core_load_template( array $templates )
Load a specific template file with fallback support.
Description Description
Example: bp_core_load_template( ‘members/index’ ); Loads: wp-content/themes/[activated_theme]/members/index.php
Parameters Parameters
- $templates
-
(Required) Array of templates to attempt to load.
Source Source
File: bp-core/bp-core-catchuri.php
function bp_core_load_template( $templates ) {
global $wp_query;
// Reset the post.
bp_theme_compat_reset_post( array(
'ID' => 0,
'is_404' => true,
'post_status' => 'publish',
) );
// Set theme compat to false since the reset post function automatically sets
// theme compat to true.
bp_set_theme_compat_active( false );
// Fetch each template and add the php suffix.
$filtered_templates = array();
foreach ( (array) $templates as $template ) {
$filtered_templates[] = $template . '.php';
}
// Only perform template lookup for bp-default themes.
if ( ! bp_use_theme_compat_with_current_theme() ) {
$template = locate_template( (array) $filtered_templates, false );
// Theme compat doesn't require a template lookup.
} else {
$template = '';
}
/**
* Filters the template locations.
*
* Allows plugins to alter where the template files are located.
*
* @since 1.1.0
*
* @param string $template Located template path.
* @param array $filtered_templates Array of templates to attempt to load.
*/
$located_template = apply_filters( 'bp_located_template', $template, $filtered_templates );
/*
* If current page is an embed, wipe out bp-default template.
*
* Wiping out the bp-default template allows WordPress to use their special
* embed template, which is what we want.
*/
if ( function_exists( 'is_embed' ) && is_embed() ) {
$located_template = '';
}
if ( !empty( $located_template ) ) {
// Template was located, lets set this as a valid page and not a 404.
status_header( 200 );
$wp_query->is_page = true;
$wp_query->is_singular = true;
$wp_query->is_404 = false;
/**
* Fires before the loading of a located template file.
*
* @since 1.6.0
*
* @param string $located_template Template found to be loaded.
*/
do_action( 'bp_core_pre_load_template', $located_template );
/**
* Filters the selected template right before loading.
*
* @since 1.1.0
*
* @param string $located_template Template found to be loaded.
*/
load_template( apply_filters( 'bp_load_template', $located_template ) );
/**
* Fires after the loading of a located template file.
*
* @since 1.6.0
*
* @param string $located_template Template found that was loaded.
*/
do_action( 'bp_core_post_load_template', $located_template );
// Kill any other output after this.
exit();
// No template found, so setup theme compatibility.
// @todo Some other 404 handling if theme compat doesn't kick in.
} else {
// We know where we are, so reset important $wp_query bits here early.
// The rest will be done by bp_theme_compat_reset_post() later.
if ( is_buddypress() ) {
status_header( 200 );
$wp_query->is_page = true;
$wp_query->is_singular = true;
$wp_query->is_404 = false;
}
/**
* Fires if there are no found templates to load and theme compat is needed.
*
* @since 1.7.0
*/
do_action( 'bp_setup_theme_compat' );
}
}
Changelog Changelog
| Version | Description |
|---|---|
| 1.0.0 | Introduced. |