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

Get type for a member.


Parameters Parameters

$user_id

(int) (Required) ID of the user.

$single

(bool) (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

$use_db

(bool) (Optional) Whether to request all member types or only the ones registered by code. Default: true.

Default value: true


Top ↑

Return Return

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


Source Source

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

function bp_get_member_type( $user_id, $single = true, $use_db = 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' );
		}
	}

	if ( false === $use_db && $types ) {
		$registred_by_code = bp_get_member_types_registered_by_code();
		$ctype_names       = wp_list_pluck( $registred_by_code, 'name' );
		$types             = array_intersect( $types, $ctype_names );
	}

	$type = false;
	if ( ! empty( $types ) ) {
		if ( $single ) {
			$type = array_pop( $types );
		} else {
			$type = $types;
		}
	}

	/**
	 * Filters a user's member type(s).
	 *
	 * @since 2.2.0
	 *
	 * @param string|array|bool $type    a single member type (if $single is true) or an array of member types
	 *                                   (if $single is false) or false on failure.
	 * @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 );
}


Top ↑

Changelog Changelog

Changelog
Version Description
7.0.0 Adds the $use_db parameter.
2.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.