title: WordPress Auto Login After Custom Registration
body: <p>I have a custom WP registration script that works nicely, although I can't get it to automatically login the user. I can confirm that it creates the user profile. I've also tried triggering wp_signon() with no luck. Any suggestions?</p>
  
  <pre><code>&lt;?php
  function complete_registration() {
      global $reg_errors, $username, $password, $email;
      if ( 1 &gt; count( $reg_errors-&gt;get_error_messages() ) ) {
          $data = array(
              'user_login'    =&gt;   $username,
              'user_email'    =&gt;   $email,
              'user_pass'     =&gt;   $password
          );
          $user = wp_insert_user( $data );
  
          if(!is_wp_error($user))
              wp_set_current_user($user);
              wp_set_auth_cookie($user);
      }
  }
  ?&gt;
  </code></pre>