Skip to:

Conditional Send User Auto-Activation after Register?

  • cahara


    Hey all,

    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 ) {
        $subscriber_type = $_POST['subscriber_type'];
        if ($subscriber_type || $subscriber_type === 'current_subscriber'){
            global $wpdb;
            //Hook if you want to do something before the activation
            $activation_key = get_user_meta($user_id, 'activation_key', true);
            $activate = apply_filters('bp_core_activate_account', bp_core_activate_signup($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
            //Automatically log the user in	.
            $user_info = get_userdata($user_id);
            do_action('wp_signon', $user_info->user_login);
            //Hook if you want to do something after the login
    // Fix validation on Form B (This works)
    function fix_signup_form_validation_text() {
        $subscriber_type = $_POST['subscriber_type'];
        if ($subscriber_type || $subscriber_type === 'current_subscriber'){
            return false;
    // Disable autivation email only for Form B (This doesn't work)
    function disable_activation_email() {
        $subscriber_type = $_POST['subscriber_type'];
        if ($subscriber_type || $subscriber_type === 'current_subscriber'){
            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');
  • You must be logged in to reply to this topic.
Skip to toolbar