I need to call a method from within a function, so I must pass it as an array like so:
array($this, 'display_page');
but I need to pass arguments along with it. Is this possible?
EDIT – New Method – Still not working.
I have now tried passing an anonymous function, in place of the array call back.
function(){MyClass::display_page($display);}
and edited the function thusly:
class MyClass{
static function display_page($arg = false)
{
if($arg){
echo $arg;
} else {
echo "Nothing to report!";
}
}
}
but all I get is Nothing to report!
EDIT The problem lies with the way the callback was being used within WordPress (didn’t think it was relevant, turns out it was). Have voted to close.
If you take a look at call_user_func, you can see that it has a second optional parameter called parameter.
Use that.
Or you could do it the dirty way like mentioned in the comment on call_user_func