Skip to:
Content
Pages
Categories
Search
Top
Bottom

difficulties with bypass activation and auto-login

  • Avatar of terraling
    terraling
    Participant

    @terraling

    I swear this was working until very recently and I just noticed it no longer is and can’t work out why…

    I use a customised registration form.

    In my functions.php I have

    add_filter( 'bp_core_signup_send_activation_key', '__return_false' );

    and

    add_action( 'bp_core_signup_user', 'my_user_signup', 5, 3 );
    function my_user_signup( $user_id, $user_login, $user_password ) {
      global $wpdb;
    
      // WE SKIP BP ACTIVATION EMAIL, SO LET'S INCLUDE STEPS FROM bp_core_activate_signup HERE
        // Tell admin we have a new user
        wp_new_user_notification( $user_id );
        // Activate user
        $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_status = 0 WHERE ID = %d", $user_id ) );
        // Remove the activation key meta
        delete_user_meta( $user_id, 'activation_key' );
    
      // ...Bunch of other stuff to do with populating extra profile fields...
    
      // Now sign them on
      $signon = wp_signon( array('user_login' => $user_login, 'user_password' => $user_password, 'remember' => false) );
    
      //Redirect
      if ( is_wp_error($signon) ) {
        error_log( "auto-login error for user " . $user_id . " : " . $signon->get_error_message() );
      }
      else {
        wp_redirect( home_url('some-page') );
        exit;
      }
    

    Now, in every case, it is logging the error “Your account has not been activated. Check your email for the activation link” and so failing to log them in and redirect.

    Any ideas?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Avatar of henrywright
    henrywright
    Participant

    @henrywright

    Hi @terraling

    Could it be anything to do with the customisations you made to the registration process recently?

    Avatar of terraling
    terraling
    Participant

    @terraling

    Hmmm – it would seem so.

    Don’t know why but hooking onto the bp_screens action seems to have broken it, somehow, so I’ll need to rethink that, perhaps ask for a more appropriate hook to be added to core after all.

    Thanks @henrywright for the nudge.

    Avatar of terraling
    terraling
    Participant

    @terraling

    Okay, scratch that, it’s not working… I stripped out what I’d been tinkering with before.

    Here’s the problem:

    
    global $wpdb;
    // Activate user
    $wpdb->query('UPDATE wp_users SET user_status = 0 WHERE ID = '.$user_id);
    // Remove the activation key meta
    delete_user_meta( $user_id, 'activation_key' );
    //TESTING
    $user = get_user_by( 'id', $user_id );
    error_log("user id " . $user_id . " has status = " . $user->user_status);
    
    $signon = wp_signon( array('user_login' => $user_login, 'user_password' => $user_password, 'remember' => false) );
    

    So the signon fails because my error_log says
    user id 106 has status = 2
    even though it has just been set to 0 and, if I look directly in the wp_users table I see that it is indeed 0.

    I can only assume that the sql query to write user_status is slow and when I manually inspect it it has changed, but when the code checks it it is still set to 2.

    Does that sound plausible? Or am I missing something?

    Avatar of terraling
    terraling
    Participant

    @terraling

    Of course, I could just

    remove_filter( 'authenticate', 'bp_core_signup_disable_inactive', 30 );

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.