Skip to:
Content

BuddyPress.org

Changeset 9575


Ignore:
Timestamp:
03/02/2015 06:53:12 PM (6 years ago)
Author:
boonebgorges
Message:

Introduce bp_remove_member_type().

Props Offereins, Mamaduka.
Fixes #6188.

Location:
trunk
Files:
2 edited

Legend:

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

    r9533 r9575  
    26022602
    26032603/**
     2604 * Remove type for a member.
     2605 *
     2606 * @since BuddyPress (2.3.0)
     2607 *
     2608 * @param int    $user_id     ID of the user.
     2609 * @param string $member_type Member Type.
     2610 *
     2611 * @return bool|WP_Error
     2612 */
     2613function bp_remove_member_type( $user_id, $member_type ) {
     2614    // Bail if no valid member type was passed.
     2615    if ( empty( $member_type ) || ! bp_get_member_type_object( $member_type ) ) {
     2616        return false;
     2617    }
     2618
     2619    $deleted = wp_remove_object_terms( $user_id, $member_type, 'bp_member_type' );
     2620
     2621    // Bust the cache if the type has been removed.
     2622    if ( ! is_wp_error( $deleted ) ) {
     2623        wp_cache_delete( $user_id, 'bp_member_member_type' );
     2624
     2625        /**
     2626         * Fires just after a user's member type has been removed.
     2627         *
     2628         * @since BuddyPress (2.3.0)
     2629         *
     2630         * @param int    $user_id     ID of the user whose member type has been updated.
     2631         * @param string $member_type Member type.
     2632         */
     2633        do_action( 'bp_remove_member_type', $user_id, $member_type );
     2634    }
     2635
     2636    return $deleted;
     2637}
     2638
     2639/**
    26042640 * Get type for a member.
    26052641 *
  • trunk/tests/phpunit/testcases/members/types.php

    r9533 r9575  
    236236        $this->assertSame( 'foo', bp_get_member_type( $new_user_id, true ) );
    237237    }
     238
     239    /**
     240     * @group BP6188
     241     */
     242    public function test_bp_remove_member_type_should_return_false_when_member_type_is_empty() {
     243        $this->assertFalse( bp_remove_member_type( 5, '' ) );
     244    }
     245
     246    /**
     247     * @group BP6188
     248     */
     249    public function test_bp_remove_member_type_should_return_false_when_member_type_is_invalid() {
     250        $this->assertFalse( bp_remove_member_type( 5, 'foo' ) );
     251    }
     252
     253    /**
     254     * @group BP6188
     255     */
     256    public function test_bp_remove_member_type_should_return_false_when_member_is_not_of_provided_type() {
     257        $u1 = $this->factory->user->create();
     258        bp_register_member_type( 'foo' );
     259        bp_register_member_type( 'bar' );
     260        bp_set_member_type( $u1, 'bar' );
     261
     262        $this->assertFalse( bp_remove_member_type( $u1, 'foo' ) );
     263        $types = bp_get_member_type( $u1, false );
     264        $this->assertEquals( array( 'bar' ), $types );
     265    }
     266
     267    /**
     268     * @group BP6188
     269     */
     270    public function test_bp_remove_member_type_should_return_true_for_successful_deletion() {
     271        $u1 = $this->factory->user->create();
     272        bp_register_member_type( 'foo' );
     273        bp_register_member_type( 'bar' );
     274        bp_set_member_type( $u1, 'foo' );
     275        bp_set_member_type( $u1, 'bar', true );
     276
     277        $this->assertTrue( bp_remove_member_type( $u1, 'foo' ) );
     278        $types = bp_get_member_type( $u1, false );
     279        $this->assertEquals( array( 'bar' ), $types );
     280    }
    238281}
Note: See TracChangeset for help on using the changeset viewer.