Ticket #6025: 6025.01-post-5911.patch
| File 6025.01-post-5911.patch, 4.6 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 330b5ca..5afe41f 100644
function groups_send_invites( $user_id, $group_id ) { 1057 1057 do_action( 'groups_send_invites', $group_id, $invited_users ); 1058 1058 } 1059 1059 1060 /** 1061 * Send specific pending group invitations keyed by group, invitee and inviter id 1062 * 1063 * @param int $group_id ID of the group. 1064 * @param int $invitee_id ID of the invited user. 1065 * @param int $inviter_id ID of the user who created the invitation. 1066 * @param bool $resend Whether to resend notification email if already sent. 1067 * 1068 * @since BuddyPress (2.2.0) 1069 */ 1070 function groups_send_invite_by_invitee( $group_id, $invitee_id, $inviter_id, $resend = false ) { 1071 1072 if ( empty( $group_id ) || empty( $invitee_id ) || empty( $inviter_id ) ) { 1073 return false; 1074 } 1075 1076 // Check that an invitation exists for this invitee/group/inviter combination. 1077 // $type = 'all' checks for sent or unsent invitations. 1078 if ( ! groups_check_user_has_invite( $invitee_id, $group_id, $type = 'all', $inviter_id ) ) { 1079 return false; 1080 } 1081 1082 $group = groups_get_group( array( 'group_id' => $group_id ) ); 1083 $member = new BP_Groups_Member( $invitee_id, $group_id ); 1084 1085 // Send the invitation email. 1086 groups_notification_group_invites( $group, $member, $inviter_id, $resend ); 1087 1088 $member->invite_sent = 1; 1089 $member->save(); 1090 1091 // Invoke the same action as groups_send_invites(). 1092 do_action( 'groups_send_invites', $group_id, array( $invitee_id ) ); 1093 } 1094 1060 1095 function groups_get_invites_for_group( $user_id, $group_id ) { 1061 1096 return BP_Groups_Group::get_invites( $user_id, $group_id ); 1062 1097 } -
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..7407587 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', $u1 ) ) ); 141 142 groups_send_invite_by_invitee( $g1, $u2, $u1 ); 143 144 $this->assertTrue( is_numeric( groups_check_user_has_invite( $u2, $g1, $type = 'sent', $u1 ) ) ); 145 146 } 130 147 } 131 148
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)