1

Been digging for a solution but can’t seem to find one. My site has 2 registration forms (Form A and Form B) on separate pages that are working great. When users signup to Form B a hidden field called subscriber_type is populated. Otherwise Form A and B are identical. Once the forms are submitted a user should only be auto-activated and logged-in if this subscriber_type field is populated.

So far users filling out Form B are activated (and don’t get the activation email) and are logged in. But users filling out Form A aren’t getting their activation emails either even though they should. Looks like no users are getting any activation emails, regardless of the form they fill.

Is there any way to make sending of the activation emails conditional?

What I’ve tried so far:

// Auto-activate users from Form B (This works)
function auto_activate_user( $user_id ) {
    //Check if subscriber_type is in form POST (and is from Form B)
    $subscriber_type = $_POST['subscriber_type'];
    if ($subscriber_type){
        global $wpdb;

        //Hook if you want to do something before the activation
        do_action('bp_disable_activation_before_activation');

        $activation_key = get_user_meta($user_id, 'activation_key', true);
        $activate = apply_filters('bp_core_activate_account', bp_core_activate_signup($activation_key));
        BP_Signup::validate($activation_key);
        $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET user_status = 0 WHERE ID = %d", $user_id ) );

        //Add note on Activity Stream
        if ( function_exists( 'bp_activity_add' ) ) {
            $userlink = bp_core_get_userlink( $user_id );

            bp_activity_add( array(
                'user_id' => $user_id,
                'action' => apply_filters( 'bp_core_activity_registered_member', sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ), $user_id ),
                'component' => 'profile',
                'type' => 'new_member'
            ) );

        }
        //Send email to admin
        wp_new_user_notification( $user_id );

        // Remove the activation key meta
        delete_user_meta( $user_id, 'activation_key' );

        // Delete the total member cache
        wp_cache_delete( 'bp_total_member_count', 'bp' );

        //Hook if you want to do something before the login
        do_action('bp_disable_activation_before_login');

        //Automatically log the user in .
        $user_info = get_userdata($user_id);
        wp_set_auth_cookie($user_id);

        do_action('wp_signon', $user_info->user_login);

        //Hook if you want to do something after the login
        do_action('bp_disable_activation_after_login');

    }
}

// Fix validation on Form B (This doesn't work - doesn't disable emails)
function fix_signup_form_validation_text() {
    //Check if subscriber_type is in form POST (and is from Form B)
    $subscriber_type = $_POST['subscriber_type'];
    if ($subscriber_type){
        return false;
    }
}

// Disable activation email only for Form B (This doesn't work - disables emails for all users)
function disable_activation_email() {
    //Check if subscriber_type is in form POST (and is from Form B)
    $subscriber_type = $_POST['subscriber_type'];
    if ($subscriber_type){
        return false;
    }
}

add_action( 'bp_core_signup_user', 'auto_activate_user');
add_filter( 'bp_registration_needs_activation', 'fix_signup_form_validation_text');
add_filter( 'bp_core_signup_send_activation_key', 'disable_activation_email');

Update: After some more digging I've confirmed the following:

  • bp_registration_needs_activation isn't the correct filter to use as it is not called during the user registration process.
  • adding the bp_core_signup_send_activation_key filter disables all activation emails regardless of the function it calls as the second argument.
Murada
  • 25
  • 2
  • 5
  • I'm confused by `$subscriber_type || $subscriber_type === 'current_subscriber'`. This will be `true` if `$subscriber_type` is set to **any value at all** apart from an empty string (or if it is 'current_subscriber', although the second part is redundant). Is this the intended behaviour? – Matt Raines May 31 '16 at 01:18
  • @MattRaines sorry about that. it was an earlier test I forgot to remove. I've updated it to just check if `$subscriber_type` has any value (I'm not checking for specific value at this point). – Murada May 31 '16 at 01:27

0 Answers0