We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Unless you’ve modified the invokeEvent() call, $user is the only thing passed:

    $modx->invokeEvent('OnUserActivate',array(
        'user' => &$user,
    ));
      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
      • 6057
      • 26 Posts
      Hi,

      I've just been trying to use the OnUserActivate generated by the Login.ConfirmRegister snippet. I eventually got it working. I wanted to check that what I've ended up with is correct/safe.

      Here's the code for my plugin (which only registered against OnUserActivate):

      <?php
      $modx->getService('mail', 'mail.modPHPMailer');
      $modx->mail->set(modMail::MAIL_BODY,'User '.$user->_fields['username'].' has clicked on the activation link sent to them via email.'.$msg);
      $modx->mail->set(modMail::MAIL_FROM,$modx->getOption('emailsender'));
      $modx->mail->set(modMail::MAIL_FROM_NAME,'######');
      $modx->mail->set(modMail::MAIL_SUBJECT,'User has confirmed their email address.');
      $modx->mail->address('to','######');
      if (!$modx->mail->send()) {
      $modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
      }
      $modx->mail->reset();
      return;

      The part that was tricky to work out was that the $user object is not a modUser but a modUser_mysql object. Once I knew that I could get the username.

      I'm a bit concerned that this code is working directly on the xPDO db object. Is that ok?

      Note: I've used MODx Evo for several years but have just switched to Revo for a new project.

      System:
      MODx Revo 2.2.14-pl
      Login 1.8.1-pl
        • 3749
        • 24,544 Posts
        It looks fine to me.
          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