Jump to content

Add function to hook


eydun
 Share

Recommended Posts

I have this code in ready.php:

<?php namespace ProcessWire;

$this->addHookAfter('ProcessPageEdit::processInput', $this, 'apiFunction');

function apiFunction($event) {
    die("testing");
}

When I run it, I get this error:

image.thumb.png.05737ba1251496bfbe64c6989eb4f1ed.png
 

Any advice is appreciated?

Link to comment
Share on other sites

Your function isn't a method on a class, but you pass $this as the second argument, so the system looks for a method "apiFunction" on $this, which doesn't exist. If you pass null instead as the second argument, it will look for a function instead, it should work then:

<?php namespace ProcessWire;

wire()->addHookAfter('ProcessPageEdit::processInput', null, 'apiFunction');

function apiFunction($event) {
    die("testing");
}

 

  • Like 4
  • Thanks 1
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...