How to prevent user save loop in CP? I have a plugin that uses its init function to save custom user data from front end registrations. It uses:

 if ($event-&gt;params['isNewUser']) {}


and

if (craft()-&gt;request-&gt;isSiteRequest()) {}


To perform front end save routines.

I want to add a small  custom user save rule for admin usage outside of the IsNewUser logic in order to preserve like this:

 if (craft()-&gt;request-&gt;isCpRequest()) {
   $user = craft()-&gt;users-&gt;getUserById($uidfromURL);
   $user-&gt;getContent()-&gt;URN = 'my custom value';
   $success = craft()-&gt;users-&gt;saveUser($user);
 }


The problem is that this code just loops thru the plugin. I need the custom field to be manually editable, but i also need to create a default value too on initial user creation in admin.
I had a similar problem a while ago when a plugin listened for onSaveUser and then saved the user itself, causing an infinite loop. Someone provided me something like:

craft()-&gt;on('users.onSaveUser', function(Event $event) {
    static $recursionLevel = 0;
    if ($recursionLevel == 0) {
        $recursionLevel++;
        // do your stuff
    }
});