PDA

View Full Version : Accessing variable of one plugin from another


CvP
01-21-2011, 08:15 PM
Say I have a variable $myvar in global_bootstrap_complete.
How do I access it from postbit_display_complete?

Also, what do the "shaded" hooks mean in debug info?

Lynne
01-21-2011, 10:04 PM
Shaded means the hook is available but not being used by an active plugin on that page.

Usually the variable should be available for use. However, sometime a hook is in a function and you may have to globalize the variables in order to use it there.

CvP
01-21-2011, 11:12 PM
Can you show me an example? I tried using global before, it didn't work.

For example,

global_bootstrap_complete
global $myvar = 5;

process_templates_complete
global $myvar;
$f = fopen('debugx.txt', 'w');
fwrite ($f, print_r($myvar, true));
fclose($f);

I tried with/without global (and a few combination of hooks) before but debugx.txt is always empty.

Lynne
01-22-2011, 12:48 AM
global_bootstrap_complete:
global $myvar;
$myvar = 5;
process_templates_complete:
global $myvar;
other code

CvP
01-22-2011, 08:32 AM
* CvP punches himself.
result of not having proper sleep.

Thanks Lynne :D