webhoes Posted June 18, 2018 Posted June 18, 2018 Hello, I am trying to make a hook in ready.php. A user can create a new page wich will be a child of his user template. I want to check the amout of children before adding a new page. If the count is more than 3 do a redirect. $wire->addHookBefore('Pages::add', function(HookEvent $event) { // Get the object the event occurred on, if needed $pages = $event->object; // Get values of arguments sent to hook (and optionally modify them) $template = $event->arguments(0); $parent = $event->arguments(1); $name = $event->arguments(2); $values = $event->arguments(3); /* Your code here, perhaps modifying arguments */ $userCount = wire('pages')->get($this->user)->children->count(); if($template == 'animal' && $userCount > 3) $session->redirect('/subscribe/'); //also implement check of user role user = max 3, paid-user is unlimited // Populate back arguments (if you have modified them) $event->arguments(0, $template); $event->arguments(1, $parent); $event->arguments(2, $name); $event->arguments(3, $values); }); I have this code, but it seems not to do anything.
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