Ticket #6025: 6025.01-pre-5911.patch
| File 6025.01-pre-5911.patch, 4.5 KB (added by , 12 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 c83e743..fac208d 100644
function groups_send_invites( $user_id, $group_id ) { 1043 1043 do_action( 'groups_send_invites', $group_id, $invited_users ); 1044 1044 } 1045 1045 1046 /** 1047 * Send specific pending group invitations keyed by group and invitee id 1048 * 1049 * @param int $group_id ID of the group. 1050 * @param int $invitee_id ID of the invited user. 1051 * @param bool $resend Whether to resend notification email if already sent. 1052 * 1053 * @since BuddyPress (2.2.0) 1054 */ 1055 function groups_send_invite_by_invitee( $group_id, $invitee_id, $resend = false ) { 1056 1057 if ( empty( $group_id ) || empty( $invitee_id ) ) { 1058 return false; 1059 } 1060 1061 // Check that an invitation exists for this user/group combination. 1062 // $type = 'all' checks for sent or unsent invitations. 1063 if ( ! groups_check_user_has_invite( $invitee_id, $group_id, $type = 'all' ) ) { 1064 return false; 1065 } 1066 1067 $group = groups_get_group( array( 'group_id' => $group_id ) ); 1068 $member = new BP_Groups_Member( $invitee_id, $group_id ); 1069 1070 // Send the invitation email. 1071 groups_notification_group_invites( $group, $member, $member->inviter_id, $resend ); 1072 1073 $member->invite_sent = 1; 1074 $member->save(); 1075 1076 // Invoke the same action as groups_send_invites(). 1077 do_action( 'groups_send_invites', $group_id, array( $invitee_id ) ); 1078 } 1079 1046 1080 function groups_get_invites_for_group( $user_id, $group_id ) { 1047 1081 return BP_Groups_Group::get_invites( $user_id, $group_id ); 1048 1082 } -
src/bp-groups/bp-groups-notifications.php
diff --git src/bp-groups/bp-groups-notifications.php src/bp-groups/bp-groups-notifications.php index c4b1a48..a01dd91 100644
add_action( 'groups_promoted_member', 'groups_notification_promoted_member', 10, 296 296 * 297 297 * @since BuddyPress (1.0.0) 298 298 * 299 * @param BP_Groups_Group $group Group object. 300 * @param BP_Groups_Member $member Member object. 301 * @param int $inviter_user_id ID of the user who sent the invite. 302 * @return bool|null False on failure. 299 * @param BP_Groups_Group $group Group object. 300 * @param BP_Groups_Member $member Member object. 301 * @param int $inviter_user_id ID of the user who sent the invite. 302 * @param bool $resend Whether to resend notification email if already sent. 303 * @return bool|null False on failure. 303 304 */ 304 function groups_notification_group_invites( &$group, &$member, $inviter_user_id ) {305 function groups_notification_group_invites( &$group, &$member, $inviter_user_id, $resend = false ) { 305 306 306 // Bail if member has already been invited 307 if ( ! empty( $member->invite_sent ) ) {307 // Bail if member has already been invited, and $resend isn't specified. 308 if ( ! $resend && ! empty( $member->invite_sent ) ) { 308 309 return; 309 310 } 310 311 -
tests/phpunit/testcases/groups/class-bp-groups-member.php
diff --git tests/phpunit/testcases/groups/class-bp-groups-member.php tests/phpunit/testcases/groups/class-bp-groups-member.php index 7d1aad3..fb225f1 100644
class BP_Tests_BP_Groups_Member_TestCases extends BP_UnitTestCase { 12 12 parent::tearDown(); 13 13 } 14 14 15 public static function invite_user_to_group( $user_id, $group_id, $inviter_id ) {15 public static function invite_user_to_group( $user_id, $group_id, $inviter_id, $draft = false ) { 16 16 $invite = new BP_Groups_Member; 17 17 $invite->group_id = $group_id; 18 18 $invite->user_id = $user_id; 19 19 $invite->date_modified = bp_core_current_time(); 20 20 $invite->inviter_id = $inviter_id; 21 21 $invite->is_confirmed = 0; 22 $invite->invite_sent = 1;22 $invite->invite_sent = $draft ? 0 : 1; 23 23 24 24 $invite->save(); 25 25 return $invite->id; … … class BP_Tests_BP_Groups_Member_TestCases extends BP_UnitTestCase { 127 127 $ids = wp_list_pluck( $mm, 'user_id' ); 128 128 $this->assertEquals( array( $u2 ), $ids ); 129 129 } 130 131 public function test_groups_send_invite_by_invitee() { 132 $g1 = $this->factory->group->create(); 133 134 $u1 = $this->factory->user->create(); 135 $u2 = $this->factory->user->create(); 136 self::add_user_to_group( $u1, $g1 ); 137 138 // Create unsent invitation 139 self::invite_user_to_group( $u2, $g1, $u1, $draft = true ); 140 $this->assertTrue( is_null( groups_check_user_has_invite( $u2, $g1, $type = 'sent' ) ) ); 141 142 groups_send_invite_by_invitee( $g1, $u2 ); 143 144 $this->assertTrue( is_numeric( groups_check_user_has_invite( $u2, $g1, $type = 'sent' ) ) ); 145 146 } 130 147 } 131 148
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)