Skip to:
Content

BuddyPress.org

Changeset 9399


Ignore:
Timestamp:
01/22/2015 05:47:27 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Move page-template support into BP Legacy template pack. Props imath. See #6065.

Location:
trunk/src
Files:
3 edited

Legend:

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

    r9393 r9399  
    6565// Filter BuddyPress template locations
    6666add_filter( 'bp_get_template_stack', 'bp_add_template_stack_locations' );
    67 
    68 // Filter BuddyPress template hierarchy and look for page templates
    69 add_filter( 'bp_get_buddypress_template', 'bp_theme_compat_page_templates' );
    7067
    7168// Turn comments off for BuddyPress pages
  • trunk/src/bp-core/bp-core-template-loader.php

    r9391 r9399  
    463463    ) );
    464464}
    465 
    466 /**
    467  * Filter the default theme compatibility root template hierarchy, and prepend
    468  * a page template to the front if it's set.
    469  *
    470  * @see https://buddypress.trac.wordpress.org/ticket/6065
    471  *
    472  * @since BuddyPress (2.2.0)
    473  *
    474  * @param  array $templates
    475  * @return array
    476  */
    477 function bp_theme_compat_page_templates( $templates = array() ) {
    478 
    479     // Bail if not looking at a directory
    480     if ( ! bp_is_directory() ) {
    481         return $templates;
    482     }
    483 
    484     // No page ID yet
    485     $page_id = 0;
    486 
    487     // Get the WordPress Page ID for the current view.
    488     foreach ( (array) buddypress()->pages as $component => $bp_page ) {
    489 
    490         // Handles the majority of components.
    491         if ( bp_is_current_component( $component ) ) {
    492             $page_id = (int) $bp_page->id;
    493         }
    494 
    495         // Stop if not on a user page.
    496         if ( ! bp_is_user() && ! empty( $page_id ) ) {
    497             break;
    498         }
    499 
    500         // The Members component requires an explicit check due to overlapping components.
    501         if ( bp_is_user() && ( 'members' === $component ) ) {
    502             $page_id = (int) $bp_page->id;
    503             break;
    504         }
    505     }
    506 
    507     // Bail if no directory page set
    508     if ( 0 === $page_id ) {
    509         return $templates;
    510     }
    511 
    512     // Check for page template
    513     $page_template = get_page_template_slug( $page_id );
    514 
    515     // Add it to the beginning of the templates array so it takes precedence
    516     // over the default hierarchy.
    517     if ( ! empty( $page_template ) ) {
    518         array_unshift( $templates, $page_template );
    519     }
    520 
    521     return $templates;
    522 }
  • trunk/src/bp-templates/bp-legacy/buddypress-functions.php

    r9351 r9399  
    8181        add_filter( 'bp_get_activity_action_pre_meta', array( $this, 'secondary_avatars' ), 10, 2 );
    8282
     83        // Filter BuddyPress template hierarchy and look for page templates
     84        add_filter( 'bp_get_buddypress_template', array( $this, 'theme_compat_page_templates' ), 10, 1 );
     85
    8386        /** Scripts ***********************************************************/
    8487
     
    8891        add_action( 'bp_head',            array( $this, 'head_scripts'     ) ); // Output some extra JS in the <head>
    8992
    90         /** Body no-js Class ********************************************************/
     93        /** Body no-js Class **************************************************/
     94
    9195        add_filter( 'body_class', array( $this, 'add_nojs_body_class' ), 20, 1 );
    9296
     
    120124                add_action( 'bp_blogs_directory_blog_types', 'bp_legacy_theme_blog_create_nav', 999 );
    121125            }
    122 
    123 
    124126        }
    125127
     
    441443        return $action;
    442444    }
     445
     446    /**
     447     * Filter the default theme compatibility root template hierarchy, and prepend
     448     * a page template to the front if it's set.
     449     *
     450     * @see https://buddypress.trac.wordpress.org/ticket/6065
     451     *
     452     * @since BuddyPress (2.2.0)
     453     *
     454     * @param  array $templates
     455     * @uses   apply_filters() call 'bp_legacy_theme_compat_page_templates_directory_only' and return false
     456     *                         to use the defined page template for component's directory and its single items
     457     * @return array
     458     */
     459    public function theme_compat_page_templates( $templates = array() ) {
     460
     461        // Bail if not looking at a directory
     462        if ( true === (bool) apply_filters( 'bp_legacy_theme_compat_page_templates_directory_only', ! bp_is_directory() ) ) {
     463            return $templates;
     464        }
     465
     466        // No page ID yet
     467        $page_id = 0;
     468
     469        // Get the WordPress Page ID for the current view.
     470        foreach ( (array) buddypress()->pages as $component => $bp_page ) {
     471
     472            // Handles the majority of components.
     473            if ( bp_is_current_component( $component ) ) {
     474                $page_id = (int) $bp_page->id;
     475            }
     476
     477            // Stop if not on a user page.
     478            if ( ! bp_is_user() && ! empty( $page_id ) ) {
     479                break;
     480            }
     481
     482            // The Members component requires an explicit check due to overlapping components.
     483            if ( bp_is_user() && ( 'members' === $component ) ) {
     484                $page_id = (int) $bp_page->id;
     485                break;
     486            }
     487        }
     488
     489        // Bail if no directory page set
     490        if ( 0 === $page_id ) {
     491            return $templates;
     492        }
     493
     494        // Check for page template
     495        $page_template = get_page_template_slug( $page_id );
     496
     497        // Add it to the beginning of the templates array so it takes precedence
     498        // over the default hierarchy.
     499        if ( ! empty( $page_template ) ) {
     500            array_unshift( $templates, $page_template );
     501        }
     502
     503        return $templates;
     504    }
    443505}
    444506new BP_Legacy();
Note: See TracChangeset for help on using the changeset viewer.