| 249 | * Includes, into page output, a template file. To be used within a template included by bp_core_load_template(). |
| 250 | * |
| 251 | * If the requested template follows the BuddyPress core theme file structure, for example "[groups]/[single]/file.php" |
| 252 | * i.e. being a file of a registered root component underneath its "single" folder, we'll also try to match against a version |
| 253 | * of that template path suffixed with the identifier of the object of the current component. |
| 254 | * |
| 255 | * For example, on pages of a group named "snugglewugglepants", we'd look for "groups/single/file-snugglewugglepants.php" |
| 256 | * as well as plain-old "groups/single/file.php". |
| 257 | * |
| 258 | * Underneath the member page hierarchy, the user's login name is used, e.g. "members/single/page-admin.php" for the admin user. |
| 259 | * |
| 260 | * @global object $bp BuddyPress global settings |
| 261 | * @param array $templates Requested templates, in priority order |
| 262 | * @see bp_core_add_root_component() |
| 263 | * @see bp_core_load_template() |
| 264 | * @since 2.0 |
| 265 | */ |
| 266 | function bp_load_template( $templates ) { |
| 267 | global $bp; |
| 268 | |
| 269 | $alternative_templates = array(); |
| 270 | |
| 271 | foreach ( $templates as $template ) { |
| 272 | $uri = explode( '/', $template ); |
| 273 | $uri_size = count( $uri ); |
| 274 | |
| 275 | if ( !is_array( $uri ) || $uri_size < 2 ) |
| 276 | continue; |
| 277 | |
| 278 | if ( '/' == $uri[0] ) { |
| 279 | unset( $uri[0] ); |
| 280 | $uri = array_merge( $uri, array() ); // Reset the keys by merging with an empty array |
| 281 | } |
| 282 | |
| 283 | if ( !in_array( $uri[0], $bp->root_components ) || 'single' != $uri[1] ) |
| 284 | continue; |
| 285 | |
| 286 | if ( $bp->current_item ) |
| 287 | $template_slug = $bp->current_item; |
| 288 | elseif ( BP_MEMBERS_SLUG == $uri[0] && isset( $bp->displayed_user ) ) |
| 289 | $template_slug = $bp->displayed_user->userdata->user_login; |
| 290 | else |
| 291 | continue; |
| 292 | |
| 293 | $extension = strpos( $uri[$uri_size - 1], '.php' ); |
| 294 | if ( false === $extension ) |
| 295 | continue; |
| 296 | |
| 297 | $template_slug = apply_filters( 'bp_load_template_slug', $template_slug, $template, $templates ); |
| 298 | if ( $template_slug ) { |
| 299 | // Reconstruct the URL with the filename suffix |
| 300 | $uri[$uri_size - 1] = substr( $uri[$uri_size - 1], 0, $extension ) . "-{$template_slug}.php"; |
| 301 | $alternative_templates[] = implode( '/', $uri ); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | $templates = array_merge( apply_filters( 'bp_load_template_alternatives', $alternative_templates, $templates ), $templates ); |
| 306 | if ( $located_template = apply_filters( 'bp_located_template', locate_template( $templates, false ), $templates, $alternative_templates ) ) |
| 307 | load_template( apply_filters( 'bp_load_template', $located_template ) ); |
| 308 | } |
| 309 | |
| 310 | /** |