Skip to:
Content

BuddyPress.org

Ticket #4546: 4546.01.patch

File 4546.01.patch, 3.3 KB (added by r-a-y, 12 years ago)
  • bp-core/bp-core-template-loader.php

    function bp_get_template_part( $slug, $name = null ) { 
    4646/**
    4747 * Retrieve the name of the highest priority template file that exists.
    4848 *
    49  * Searches in the STYLESHEETPATH before TEMPLATEPATH so that themes which
    50  * inherit from a parent theme can just overload one file. If the template is
    51  * not found in either of those, it looks in the theme-compat folder last.
     49 * Searches in the current theme's folder (child or parent) to see if a
     50 * template was overriden. If the template is not found in the current theme,
     51 * it uses our theme-compat template last.
    5252 *
    5353 * @since BuddyPress (1.7)
    5454 *
    function bp_locate_template( $template_names, $load = false, $require_once = tru 
    7272
    7373                // Trim off any slashes from the template name
    7474                $template_name = ltrim( $template_name, '/' );
    75                 $child_theme    = get_stylesheet_directory();
    76                 $parent_theme   = get_template_directory();
    7775                $fallback_theme = bp_get_theme_compat_dir();
    7876
    79                 // Check child theme first
    80                 if ( file_exists( trailingslashit( $child_theme ) . $template_name ) ) {
    81                         $located = trailingslashit( $child_theme ) . $template_name;
    82                         break;
     77                // Use locate_template() to check the current theme (both child and parent)
     78                // for a BP template
     79                $located = locate_template( (array) $template_name );
    8380
    84                 // Check parent theme next
    85                 } elseif ( file_exists( trailingslashit( $parent_theme ) . $template_name ) ) {
    86                         $located = trailingslashit( $child_theme ) . $template_name;
     81                // we've located a template in the current theme, so stop!
     82                if ( ! empty( $located ) ) {
    8783                        break;
    8884
    89                 // Check theme compatibility last
    90                 } elseif ( file_exists( trailingslashit( $fallback_theme ) . $template_name ) ) {
    91                         $located = trailingslashit( $fallback_theme ) . $template_name;
    92                         break;
     85                // if no override template, use theme compatibility template last
     86                } else {
     87                        // 3rd-party plugin devs can hook into the 'bp_locate_fallback_template' filter to load custom templates if desired
     88                        $fallback_template = apply_filters( 'bp_locate_fallback_template', trailingslashit( $fallback_theme ) . $template_name, $template_name );
     89
     90                        if ( file_exists( $fallback_template ) ) {
     91                                $located = $fallback_template;
     92                                break;
     93                        }
    9394                }
     95
    9496        }
    9597
     98        // one final filter just in case someone wants to go crazy and override a theme's template from a plugin!
     99        $located = apply_filters( 'bp_locate_template', $located, $template_names );
     100
    96101        if ( ( true == $load ) && !empty( $located ) )
    97102                load_template( $located, $require_once );
    98103
    function bp_get_template_locations( $templates = array() ) { 
    188193 * @since BuddyPress (1.7)
    189194 *
    190195 * @param array $templates
    191  * @return array() 
     196 * @return array()
    192197 */
    193198function bp_add_template_locations( $templates = array() ) {
    194199        $retval = array();
    function bp_parse_query( $posts_query ) { 
    234239 *
    235240 * Listens to the 'template_include' filter and waits for any BuddyPress specific
    236241 * template condition to be met. If one is met and the template file exists,
    237  * it will be used; otherwise 
     242 * it will be used; otherwise
    238243 *
    239244 * Note that the _edit() checks are ahead of their counterparts, to prevent them
    240245 * from being stomped on accident.