Skip to:
Content

BuddyPress.org

Changeset 9389


Ignore:
Timestamp:
01/21/2015 07:31:58 PM (12 years ago)
Author:
johnjamesjacoby
Message:

Introduce bp_theme_compat_page_templates() for determining if a directory page template is available as an override for the theme compatibility template hierarchy.

This fixes a fatal PHP error when the results of get_page_template_slug() do not match an available template for the currently active parent or child themes, causing that directory page to have no fallback template (and consequently template_include to receive an empty array.)

Fixes #6065.

Location:
trunk/src/bp-core
Files:
2 edited

Legend:

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

    r9351 r9389  
    6464
    6565// Filter BuddyPress template locations
    66 add_filter( 'bp_get_template_stack', 'bp_add_template_stack_locations'          );
     66add_filter( 'bp_get_template_stack', 'bp_add_template_stack_locations' );
     67
     68// Filter BuddyPress template hierarchy and look for page templates
     69add_filter( 'bp_get_buddypress_template', 'bp_theme_compat_page_templates' );
    6770
    6871// Turn comments off for BuddyPress pages
  • trunk/src/bp-core/bp-core-template-loader.php

    r9351 r9389  
    443443 */
    444444function bp_get_theme_compat_templates() {
    445         $page_id = 0;
    446 
    447         // Get the WordPress Page ID for the current view.
    448         foreach ( (array) buddypress()->pages as $component => $bp_page ) {
    449 
    450                 // Handles the majority of components.
    451                 if ( bp_is_current_component( $component ) ) {
    452                         $page_id = (int) $bp_page->id;
    453                 }
    454 
    455                 // Stop if not on a user page.
    456                 if ( ! bp_is_user() && ! empty( $page_id ) ) {
    457                         break;
    458                 }
    459 
    460                 // The Members component requires an explicit check due to overlapping components.
    461                 if ( bp_is_user() && 'members' === $component ) {
    462                         $page_id = (int) $bp_page->id;
    463                         break;
    464                 }
    465         }
    466 
    467         $templates = array(
     445        return bp_get_query_template( 'buddypress', array(
    468446                'plugin-buddypress.php',
    469447                'buddypress.php',
     
    473451                'single.php',
    474452                'index.php'
    475         );
    476 
    477         // If the Page has a Page Template set, use that.
    478         if ( $page_id ) {
    479                 $template_file = get_page_template_slug( $page_id );
    480 
    481                 if ( $template_file ) {
    482                         $templates = array( $template_file );
     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
     475        $page_id = 0;
     476
     477        // Get the WordPress Page ID for the current view.
     478        foreach ( (array) buddypress()->pages as $component => $bp_page ) {
     479
     480                // Handles the majority of components.
     481                if ( bp_is_current_component( $component ) ) {
     482                        $page_id = (int) $bp_page->id;
    483483                }
    484         }
    485 
    486         return bp_get_query_template( 'buddypress', $templates );
    487 }
     484
     485                // Stop if not on a user page.
     486                if ( ! bp_is_user() && ! empty( $page_id ) ) {
     487                        break;
     488                }
     489
     490                // The Members component requires an explicit check due to overlapping components.
     491                if ( bp_is_user() && ( 'members' === $component ) ) {
     492                        $page_id = (int) $bp_page->id;
     493                        break;
     494                }
     495        }
     496
     497        // Bail if no directory page set
     498        if ( 0 === $page_id ) {
     499                return $templates;
     500        }
     501
     502        // Check for page template
     503        $page_template = get_page_template_slug( $page_id );
     504
     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 );
     509        }
     510
     511        return $templates;
     512}
Note: See TracChangeset for help on using the changeset viewer.