groups_accept_invite( int $user_id, int $group_id )
Process the acceptance of a group invitation.
Description
Returns true if a user is already a member of the group.
Parameters
- $user_id
-
(Required) ID of the user.
- $group_id
-
(Required) ID of the group.
Return
(bool) True when the user is a member of the group, otherwise false.
Source
File: bp-groups/bp-groups-functions.php
1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 | function groups_accept_invite( $user_id , $group_id ) { // If the user is already a member (because BP at one point allowed two invitations to // slip through), delete all existing invitations/requests and return true. if ( groups_is_user_member( $user_id , $group_id ) ) { if ( groups_check_user_has_invite( $user_id , $group_id ) ) { groups_delete_invite( $user_id , $group_id ); } if ( groups_check_for_membership_request( $user_id , $group_id ) ) { groups_delete_membership_request( null, $user_id , $group_id ); } return true; } $member = new BP_Groups_Member( $user_id , $group_id ); // Save the inviter ID so that we can pass it to the action below. $inviter_id = $member ->inviter_id; $member ->accept_invite(); if ( ! $member ->save() ) { return false; } // Remove request to join. if ( $member ->check_for_membership_request( $user_id , $group_id ) ) { $member ->delete_request( $user_id , $group_id ); } // Modify group meta. groups_update_groupmeta( $group_id , 'last_activity' , bp_core_current_time() ); /** * Fires after a user has accepted a group invite. * * @since BuddyPress 1.0.0 * @since BuddyPress 2.8.0 The $inviter_id arg was added. * * @param int $user_id ID of the user who accepted the group invite. * @param int $group_id ID of the group being accepted to. * @param int $inviter_id ID of the user who invited this user to the group. */ do_action( 'groups_accept_invite' , $user_id , $group_id , $inviter_id ); return true; } |
Changelog
Version | Description |
---|---|
BuddyPress 1.0.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.