We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36760
    • 136 Posts
    I was trying to get a plugin to run OnUserAddToGroup, and consequently OnUserBeforeAddToGroup after the first method didn't work, but neither seem to be working. Several other threads don't offer any alternatives: https://github.com/modxcms/revolution/issues/8317, http://forums.modx.com/thread/78146/onuseraddtogroup-not-working, etc.

    I'm running Revolution 2.3.3 and was wondering if there are any alternatives to getting a plugin to run when the user is (successfully) added to a group?

    Right now my plugin is just this:

    $modx->log(modX::LOG_LEVEL_ERROR,'[moveActiveUser] User added to group');


    Which shows the message in the log if I make it run on another event like OnUserActivate.

    I appreciate the help!
      • 3749
      • 24,544 Posts
      How is the user being added to the group?
        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
        • 36760
        • 136 Posts
        Finally getting back around to this.

        I was adding the user under the Access Permissions tab from their profile in the manager area. I made sure to save the user after adding them to a goup.
          • 3749
          • 24,544 Posts
          I don't see that being called by the user panel. See if adding the user on the Settings -> Access Control Lists -> User Groups tab works. I doubt if it will work.

          I think that event is for future use. I could be wrong.

          I think adding this code at the end of the modUser class joinGroup function would do it (just above the 'return $joined;' line around line 701):

          if ($joined) {
              /* invoke OnUserAddToGroup event */
              $modx->invokeEvent('OnUserAddToGroup',array(
                 'user' => &$this,
                 'usergroup' => &$userGroup,
                 'membership' => &$member,
              ));
          }
          


          Of course it's very much *not* recommended to hack the core code and it would be overwritten when you upgrade MODX.

          A safer solution would be a plugin attached to OnBeforeUserFormSave and OnUserFormSave that checked to see if the user was added to any new groups, and performed your operations in that case. It would be very tricky, though.

          I think you'd have to get the user's groups in OnBeforeUserFormSave, save them to a $_SESSION variable, then get them again in OnUserFormSave and compare them to the ones in the $_SESSION variable, then unset the $_SESSION variable. I'm not sure it would work.
            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