Skip to:
Content

BuddyPress.org

Ticket #6188: 6188.patch

File 6188.patch, 1.6 KB (added by Offereins, 6 years ago)
  • src/bp-members/bp-members-functions.php

    diff --git src/bp-members/bp-members-functions.php src/bp-members/bp-members-functions.php
    index 005151f..8f2cb2b 100644
    function bp_get_member_type( $user_id, $single = true ) { 
    26452645}
    26462646
    26472647/**
     2648 * Remove type for a member.
     2649 *
     2650 * @since BuddyPress (2.3.0)
     2651 *
     2652 * @param  int    $user_id     ID of the user.
     2653 * @param  string $member_type Member type.
     2654 * @return See {@see bp_set_object_terms()}.
     2655 */
     2656function bp_remove_member_type( $user_id, $member_type ) {
     2657
     2658        // Bail when no valid member type was passed
     2659        if ( empty( $member_type ) || ! bp_get_member_type_object( $member_type ) ) {
     2660                return false;
     2661        }
     2662
     2663        // Get all user's member types
     2664        $types = bp_get_member_type( $user_id, false );
     2665
     2666        // Bail when the user does not have the given type
     2667        if ( ! in_array( $member_type, $types ) ) {
     2668                return true;
     2669        }
     2670
     2671        $retval = bp_set_object_terms( $user_id, array_diff( $types, (array) $member_type ), 'bp_member_type', $append );
     2672
     2673        // Bust the cache if the type has been updated.
     2674        if ( ! is_wp_error( $retval ) ) {
     2675                wp_cache_delete( $user_id, 'bp_member_type' );
     2676
     2677                /**
     2678                 * Fires just after a user's member type has been removed.
     2679                 *
     2680                 * @since BuddyPress (2.3.0)
     2681                 *
     2682                 * @param int    $user_id     ID of the user whose member type has been removed.
     2683                 * @param string $member_type Member type.
     2684                 */
     2685                do_action( 'bp_remove_member_type', $user_id, $member_type );
     2686        }
     2687
     2688        return $retval;
     2689}
     2690
     2691/**
    26482692 * Delete a user's member type when the user when the user is deleted.
    26492693 *
    26502694 * @since BuddyPress (2.2.0)