DrQuincy Posted February 20 Share Posted February 20 (edited) I have a default front-end user field call approved that is a true|false switch. I want to redirect them to a URL is not yet manually approved. I have this hook in $config->prependTemplateFile file. wire()->addHookBefore('Users::login', function($event) { $user = $event->arguments[0]; $user->of(true); if($user->approved === false) { // Prevent login $event->return = false; wire('session')->redirect('/account/?approved=0'); } }); But it does not fire. Do I have the hook wrong or is it in the wrong place? The file itself is definitely being included and if I replace the contents of the hook to a simple exit statement, still nothing happens. EDIT: I am using LoginRegisterPro, are the hooks different? Edited February 20 by DrQuincy Link to comment Share on other sites More sharing options...
bernhard Posted February 20 Share Posted February 20 This might be helpful: On 12/27/2024 at 4:47 PM, bernhard said: Ever wondered when certain hooks get executed? Which hooks got fired along the request? Or need to debug why your hook does not fire as expected? Expand 1 Link to comment Share on other sites More sharing options...
DrQuincy Posted February 21 Author Share Posted February 21 (edited) That's great, thanks, I'm definitely going to try that. 🙂 I do want to know why the User hooks aren't firing but in case anyone is using LRP and wondering the same, I have made what I need to do work with the following hooks: LoginRegisterPro::createdUser: use this to send an admin email to let the site owner know that a new user has registered LoginRegisterProLogin::success: used to set approved=0 on $user More info here: https://processwire.com/store/login-register-pro/docs/#hooks Edited February 21 by DrQuincy Link to comment Share on other sites More sharing options...
DrQuincy Posted February 21 Author Share Posted February 21 @bernhard Thanks for your massively helpful debug code. I can see now that the Users::* hooks apply to managing users in the back-end so it was never going to work with LRP — the LRP-specific ones are what I needed. 1 Link to comment Share on other sites More sharing options...
fliwire Posted February 21 Share Posted February 21 try $session->login() method - ProcessWire API Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now