bp_core_load_template

Load a specific template file with fallback support.

Description

bp_core_load_template( (array) $templates ); 

Example: bp_core_load_template( members/index ); Loads: wp-content/themes/[activated_theme]/members/index.php

Parameters (1)

0. $templates (array)
Array of templates to attempt to load.

Usage

  1. if ( !function_exists( 'bp_core_load_template' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-catchuri.php'; 
  3.  
  4. // Array of templates to attempt to load. 
  5. $templates = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_core_load_template($templates); 
  9.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-catchuri.php  
  1. function bp_core_load_template( $templates ) { 
  2. global $wp_query; 
  3.  
  4. // Reset the post. 
  5. 'ID' => 0,  
  6. 'is_404' => true,  
  7. 'post_status' => 'publish',  
  8. ) ); 
  9.  
  10. // Set theme compat to false since the reset post function automatically sets 
  11. // theme compat to true. 
  12.  
  13. // Fetch each template and add the php suffix. 
  14. $filtered_templates = array(); 
  15. foreach ( (array) $templates as $template ) { 
  16. $filtered_templates[] = $template . '.php'; 
  17.  
  18. // Only perform template lookup for bp-default themes. 
  19. $template = locate_template( (array) $filtered_templates, false ); 
  20.  
  21. // Theme compat doesn't require a template lookup. 
  22. } else { 
  23. $template = ''; 
  24.  
  25. /** 
  26. * Filters the template locations. 
  27. * Allows plugins to alter where the template files are located. 
  28. * @since 1.1.0 
  29. * @param string $template Located template path. 
  30. * @param array $filtered_templates Array of templates to attempt to load. 
  31. */ 
  32. $located_template = apply_filters( 'bp_located_template', $template, $filtered_templates ); 
  33.  
  34. /** 
  35. * If current page is an embed, wipe out bp-default template. 
  36. * Wiping out the bp-default template allows WordPress to use their special 
  37. * embed template, which is what we want. 
  38. */ 
  39. if ( function_exists( 'is_embed' ) && is_embed() ) { 
  40. $located_template = ''; 
  41.  
  42. if ( !empty( $located_template ) ) { 
  43. // Template was located, lets set this as a valid page and not a 404. 
  44. status_header( 200 ); 
  45. $wp_query->is_page = true; 
  46. $wp_query->is_singular = true; 
  47. $wp_query->is_404 = false; 
  48.  
  49. /** 
  50. * Fires before the loading of a located template file. 
  51. * @since 1.6.0 
  52. * @param string $located_template Template found to be loaded. 
  53. */ 
  54. do_action( 'bp_core_pre_load_template', $located_template ); 
  55.  
  56. /** 
  57. * Filters the selected template right before loading. 
  58. * @since 1.1.0 
  59. * @param string $located_template Template found to be loaded. 
  60. */ 
  61. load_template( apply_filters( 'bp_load_template', $located_template ) ); 
  62.  
  63. /** 
  64. * Fires after the loading of a located template file. 
  65. * @since 1.6.0 
  66. * @param string $located_template Template found that was loaded. 
  67. */ 
  68. do_action( 'bp_core_post_load_template', $located_template ); 
  69.  
  70. // Kill any other output after this. 
  71. exit(); 
  72.  
  73. // No template found, so setup theme compatibility. 
  74. // @todo Some other 404 handling if theme compat doesn't kick in. 
  75. } else { 
  76.  
  77. // We know where we are, so reset important $wp_query bits here early. 
  78. // The rest will be done by bp_theme_compat_reset_post() later. 
  79. if ( is_buddypress() ) { 
  80. status_header( 200 ); 
  81. $wp_query->is_page = true; 
  82. $wp_query->is_singular = true; 
  83. $wp_query->is_404 = false; 
  84.  
  85. /** 
  86. * Fires if there are no found templates to load and theme compat is needed. 
  87. * @since 1.7.0 
  88. */