[buddypress-trac] [BuddyPress Trac] #7397: groups_send_invites() should allow us to omit sending to users that have already received an invite

buddypress-trac noreply at wordpress.org
Tue Dec 20 02:44:03 UTC 2016


#7397: groups_send_invites() should allow us to omit sending to users that have
already received an invite
-------------------------+------------------------------
 Reporter:  r-a-y        |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Groups       |     Version:
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |
-------------------------+------------------------------

Comment (by boonebgorges):

 Thanks for opening this ticket, @r-a-y.

 Under what circumstances would one want `$omit_sent = false`? I assume you
 added this param to maintain compatibility with the current behavior. But
 the current behavior may not be worth preserving. Here's what happens in
 the loop:

 {{{
         for ( $i = 0, $count = count( $invited_users ); $i < $count; ++$i
 ) {
                 $member = new BP_Groups_Member( $invited_users[$i],
 $group_id );

                 // Send the actual invite.
                 groups_notification_group_invites( $group, $member,
 $user_id );

                 $member->invite_sent = 1;
                 $member->save();
         }
 }}}

 Members with `invite_sent=1` will be passed to
 `groups_notification_group_invites()`, but that function bails immediately
 for memberships with `invite_sent=1`. Setting `$member->invite_sent = 1`
 obviously does nothing. So the only things that actually happen for these
 members is that (a) the `BP_Group_Member::save()` hooks fire, and (b) the
 already-invited users are passed to the `groups_send_invites` filter.

 What if we simply do something like this:

 {{{
         for ( $i = 0, $count = count( $invited_users ); $i < $count; ++$i
 ) {
                 $member = new BP_Groups_Member( $invited_users[$i],
 $group_id );

                 if ( $member->invite_sent ) {
                     continue;
                 }

                 // ...
         }
 }}}

 This preserves behavior (b) (the values passed to the filter). It changes
 (a), but (a) is sorta semantically incorrect anyway - no change has been
 made, so why fire the `save` actions? - and it's hard to imagine any real-
 world compatibility breaks.

 What do you think?

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/7397#comment:2>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list