Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/13/2013 01:27:01 AM (11 years ago)
Author:
boonebgorges
Message:

Introduces template hierarchy for top-level theme compat templates

The "top-level" template is the outermost template included by theme
compatibility. As of BuddyPress 1.7, a stack of template names is checked when
BP decides which top-level template to use: plugin-buddypres.php,
buddypress.php, community.php, etc. (See bp_get_theme_compat_templates().)

This changeset introduces an additional level of template hierarchy, so that
themes may provide top-level templates that are specific to the current
component, such as blogs/index-directory.php, or specific to the current item,
action, or status, such as groups/single/index-id-{$group_id}.php. In this way,
BP's top-level template hierarchy becomes more flexible for theme devs, and
more closely parallels the template hierarchy used by WordPress.

Note that this changeset only implements hierarchy for the top-level templates.
Inner template parts may receive a parallel hierarchy in a future version of
BuddyPress.

Fixes #4639

Props r-a-y

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs/bp-blogs-screens.php

    r6419 r7212  
    8787            do_action( 'bp_blogs_screen_index' );
    8888
     89            add_filter( 'bp_get_buddypress_template',                array( $this, 'directory_template_hierarchy' ) );
    8990            add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) );
    9091            add_filter( 'bp_replace_the_content',                    array( $this, 'directory_content'    ) );
     
    9293        // Create blog
    9394        } elseif ( is_user_logged_in() && bp_blog_signup_enabled() ) {
     95            add_filter( 'bp_get_buddypress_template',                array( $this, 'create_template_hierarchy' ) );
    9496            add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'create_dummy_post' ) );
    9597            add_filter( 'bp_replace_the_content',                    array( $this, 'create_content'    ) );         
     
    98100
    99101    /** Directory *************************************************************/
     102
     103    /**
     104     * Add template hierarchy to theme compat for the blog directory page.
     105     *
     106     * This is to mirror how WordPress has {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
     107     *
     108     * @since BuddyPress (1.8)
     109     *
     110     * @param string $templates The templates from bp_get_theme_compat_templates()
     111     * @return array $templates Array of custom templates to look for.
     112     */
     113    public function directory_template_hierarchy( $templates ) {
     114        // Setup our templates based on priority
     115        $new_templates = apply_filters( 'bp_template_hierarchy_blogs_create', array(
     116            'blogs/index-directory.php'
     117        ) );
     118
     119        // Merge new templates with existing stack
     120        // @see bp_get_theme_compat_templates()
     121        $templates = array_merge( (array) $new_templates, $templates );
     122
     123        return $templates;
     124    }
    100125
    101126    /**
     
    138163
    139164    /**
     165     * Add custom template hierarchy to theme compat for the blog create page.
     166     *
     167     * This is to mirror how WordPress has {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
     168     *
     169     * @since BuddyPress (1.8)
     170     *
     171     * @param string $templates The templates from bp_get_theme_compat_templates()
     172     * @return array $templates Array of custom templates to look for.
     173     */
     174    public function create_template_hierarchy( $templates ) {
     175        // Setup our templates based on priority
     176        $new_templates = apply_filters( 'bp_template_hierarchy_blogs_create', array(
     177            'blogs/index-create.php'
     178        ) );
     179
     180        // Merge new templates with existing stack
     181        // @see bp_get_theme_compat_templates()
     182        $templates = array_merge( (array) $new_templates, $templates );
     183
     184        return $templates;
     185    }
     186
     187    /**
    140188     * Update the global $post with create screen data
    141189     *
Note: See TracChangeset for help on using the changeset viewer.