Skip to:
Content

BuddyPress.org

Ticket #6065: 6065.02.patch

File 6065.02.patch, 2.2 KB (added by johnjamesjacoby, 10 years ago)
  • src/bp-core/bp-core-template-loader.php

     
    442442 * @return array Array of possible root level wrapper template files.
    443443 */
    444444function bp_get_theme_compat_templates() {
     445        return bp_get_query_template( 'buddypress', array(
     446                'plugin-buddypress.php',
     447                'buddypress.php',
     448                'community.php',
     449                'generic.php',
     450                'page.php',
     451                'single.php',
     452                'index.php'
     453        ) );
     454}
     455
     456/**
     457 * Filter the default theme compatibility root template hierarchy, and prepend
     458 * a page template to the front if it's set.
     459 *
     460 * @see https://buddypress.trac.wordpress.org/ticket/6065
     461 *
     462 * @since BuddyPress (2.2.0)
     463 *
     464 * @param  array $templates
     465 * @return array
     466 */
     467function bp_theme_compat_page_templates( $templates = array() ) {
     468
     469        // Bail if not looking at a directory
     470        if ( ! bp_is_directory() ) {
     471                return $templates;
     472        }
     473
     474        // No page ID yet
    445475        $page_id = 0;
    446476
    447477        // Get the WordPress Page ID for the current view.
     
    458488                }
    459489
    460490                // The Members component requires an explicit check due to overlapping components.
    461                 if ( bp_is_user() && 'members' === $component ) {
     491                if ( bp_is_user() && ( 'members' === $component ) ) {
    462492                        $page_id = (int) $bp_page->id;
    463493                        break;
    464494                }
    465495        }
    466496
    467         $templates = array(
    468                 'plugin-buddypress.php',
    469                 'buddypress.php',
    470                 'community.php',
    471                 'generic.php',
    472                 'page.php',
    473                 'single.php',
    474                 'index.php'
    475         );
     497        // Bail if no directory page set
     498        if ( 0 === $page_id ) {
     499                return $templates;
     500        }
    476501
    477         // If the Page has a Page Template set, use that.
    478         if ( $page_id ) {
    479                 $template_file = get_page_template_slug( $page_id );
     502        // Check for page template
     503        $page_template = get_page_template_slug( $page_id );
    480504
    481                 if ( $template_file ) {
    482                         $templates = array( $template_file );
    483                 }
     505        // Add it to the beginning of the templates array so it takes precedence
     506        // over the default hierarchy.
     507        if ( ! empty( $page_template ) ) {
     508                array_unshift( $templates, $page_template );
    484509        }
    485510
    486         return bp_get_query_template( 'buddypress', $templates );
     511        return $templates;
    487512}
     513add_filter( 'bp_get_buddypress_template', 'bp_theme_compat_page_templates' );