Skip to:
Content

BuddyPress.org

Changeset 9306


Ignore:
Timestamp:
01/07/2015 08:15:06 PM (9 years ago)
Author:
djpaul
Message:

If a component's mapped Page's template is set in wp-admin, use that instead of BP's default template stack.

This allows people to override which page template BuddyPress injects its content into.

While this was previously possible by creating a specially-named template file in the theme, the technique was a little obscure. This alternate solution is user friendly and allows different container page templates on a per-component basis.

Fixes #6065

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-template-loader.php

    r8463 r9306  
    443443 */
    444444function bp_get_theme_compat_templates() {
     445    $page_id       = 0;
     446    $page_template = array();
     447
     448    // Get the WordPress Page ID for the current view.
     449    foreach ( (array) buddypress()->pages as $component => $bp_page ) {
     450
     451        // Handles the majority of components.
     452        if ( bp_is_current_component( $component ) ) {
     453            $page_id = (int) $bp_page->id;
     454        }
     455
     456        // Stop if not on a user page.
     457        if ( ! bp_is_user() && ! empty( $page_id ) ) {
     458            break;
     459        }
     460
     461        // The Members component requires an explicit check due to overlapping components.
     462        if ( bp_is_user() && 'members' === $component ) {
     463            $page_id = (int) $bp_page->id;
     464            break;
     465        }
     466    }
     467
    445468    $templates = array(
    446469        'plugin-buddypress.php',
     
    452475        'index.php'
    453476    );
     477
     478    // If the Page has a Page Template set, use that.
     479    if ( $page_id ) {
     480        $template_file = get_page_template_slug( $page_id );
     481
     482        if ( $template_file ) {
     483            $templates = array( $template_file );
     484        }
     485    }
     486
    454487    return bp_get_query_template( 'buddypress', $templates );
    455488}
Note: See TracChangeset for help on using the changeset viewer.