Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/13/2013 01:27:01 AM (6 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-groups/bp-groups-screens.php

    r6956 r7212  
    972972            do_action( 'groups_directory_groups_setup' );
    973973
     974            add_filter( 'bp_get_buddypress_template',                array( $this, 'directory_template_hierarchy' ) );
    974975            add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'directory_dummy_post' ) );
    975976            add_filter( 'bp_replace_the_content',                    array( $this, 'directory_content'    ) );
     
    977978        // Creating a group
    978979        } elseif ( bp_is_groups_component() && bp_is_current_action( 'create' ) ) {
     980            add_filter( 'bp_get_buddypress_template',                array( $this, 'create_template_hierarchy' ) );
    979981            add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'create_dummy_post' ) );
    980982            add_filter( 'bp_replace_the_content',                    array( $this, 'create_content'    ) );
    981983
    982         // Group admin
     984        // Group page
    983985        } elseif ( bp_is_single_item() ) {
     986            add_filter( 'bp_get_buddypress_template',                array( $this, 'single_template_hierarchy' ) );
    984987            add_action( 'bp_template_include_reset_dummy_post_data', array( $this, 'single_dummy_post' ) );
    985988            add_filter( 'bp_replace_the_content',                    array( $this, 'single_content'    ) );
     
    989992
    990993    /** Directory *************************************************************/
     994
     995    /**
     996     * Add template hierarchy to theme compat for the group directory page.
     997     *
     998     * This is to mirror how WordPress has {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
     999     *
     1000     * @since BuddyPress (1.8)
     1001     *
     1002     * @param string $templates The templates from bp_get_theme_compat_templates()
     1003     * @return array $templates Array of custom templates to look for.
     1004     */
     1005    public function directory_template_hierarchy( $templates ) {
     1006        // Setup our templates based on priority
     1007        $new_templates = apply_filters( 'bp_template_hierarchy_groups_directory', array(
     1008            'groups/index-directory.php'
     1009        ) );
     1010
     1011        // Merge new templates with existing stack
     1012        // @see bp_get_theme_compat_templates()
     1013        $templates = array_merge( (array) $new_templates, $templates );
     1014
     1015        return $templates;
     1016    }
    9911017
    9921018    /**
     
    10291055
    10301056    /**
     1057     * Add custom template hierarchy to theme compat for the group create page.
     1058     *
     1059     * This is to mirror how WordPress has {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
     1060     *
     1061     * @since BuddyPress (1.8)
     1062     *
     1063     * @param string $templates The templates from bp_get_theme_compat_templates()
     1064     * @return array $templates Array of custom templates to look for.
     1065     */
     1066    public function create_template_hierarchy( $templates ) {
     1067        // Setup our templates based on priority
     1068        $new_templates = apply_filters( 'bp_template_hierarchy_groups_create', array(
     1069            'groups/index-create.php'
     1070        ) );
     1071
     1072        // Merge new templates with existing stack
     1073        // @see bp_get_theme_compat_templates()
     1074        $templates = array_merge( $new_templates, $templates );
     1075
     1076        return $templates;
     1077    }
     1078
     1079    /**
    10311080     * Update the global $post with create screen data
    10321081     *
     
    10651114
    10661115    /** Single ****************************************************************/
     1116
     1117    /**
     1118     * Add custom template hierarchy to theme compat for group pages.
     1119     *
     1120     * This is to mirror how WordPress has {@link https://codex.wordpress.org/Template_Hierarchy template hierarchy}.
     1121     *
     1122     * @since BuddyPress (1.8)
     1123     *
     1124     * @param string $templates The templates from bp_get_theme_compat_templates()
     1125     * @return array $templates Array of custom templates to look for.
     1126     */
     1127    public function single_template_hierarchy( $templates ) {
     1128        // Setup some variables we're going to reference in our custom templates
     1129        $group = groups_get_current_group();
     1130
     1131        // Setup our templates based on priority
     1132        $new_templates = apply_filters( 'bp_template_hierarchy_groups_single_item', array(
     1133            'groups/single/index-id-'     . sanitize_file_name( bp_get_current_group_id() )   . '.php',
     1134            'groups/single/index-slug-'   . sanitize_file_name( bp_get_current_group_slug() ) . '.php',
     1135            'groups/single/index-action-' . sanitize_file_name( bp_current_action() )         . '.php',
     1136            'groups/single/index-status-' . sanitize_file_name( $group->status )              . '.php',
     1137            'groups/single/index.php'
     1138        ) );
     1139
     1140        // Merge new templates with existing stack
     1141        // @see bp_get_theme_compat_templates()
     1142        $templates = array_merge( (array) $new_templates, $templates );
     1143
     1144        return $templates;
     1145    }
    10671146
    10681147    /**
Note: See TracChangeset for help on using the changeset viewer.