bp_displayed_user_get_front_template( object|null $displayed_user = null )

Locate a custom user front template if it exists.

Description

Parameters

$displayed_user

(Optional) Falls back to current user if not passed.

Default value: null

Return

(string|bool) Path to front template on success; boolean false on failure.

Source

File: bp-members/bp-members-template.php

1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
function bp_displayed_user_get_front_template( $displayed_user = null ) {
    if ( ! is_object( $displayed_user ) || empty( $displayed_user->id ) ) {
        $displayed_user = bp_get_displayed_user();
    }
 
    if ( ! isset( $displayed_user->id ) ) {
        return false;
    }
 
    if ( isset( $displayed_user->front_template ) ) {
        return $displayed_user->front_template;
    }
 
    // Init the hierarchy
    $template_names = array(
        'members/single/front-id-' . sanitize_file_name( $displayed_user->id ) . '.php',
        'members/single/front-nicename-' . sanitize_file_name( $displayed_user->userdata->user_nicename ) . '.php',
    );
 
    /**
     * Check for profile types and add it to the hierarchy
     *
     * Make sure to register your member
     * type using the hook 'bp_register_member_types'
     */
    if ( bp_get_member_types() ) {
        $displayed_user_member_type = bp_get_member_type( $displayed_user->id );
        if ( ! $displayed_user_member_type ) {
            $displayed_user_member_type = 'none';
        }
 
        $template_names[] = 'members/single/front-member-type-' . sanitize_file_name( $displayed_user_member_type )   . '.php';
    }
 
    // Add The generic template to the end of the hierarchy
    $template_names[] = 'members/single/front.php';
 
    /**
     * Filters the hierarchy of user front templates corresponding to a specific user.
     *
     * @since BuddyPress 2.6.0
     *
     * @param array  $template_names Array of template paths.
     */
    return bp_locate_template( apply_filters( 'bp_displayed_user_get_front_template', $template_names ), false, true );
}

Changelog

Changelog
Version Description
BuddyPress 2.6.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.