Skip to:
Content

Opened 3 years ago

Closed 3 years ago

#6188 closed enhancement (fixed)

Member Types API: remove a user's member type

Reported by: Offereins Owned by: boonebgorges
Milestone: 2.3 Priority: normal
Severity: normal Version: 2.2
Component: Members Keywords: has-patch
Cc: lmoffereins@…

Description

I find myself missing a simple method for removing a certain user's member type, especially for situations where a user has multiple member types. Passing an emtpy value to bp_set_member_type() removes *all* member types. You cannot specify which one you'd like to remove.

Attached patch introduces bp_remove_member_type( $user_id, $member_type ), which is a possible solution that handles associated cache manipulations and hooks. This should fill the gap where plugin devs are building their own implementations. I'm not sure how this ties together with the mentioned use of bp_set_member_type( $user_id, '' ), but it is a start.

Attachments (4)

6188.patch (1.6 KB) - added by Offereins 3 years ago.
6188.2.diff (1.3 KB) - added by Mamaduka 3 years ago.
6188.2.tests.diff (1.1 KB) - added by Mamaduka 3 years ago.
6188-bp_remove_object_terms.diff (1.6 KB) - added by Mamaduka 3 years ago.

Download all attachments as: .zip

Change History (13)

@Offereins
3 years ago

#1 @johnjamesjacoby
3 years ago

  • Milestone changed from Awaiting Review to 2.3

#2 @boonebgorges
3 years ago

  • Keywords needs-unit-tests added

Good catch, Offereins, and thanks for the patch. As a temporary workaround, you can do something like this to remove member type 'foo' but not 'bar';

// array( 'foo', 'bar' )
$current_types = bp_get_member_type( $user_id, false );
bp_set_member_type( $user_id, '' );
foreach ( $current_types as $type ) {
    if ( 'foo' == $type ) {
        continue;
    }

    bp_set_member_type( $user_id, $type, true );
}

The patch looks good, though I'd say that the function should return false if the user does not have the member type passed to the function (since nothing was deleted). This is how other WP delete functions work.

Let's get some unit tests for this, and put it in for 2.3.

This ticket was mentioned in Slack in #buddypress by boone. View the logs.


3 years ago

@Mamaduka
3 years ago

#4 @Mamaduka
3 years ago

  • Keywords needs-unit-tests removed

Offereins, boonebgorges

I think better approach here will be to use wp_remove_object_terms() function.

6188.2.diff updates function to use this method.

#5 @boonebgorges
3 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 9575:

Introduce bp_remove_member_type().

Props Offereins, Mamaduka.
Fixes #6188.

This ticket was mentioned in Slack in #buddypress by mamaduka. View the logs.


3 years ago

#7 @Mamaduka
3 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

#8 @Mamaduka
3 years ago

New patch introduces bp_remove_object_terms() BP taxonomy function and updates bp_remove_member_type() to use it instead of WP core one.

#9 @boonebgorges
3 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 9589:

Introduce bp_remove_object_terms() wrapper, and use in bp_remove_member_type().

Props Mamaduka.
Fixes #6188.

Note: See TracTickets for help on using tickets.