add_action
‘s second parameter is a callable
, it can accept a string (like what you did in the example) or an array of class-instance and function name.
For example, if you want to call a method get_age()
from Person
class, you can do this:
$person = new Person();
add_action( 'hook_name', array($person , 'get_age') );