We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44969
    • 16 Posts
    Hello everyone,

    Using version 2.5.2 here. I'm trying to write a simple plugin to listen for a few system events and take some action when they occur. The main two events I want to listen for are when a new user is created (by any method) and when a user is deleted (by any method).

    One event that is successfully triggered when I delete a user from the manager is "OnUserFormDelete". When I look at the docs for this event, it mentions two event parameters. (I assume this means return parameters.)

    https://docs.modx.com/revolution/2.x/developing-in-modx/basic-development/plugins/system-events/onuserformdelete

    The two parameters are:

    user - A reference to the modUser object.
    id - The ID of the user.

    I want to get the id of the user that was just deleted. How can I access this value in my plugin?

    I also want to get the same value when a new user is activated. I would expect the "OnUserActivate" event to be triggered when this happens, and for it to provide the new user's id to listeners. Is this the event I should listen for? And how can I access the user id for this one?

    Thanks for any help anyone can provide!
      • 44969
      • 16 Posts
      Update: it looks like I can just reference it when OnUserFormDelete is fired with $id.

      However, the "OnUserActivate" event doesn't seem to fire when a new user is created, whether in the manager or by another plugin (hybridauth).
        • 3749
        • 24,544 Posts
        I think you're right about OnUserActivate. When I created the ActivationEmail plugin, I had to resort to checking the user's active status in the DB in OnUserBeforeSave, then checking it against the value in the user object to see if the user was going from inactive to active.

        You can look at the code here: https://github.com/BobRay/ActivationEmail/blob/master/core/components/activationemail/elements/plugins/activationemail.plugin.php
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 44969
          • 16 Posts
          Quote from: BobRay at Jan 12, 2017, 08:25 AM
          I think you're right about OnUserActivate. When I created the ActivationEmail plugin, I had to resort to checking the user's active status in the DB in OnUserBeforeSave, then checking it against the value in the user object to see if the user was going from inactive to active.

          You can look at the code here: https://github.com/BobRay/ActivationEmail/blob/master/core/components/activationemail/elements/plugins/activationemail.plugin.php

          Thanks Bob. I'll have to code around it as you did, it seems. Should it be reported as a bug? If so, what's the best way to do that?
            • 3749
            • 24,544 Posts
            I thought I had reported it, but maybe not. I couldn't find it.


            I was just looking at the code and the fix would be somewhat tricky.

            The logical place for it, imo, is in the save() function of the modUser object. It would involve code like I suggested above to check the DB, and would fire both OnBeforeUserActivate and OnUserActivate. But then the confirmRegister snippet in the Login extra would have to be modified to remove the invocation. Until people updated the Login package, for example, whatever happened in a plugin tied to OnUserActivate would execute twice.

            My ActivationEmail extra, and perhaps other extras, would also have to be modified.

            Another place for it would be the user/create processor, but then it wouldn't be invoked by lots of code that calls save() directly when creating a user instead of using the processor, so I think that's off the table.

            Besides confirmRegister, the only place I could find where that event is invoked is in the activatemultiple processor, so the invocation would have to be removed there as well, but that processor uses the response to determine whether the user can be activated or not. I don't think that code is used by anyone, but I could be wrong.


            You can report it here:

            https://github.com/modxcms/revolution/issues


              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting