/** * Create a group membership request. * * @param int $requesting_user_id ID of the user requesting membership. * @param int $group_id ID of the group. * * @return bool True on success, false on failure. */ function groups_send_membership_request($requesting_user_id, $group_id) { // Prevent duplicate requests if (groups_check_for_membership_request($requesting_user_id, $group_id)) { return false; } // Check if the user is already a member or is banned if (groups_is_user_member($requesting_user_id, $group_id) || groups_is_user_banned($requesting_user_id, $group_id)) { return false; } // Check if the user is already invited - if so, simply accept invite if (groups_check_user_has_invite($requesting_user_id, $group_id)) { groups_accept_invite($requesting_user_id, $group_id); return true; } $requesting_user = new BP_Groups_Member(); $requesting_user->group_id = $group_id; $requesting_user->user_id = $requesting_user_id; $requesting_user->inviter_id = 0; $requesting_user->is_admin = 0; $requesting_user->user_title = ''; $requesting_user->date_modified = bp_core_current_time(); $requesting_user->is_confirmed = 0; $requesting_user->comments = isset($_POST['group-request-membership-comments']) ? $_POST['group-request-membership-comments'] : ''; if ($requesting_user->save()) { $admins = groups_get_group_admins($group_id); // Saved okay, now send the email notification for ($i = 0, $count = count($admins); $i < $count; ++$i) { groups_notification_new_membership_request($requesting_user_id, $admins[$i]->user_id, $group_id, $requesting_user->id); } /** * Fires after the creation of a new membership request. * * @since 1.0.0 * * @param int $requesting_user_id ID of the user requesting membership. * @param array $admins Array of group admins. * @param int $group_id ID of the group being requested to. * @param int $requesting_user->id ID of the user requesting membership. */ do_action('groups_membership_requested', $requesting_user_id, $admins, $group_id, $requesting_user->id); return true; } return false; }
function groups_send_membership_request( $requesting_user_id, $group_id ) { global $bp; /* Prevent duplicate requests */ if ( groups_check_for_membership_request( $requesting_user_id, $group_id ) ) return false; /* Check if the user is already a member or is banned */ if ( groups_is_user_member( $requesting_user_id, $group_id ) || groups_is_user_banned( $requesting_user_id, $group_id ) ) return false; $requesting_user = new BP_Groups_Member; $requesting_user->group_id = $group_id; $requesting_user->user_id = $requesting_user_id; $requesting_user->inviter_id = 0; $requesting_user->is_admin = 0; $requesting_user->user_title = ''; $requesting_user->date_modified = gmdate( "Y-m-d H:i:s" ); $requesting_user->is_confirmed = 0; $requesting_user->comments = $_POST['group-request-membership-comments']; if ( $requesting_user->save() ) { $admins = groups_get_group_admins( $group_id ); require_once ( BP_PLUGIN_DIR . '/bp-groups/bp-groups-notifications.php' ); for ( $i = 0; $i < count( $admins ); $i++ ) { // Saved okay, now send the email notification groups_notification_new_membership_request( $requesting_user_id, $admins[$i]->user_id, $group_id, $requesting_user->id ); } do_action( 'groups_membership_requested', $requesting_user_id, $admins, $group_id, $requesting_user->id ); return true; } return false; }
function groups_send_membership_request($requesting_user_id, $group_id) { // Prevent duplicate requests if (groups_check_for_membership_request($requesting_user_id, $group_id)) { return false; } // Check if the user is already a member or is banned if (groups_is_user_member($requesting_user_id, $group_id) || groups_is_user_banned($requesting_user_id, $group_id)) { return false; } $requesting_user = new BP_Groups_Member(); $requesting_user->group_id = $group_id; $requesting_user->user_id = $requesting_user_id; $requesting_user->inviter_id = 0; $requesting_user->is_admin = 0; $requesting_user->user_title = ''; $requesting_user->date_modified = bp_core_current_time(); $requesting_user->is_confirmed = 0; $requesting_user->comments = isset($_POST['group-request-membership-comments']) ? $_POST['group-request-membership-comments'] : ''; if ($requesting_user->save()) { $admins = groups_get_group_admins($group_id); // Saved okay, now send the email notification for ($i = 0, $count = count($admins); $i < $count; ++$i) { groups_notification_new_membership_request($requesting_user_id, $admins[$i]->user_id, $group_id, $requesting_user->id); } do_action('groups_membership_requested', $requesting_user_id, $admins, $group_id, $requesting_user->id); return true; } return false; }
function groups_send_membership_request($requesting_user_id, $group_id) { global $bp; /* Check the nonce first. */ if (!check_admin_referer('groups_request_membership')) { return false; } $requesting_user = new BP_Groups_Member(); $requesting_user->group_id = $group_id; $requesting_user->user_id = $requesting_user_id; $requesting_user->inviter_id = 0; $requesting_user->is_admin = 0; $requesting_user->user_title = ''; $requesting_user->date_modified = time(); $requesting_user->is_confirmed = 0; $requesting_user->comments = $_POST['group-request-membership-comments']; if ($requesting_user->save()) { $admins = groups_get_group_admins($group_id); require_once BP_PLUGIN_DIR . '/bp-groups/bp-groups-notifications.php'; for ($i = 0; $i < count($admins); $i++) { // Saved okay, now send the email notification groups_notification_new_membership_request($requesting_user_id, $admins[$i]->user_id, $group_id, $requesting_user->id); } do_action('groups_membership_requested', $requesting_user_id, $admins, $group_id, $requesting_user->id); return true; } return false; }