I have a few filters that I want to apply based on parameters set by, and in, a larger class.
The way I'm currently doing it is with something that looks like this:
public static function setCustomFilter($name){
self::$name = $name;
add_filter('event', function ($args) {
//$name; // wrong scope
CustomClass::$name;
});
}
In order to access $name inside of the filter function I'm setting it to a static field variable on the class. Otherwise $name
will be undefined inside of the filter function.
This seems very clumsy.
Are there ways of doing this more elegantly without global
or field variables?