[wp-hackers] [help] sink plugin hooks for $this

Jamie Talbot wphackers at jamietalbot.com
Sat Jan 14 12:04:59 GMT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mark Jaquith wrote:
> If you use add_action() from within the class, $this is perfectly fine:
> 
> <?php
> 
> class myTestClass() {
> 
>     function myTestClass() { // constructor
>         add_action('activate_samba/loadbalancer.php', array(&$this, 
> 'install');
>     }
> 
>     function install() {
>         // do install stuff here
>     }
> 
> }
> $singleton = new myTestClass;
> ?>

Yes, but from what I understand, Niels is having problem with references.

Niels Hackius wrote:
>My problem isn't really that the hook doesn't work its more that I can't
>pass a classvariable by reference

The line I gave,

>> add_action('activate_samba/loadbalancer.php', array ('LoadBalancerClass', 'installer'));

can be called _outside_ a class, at the bottom of a plugin definition file, which may or may not help.
If I remember correctly, this is how UltimateTagWarrior adds its filters and actions.
But, if you do that, you _can't_ use $this inside the registered callback functions.

Jamie.

- --
http://jamietalbot.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDyOjrrovxfShShFARAglqAJ9K6DtZiL3056xjM7sqjGSDRwccSwCfWyeJ
TeSPvay1MbI1eyxAdLDUl2Y=
=YFvD
-----END PGP SIGNATURE-----


More information about the wp-hackers mailing list