BP_Members_Theme_Compat::single_template_hierarchy( string $templates )

Add custom template hierarchy to theme compat for member pages.

Description

This is to mirror how WordPress has template hierarchy.

Parameters

$templates

(Required) The templates from bp_get_theme_compat_templates().

Return

(array) $templates Array of custom templates to look for.

Source

File: bp-members/classes/class-bp-members-theme-compat.php

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
public function single_template_hierarchy( $templates ) {
    // Setup some variables we're going to reference in our custom templates.
    $user_nicename = buddypress()->displayed_user->userdata->user_nicename;
 
    /**
     * Filters the template hierarchy for theme compat and member pages.
     *
     * @since BuddyPress 1.8.0
     *
     * @param array $value Array of template paths to add to hierarchy.
     */
    $new_templates = apply_filters( 'bp_template_hierarchy_members_single_item', array(
        'members/single/index-id-'        . sanitize_file_name( bp_displayed_user_id() ) . '.php',
        'members/single/index-nicename-'  . sanitize_file_name( $user_nicename )         . '.php',
        'members/single/index-action-'    . sanitize_file_name( bp_current_action() )    . '.php',
        'members/single/index-component-' . sanitize_file_name( bp_current_component() ) . '.php',
        'members/single/index.php'
    ) );
 
    // Merge new templates with existing stack
    // @see bp_get_theme_compat_templates().
    $templates = array_merge( (array) $new_templates, $templates );
 
    return $templates;
}

Changelog

Changelog
Version Description
BuddyPress 1.8.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.