bp_set_member_type( int $user_id, string|array $member_type, bool $append = false )

Set type for a member.


Parameters Parameters

$user_id

(int) (Required) ID of the user.

$member_type

(string|array) (Required) The member type name or an array of member type names.

$append

(bool) (Optional) True to append this to existing types for user, false to replace. Default: false.

Default value: false


Top ↑

Return Return

(false|array) $retval See bp_set_object_terms().


Source Source

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

function bp_set_member_type( $user_id, $member_type, $append = false ) {
	// Pass an empty $member_type to remove a user's type.
	if ( ! empty( $member_type ) ) {
		$member_types = (array) $member_type;
		$valid_types  = array_filter( array_map( 'bp_get_member_type_object', $member_types ) );

		if ( $valid_types ) {
			$member_type = wp_list_pluck( $valid_types, 'name' );
		} else {
			return false;
		}
	}

	$retval = bp_set_object_terms( $user_id, $member_type, bp_get_member_type_tax_name(), $append );

	// Bust the cache if the type has been updated.
	if ( ! is_wp_error( $retval ) ) {
		wp_cache_delete( $user_id, 'bp_member_member_type' );

		/**
		 * Fires just after a user's member type has been changed.
		 *
		 * @since 2.2.0
		 *
		 * @param int          $user_id     ID of the user whose member type has been updated.
		 * @param string|array $member_type The member type name or an array of member type names.
		 * @param bool         $append      Whether the type is being appended to existing types.
		 */
		do_action( 'bp_set_member_type', $user_id, $member_type, $append );
	}

	return $retval;
}


Top ↑

Changelog Changelog

Changelog
Version Description
7.0.0 $member_type parameter also accepts an array of member type names.
2.2.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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