remove_action: how to access to a method in an child class?
I've this in my main plugin file:
$main_admin_class = new MainAdminClass();
$main_admin_class-init();
MainAdminClass has this code:
class MainAdminClass {
public function init() {
$child_admin = new ChildAdminClass();
$child_admin-init();
}
}
and, finally, the child class has this code
class ChildAdminClass {
public function init() {
add_action('admin_notices', array($this, 'printFoo'));
//I know it works if I use 'ChildAdminClass' instead of $this
}
public function printFoo() {
echo 'fooooooooooooooooooooooooooooo';
}
}
When later I try to use remove_action in functions.php, with this code:
global $child_admin;
remove_action('admin_notices', array($child_admin, 'printFoo'));
It doesn't works, unless I call the method statically.
I'm aware that it works if I use the add_action in the MainAdminClass instead of the child, but I would like to know if it is possible to make this works.