Following the advice in this posting: php class as a plugin in wordpress
I’ve created a helper class for use with other plugins. In the class file, I have a declaration for activating the class, like:
function test_init() {
$test = new Test();
} // End of test_init()
I’m able to access the functions in this class by doing something like:
Test::my_function();
However, I’m having issues referring to functions within this class from each other. For example:
function my_function() {
Test::other_func();
}
In a case like this, I get the error message: “Function name must be a string”
I’ve tried $this->other_func, which returns the error: “there is not function “other_func” in the Class_Using_The_Test_Class.
I’ve tried self::other_func, which return the error: “Function name must be a string”
I tried using call_user_func() and I get: “call_user_func() expects parameter 1 to be a valid callback”
How do I call another function within this class?
You don’t actually need to activate the class. I’ll give an example.
Let’s say this code lives in
helper-class.php:Now, over in your other class file you could have something like this:
I hope this sheds a bit of light on your situation. Just ask if you’d like further clarification. 🙂