Recent Topics

1 Mar 24, 2009 08:30    

Is it possible from plugin A to access data from plugin B?

The scenario is this: plugin A and B do similar things but on different places. Plugin A displays on widgets via SkinTag, while plugin B is a Renderer. From plugin A I would like to inspect one internal variable from Plugin B to check if Plugin B has already displayed more than "N" times and in that case my widget from plugin A does nothing, otherwise it displays as requested.

Is it possible to do something like:

 $pluginBstatus = parent::pluginB_class::$internal_pluginb_variable

That's an abstract description but if you need more specifics to clarify, please ask.

Or Am I completely out of order here and that's utterly impossible. Maybe I should go and read a basic PHP reference or something. If that's the case, don't hesitate to be blunt.

Thanks in advance.

2 Mar 24, 2009 14:00

Not sure if it'll help or not, but if this is for personal use then you can look at your database and see the plugin ID for the first, then manually tell the second what to go look for. *probably*. I almost tried this then decided to jam everything into one 'mother of all plugins'.

Alternatively, dig on AM Current Plugins plugin via bopit. It builds itself a list of all plugins for displaying as a skintag, so it knows all sorts of stuff about installed plugins. That should get you well down the path of having plugin B talk to plugin A ... I think. Like, first plugin B needs to know plugin A is there, then know stuff like it's code and plugin_ID right?

To get database stuff would be real easy, which is what I thought of doing. One plugin to build the database tables and handle most data entry, the other to use that info and handle the data entry associated with posting. Anyway to get an internal variable, for me, would be next to impossible. I'd start with a whole bunch of stuff like

$this->msg('<pre>'.var_export($Plugins, true).'</pre>', 'note');


Then go back and add "global $Plugins after it choked until I finally figured out how to get all the way to plugin A and learn what it knows.

Or I'd wait for Yabba to make a plugin that talks to another plugin, then "steal with pride" the bits that didn't suck :)

3 Mar 25, 2009 02:18

if( ($Some_Plugin = & $Plugins->get_by_code('some_code')) !== false )
{	
	if( $Some_Plugin->status == 'enabled' )
	{    // Plugin is installed and enabled
		echo $Some_Plugin->Settings->get('some_setting');
	}
}

;)

4 Mar 25, 2009 10:04

Hi sam,

That's almost there. The problem is that I'm not trying to access a Setting from the another plugin, but an internal variable.

See, the second plugin mantains a static variable inside one of its functions, which holds the number of times it has rendered some content. I want to check that variable, not a setting.

Probably that's not possible unless the second plugin does export this variable or something like that. I don't know if that's the proper terminology in the OO context we're speaking.

Corrections to my broken OO PHP lingo are welcome, of course.

5 Mar 25, 2009 13:48

Plugin A

$my_var = 'qwerty';
$this->var = $my_var;

Plugin B

if( ($Some_Plugin = & $Plugins->get_by_code('some_code')) !== false )
{    
    if( $Some_Plugin->status == 'enabled' )
    {    // Plugin is installed and enabled
        echo $Some_Plugin->var;
    }
}

This should work also


Form is loading...