Skip to:
Content

BuddyPress.org

Ticket #8693: 8693.1.diff

File 8693.1.diff, 1.7 KB (added by dcavins, 2 years ago)

SIte invitations: Do not assume that a user exists. a651ce5f5 In some BuddyPress setups, a user is not created until the signup has been activated. This is the case when BP_SIGNUPS_SKIP_USER_CREATION is set to true and when installed on a WodPress network. So we rely on the BP_Signup instead of the dodgy user in bp_members_invitations_complete_signup().

  • src/bp-members/bp-members-invitations.php

    diff --git src/bp-members/bp-members-invitations.php src/bp-members/bp-members-invitations.php
    index 2fadc0e94..0ad23999e 100644
    add_filter( 'bp_core_signup_send_activation_key', 'bp_members_invitations_cancel 
    105105function bp_members_invitations_complete_signup( $user_id ) {
    106106        $bp = buddypress();
    107107
    108         if ( ! $user_id ) {
    109                 return;
    110         }
    111 
    112108        // Check to see if this signup is the result of a valid invitation.
    113109        $invite = bp_get_members_invitation_from_request();
    114110        if ( ! $invite->id ) {
    115111                return;
    116112        }
    117113
    118         // Accept the invitation.
    119         $invites_class = new BP_Members_Invitation_Manager();
    120         $args          = array(
    121                 'id' => $invite->id,
    122         );
    123         $invites_class->accept_invitation( $args );
    124 
    125114        // User has already verified their email by responding to the invitation, so we can activate.
    126         $key = bp_get_user_meta( $user_id, 'activation_key', true );
     115        $signup = bp_members_get_signup_by( 'user_email', $invite->invitee_email );
     116        $key = false;
     117        if ( ! empty( $signup->activation_key ) ) {
     118                $key = $signup->activation_key;
     119        }
     120
    127121        if ( $key ) {
    128122                $redirect = bp_get_activation_page();
    129123
    function bp_members_invitations_complete_signup( $user_id ) { 
    137131                 */
    138132                $user = apply_filters( 'bp_core_activate_account', bp_core_activate_signup( $key ) );
    139133
     134                // Accept the invitation now that the user has been created.
     135                $invites_class = new BP_Members_Invitation_Manager();
     136                $args          = array(
     137                        'id' => $invite->id,
     138                );
     139                $invites_class->accept_invitation( $args );
     140
    140141                // If there were errors, add a message and redirect.
    141142                if ( ! empty( $user->errors ) ) {
    142143                        /**