How to identify the logged in user inside a plugin? I have a public registration form and a plugin which needs to create an entry for a user when that user is activated. That part works. Because I want to force an Admin to activate the user, I am using this code block to stop Craft automatically activating a user on registration:

public function init() {
    craft()-&gt;on('users.beforeActivateUser', function(Event $event){
        // stop the user from being able to activate their account. Forces admins to do so.
        $event-&gt;performAction = false;
    });
}


But this also stops an Admin from activating the user account via the control panel.

I can't work out how to test that the user performing the event is the admin and therefore skip that blocking code. I'd tried this:

public function init() {
    craft()-&gt;on('users.beforeActivateUser', function(Event $event){
        // stop the user from being able to activate their account. Forces admins to do so.
        if($event-&gt;params['user']-&gt;isInGroup('artists')){
            $event-&gt;performAction = false;
        }
    });
}


But that doesn't work, presumably because a new registering user doesn't belong to any group at the point that code is run.
I'm a bit confused by your question.

It sounds as though you want to check if the currently logged-in user is an Administrator, but it looks like you're actually checking whether the newly-registered user is an Administrator.

Here's how to retrieve the currently logged-in User, and check whether they belong to a specific User Group.

function (Event $event)
{
    $user = craft()-&gt;userSession-&gt;getUser();

    if ($user &amp;&amp; $user-&gt;isInGroup('groupHandle') {
        // Do stuff.
    }
}


Alternatively, you could check whether the current user has permission to perform a specific action:

if ($user &amp;&amp; craft()-&gt;userPermissions-&gt;doesUserHavePermission($user-&gt;id, 'registerUsers')) {
    // Do stuff.
}