Skip to:
Content

BuddyPress.org

Ticket #6597: 6597.groups_remove_member_tweaks.patch

File 6597.groups_remove_member_tweaks.patch, 3.1 KB (added by r-a-y, 9 years ago)
  • src/bp-groups/bp-groups-functions.php

    diff --git src/bp-groups/bp-groups-functions.php src/bp-groups/bp-groups-functions.php
    index a65f82d..2af2773 100644
    function groups_leave_group( $group_id, $user_id = 0 ) { 
    440440                }
    441441        }
    442442
    443         if ( ! groups_remove_member( $user_id, $group_id ) ) {
     443        if ( ! groups_remove_member( $user_id, $group_id, 'leave_group' ) ) {
    444444                return false;
    445445        }
    446446
    447447        bp_core_add_message( __( 'You successfully left the group.', 'buddypress' ) );
    448448
    449         /**
    450          * Fires after a user leaves a group.
    451          *
    452          * @since BuddyPress (1.0.0)
    453          *
    454          * @param int $group_id ID of the group.
    455          * @param int $user_id  ID of the user leaving the group.
    456          */
    457         do_action( 'groups_leave_group', $group_id, $user_id );
    458 
    459449        return true;
    460450}
    461451
    function groups_unban_member( $user_id, $group_id ) { 
    14271417/**
    14281418 * Remove a member from a group.
    14291419 *
    1430  * @param int $user_id  ID of the user.
    1431  * @param int $group_id ID of the group.
     1420 * @param int    $user_id  ID of the user.
     1421 * @param int    $group_id ID of the group.
     1422 * @param string $context  Optional. Context of removal. Default: 'remove'. If passed, this will fire
     1423 *                         a hook named after $context when a group member is removed succesfully.
    14321424 *
    14331425 * @return bool True on success, false on failure.
    14341426 */
    1435 function groups_remove_member( $user_id, $group_id ) {
     1427function groups_remove_member( $user_id, $group_id, $context = 'remove' ) {
    14361428
    14371429        if ( ! bp_is_item_admin() ) {
    14381430                // bp_is_item_admin may not be set if this function is called outside of group context.
    function groups_remove_member( $user_id, $group_id ) { 
    14471439
    14481440        $member = new BP_Groups_Member( $user_id, $group_id );
    14491441
    1450         /**
    1451          * Fires before the removal of a member from a group.
    1452          *
    1453          * @since BuddyPress (1.2.6)
    1454          *
    1455          * @param int $group_id ID of the group being removed from.
    1456          * @param int $user_id  ID of the user being removed.
    1457          */
    1458         do_action( 'groups_remove_member', $group_id, $user_id );
     1442        // Backward compatibility hook.
     1443        if ( 'remove' === $context ) {
     1444                /**
     1445                 * Fires before the removal of a member from a group.
     1446                 *
     1447                 * @todo We should deprecate this and direct devs to use the
     1448                 *       'groups_member_before_remove' hook instead.
     1449                 *
     1450                 * @since BuddyPress (1.2.6)
     1451                 *
     1452                 * @param int $group_id ID of the group being removed from.
     1453                 * @param int $user_id  ID of the user being removed.
     1454                 */
     1455                do_action( "groups_remove_member", $group_id, $user_id );
     1456
     1457        }
     1458
     1459        $retval = $member->remove();
     1460
     1461        if ( false !== $retval && ! empty( $context ) && 'remove' !== $context ) {
     1462                /**
     1463                 * Dynamic hook that fires after a group member is removed successfully.
     1464                 *
     1465                 * Hook name is derived from the $context parameter.
     1466                 *
     1467                 * @since 2.4.0
     1468                 *
     1469                 * @param int $group_id ID of the group being removed from.
     1470                 * @param int $user_id  ID of the user being removed.
     1471                 */
     1472                do_action( "groups_{$context}", $group_id, $user_id );
     1473
     1474        }
    14591475
    1460         return $member->remove();
     1476        return $retval;
    14611477}
    14621478
    14631479/** Group Membership **********************************************************/