We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5340
    • 1,624 Posts
    HI,

    I want to know if it’s possible to attach some code to the OnManagerDeleteUser event, without hacking the core.

    I created my own custom web user registration using eform and I’m using a custom table for custom user information. When a web user is deleted(inside manager) I want to delete all the references from the other tables.

    Thank you


    solution

    //<?php
    
    $e = &$modx->Event;
    
    switch($e->name) {
    	
    	case 'OnWebDeleteUser':
    		
    		//delete extended user information
    		$modx->db->delete($modx->getFullTableName('web_user_attributes_extended'), "internalKey = $userid");
    		
    	break;
    
      	default:
      		$modx->logEvent(5, 3, 'Delete Web User Extended Attributes', 'Possible error when deleting this user: ' . $userid);
        return;
        break;
    }
      • 3749
      • 24,544 Posts
      A plugin attached to OnManagerDeleteUser should work fine for you. The event fires just after the user has been deleted from the DB.

      These three variables should be automatically set and available to you for use in the plugin:

      $user (user object)
      $userid
      $username

      [Update] I was assuming that you’re using Revolution -- hope that’s right -- the $user object might not be available in Evo.
        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
        • 5340
        • 1,624 Posts
        I need it for evo

        I’m not sure which event is triggered when a web user is deleted

        I have this so far but it’s not working:

        $e = & $modx->Event;
        
        switch ($e->name) {
        	
        	case "OnManagerDeleteUser":
        		$modx->logEvent(5, 3, 'Deleted web User', 'User OnManagerDeleteUser: ' . $userid);
        	break;
        	case "OnWUsrFormDelete":
        		$modx->logEvent(5, 3, 'Deleted web User', 'User OnWUsrFormDelete: ' . $userid);
        	break;
        		
        }


        I’ll test some more
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          OnManagerDeleteUser is for when a Manager user is deleted. You want OnWebDeleteUser, which will give you the $user and $username values.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 5340
            • 1,624 Posts
            Thanks,

            It seems that OnWUsrFormDelete is fired as well after OnWebDeleteUser. I’ll use OnWebDeleteUser for now.
              • 5340
              • 1,624 Posts
              I guess this explains the OnWUsrFormDelete


              } else {
              	// invoke OnWebDeleteUser event
              	$modx->invokeEvent("OnWebDeleteUser",
              						array(
              							"userid"		=> $id,
              							"username"		=> $username
              						));
              
              	// invoke OnWUsrFormDelete event
              	$modx->invokeEvent("OnWUsrFormDelete",
              						array(
              							"id"	=> $id
              						));
              
              	$header="Location: index.php?a=99";
              	header($header);
              }
              



              taken from delete_web_user.processor.php

              Thanks for all your help!