Storing variables in a plugin This is a super basic question...

I've got a plugin that watches two events, in one event it creates a user. After another event I want it to activate that user.

How do I get/store/pass the id of the newly created user from the first event to the second?

public function init()
{
    craft()-&gt;on('thing.beforeEvent', function(Event $event){
        // Save the new user if they're not already a user
        if(!craft()-&gt;userSession-&gt;getUser()){
            $newUser = new UserModel;

            $newUser-&gt;firstName = craft()-&gt;request-&gt;getPost('firstName');
            $newUser-&gt;lastName  = craft()-&gt;request-&gt;getPost('lastName');
            $newUser-&gt;username  = craft()-&gt;request-&gt;getPost('username');
            $newUser-&gt;email     = craft()-&gt;request-&gt;getPost('email');
            $newUser-&gt;password  = craft()-&gt;request-&gt;getPost('password');

            $newUserSuccess = craft()-&gt;users-&gt;saveUser($newUser);
            if (!$newUserSuccess)
            {
                Craft::log('Couldn’t save the new user', LogLevel::Error);
            }
        }
    });

    craft()-&gt;on('thing.afterEvent', function(Event $event){
        // Activate the new user if they're not already a user
        //if(!craft()-&gt;userSession-&gt;getUser()){
        //  craft()-&gt;users-&gt;activateUser();
        //}
    });
}
Declare a private variable inside your class, private $userId = NULL

After you've saved the user in the first method, update the variable $this-&gt;userId = $user-&gt;id

In the second method grab the user by using the variable $user = craft()-&gt;users-&gt;getUserById($this-&gt;userId);

I haven't actually tested the code, but it might do the trick :)

EDIT: You might want to make a null-check before attempting to fetch the user, to ensure that it doesn't break if it tries to run it while the variable is still NULL