bp_get_member_type( int $user_id, bool $single = true )

Get type for a member.

Description

Parameters

$user_id

(Required) ID of the user.

$single

(Optional) Whether to return a single type string. If multiple types are found for the user, the oldest one will be returned. Default: true.

Default value: true

Return

(string|array|bool) On success, returns a single profile type (if $single is true) or an array of member types (if $single is false). Returns false on failure.

Source

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

2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
function bp_get_member_type( $user_id, $single = true ) {
    $types = wp_cache_get( $user_id, 'bp_member_member_type' );
 
    if ( false === $types ) {
        $raw_types = bp_get_object_terms( $user_id, bp_get_member_type_tax_name() );
 
        if ( ! is_wp_error( $raw_types ) ) {
            $types array();
 
            // Only include currently registered group types.
            foreach ( $raw_types as $mtype ) {
                if ( bp_get_member_type_object( $mtype->name ) ) {
                    $types[] = $mtype->name;
                }
            }
 
            wp_cache_set( $user_id, $types, 'bp_member_member_type' );
        }
    }
 
    $type = false;
    if ( ! empty( $types ) ) {
        if ( $single ) {
            $type = array_pop( $types );
        } else {
            $type = $types;
        }
    }
 
    /**
     * Filters a user's profile type(s).
     *
     * @since BuddyPress 2.2.0
     *
     * @param string $type    profile type.
     * @param int    $user_id ID of the user.
     * @param bool   $single  Whether to return a single type string, or an array.
     */
    return apply_filters( 'bp_get_member_type', $type, $user_id, $single );
}

Changelog

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