Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/10/2015 03:43:27 PM (6 years ago)
Author:
boonebgorges
Message:

Introduce bp_has_member_type().

This function allows developers to test whether a given user has a given member
type. Thus the clever function name.

Props Offereins, Mamaduka.
Fixes #6138.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-functions.php

    r9589 r9611  
    26822682
    26832683/**
     2684 * Check whether the given user has a certain member type.
     2685 *
     2686 * @since BuddyPress (2.3.0)
     2687 *
     2688 * @param  int    $user_id     $user_id ID of the user.
     2689 * @param  string $member_type Member Type.
     2690 * @return bool Whether the user has the given member type.
     2691 */
     2692function bp_has_member_type( $user_id, $member_type ) {
     2693    // Bail if no valid member type was passed.
     2694    if ( empty( $member_type ) || ! bp_get_member_type_object( $member_type ) ) {
     2695        return false;
     2696    }
     2697
     2698    // Get all user's member types.
     2699    $types = bp_get_member_type( $user_id, false );
     2700
     2701    if ( ! is_array( $types ) ) {
     2702        return false;
     2703    }
     2704
     2705    return in_array( $member_type, $types );
     2706}
     2707
     2708/**
    26842709 * Delete a user's member type when the user when the user is deleted.
    26852710 *
Note: See TracChangeset for help on using the changeset viewer.