Jump to content

Delete user on logout


netcarver
 Share

Recommended Posts

I'm sure this should be pretty easy on PW - but is it possible to delete a user when they logout? Essentially, I have a bunch of ephemeral users I use for testing, once I log out as that user, I want them to disappear from PW.

I've tried hooking before/after Session::logoutSuccess, and also just processing the ?logout=1 directly in a template file.

Not feeling particularly bright at the moment.

Link to comment
Share on other sites

Works fine for me. In ready.php

$this->addHookAfter('Session::logoutSuccess', function(HookEvent $event) {
	$user = $event->arguments(0);
	// here, your condition for getting transitory user
	if($user->id>1025){
		// just to confirm
		wire('log')->save('logged_out',$user->name);
		// delete the user
		wire('users')->delete($user);
	}
});

ProcessWire 3.0.159

Edited by kongondo
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...