bp_get_member_type

Get type for a member.

Description

(string|array|bool) bp_get_member_type( (int) $user_id, (bool) $single = true ); 

Returns (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.

Parameters (2)

0. $user_id (int)
ID of the user.
1. $single — Optional. (bool) => true
Whether to return a single type string. If multiple types are found for the user, the oldest one will be returned. Default: true.

Usage

  1. if ( !function_exists( 'bp_get_member_type' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-members/bp-members-functions.php'; 
  3.  
  4. // ID of the user. 
  5. $user_id = -1; 
  6.  
  7. // Optional. Whether to return a single type string. If multiple types are found 
  8. // for the user, the oldest one will be returned. Default: true. 
  9. $single = true; 
  10.  
  11. // NOTICE! Understand what this does before running. 
  12. $result = bp_get_member_type($user_id, $single); 
  13.  

Defined (1)

The function is defined in the following location(s).

/bp-members/bp-members-functions.php  
  1. function bp_get_member_type( $user_id, $single = true ) { 
  2. $types = wp_cache_get( $user_id, 'bp_member_member_type' ); 
  3.  
  4. if ( false === $types ) { 
  5. $raw_types = bp_get_object_terms( $user_id, bp_get_member_type_tax_name() ); 
  6.  
  7. if ( ! is_wp_error( $raw_types ) ) { 
  8. $types = array(); 
  9.  
  10. // Only include currently registered group types. 
  11. foreach ( $raw_types as $mtype ) { 
  12. if ( bp_get_member_type_object( $mtype->name ) ) { 
  13. $types[] = $mtype->name; 
  14.  
  15. wp_cache_set( $user_id, $types, 'bp_member_member_type' ); 
  16.  
  17. $type = false; 
  18. if ( ! empty( $types ) ) { 
  19. if ( $single ) { 
  20. $type = array_pop( $types ); 
  21. } else { 
  22. $type = $types; 
  23.  
  24. /** 
  25. * Filters a user's member type(s). 
  26. * @since 2.2.0 
  27. * @param string $type Member type. 
  28. * @param int $user_id ID of the user. 
  29. * @param bool $single Whether to return a single type string, or an array. 
  30. */ 
  31. return apply_filters( 'bp_get_member_type', $type, $user_id, $single );