Page 1 of 1

Api plugin that can be used by other plugins

Posted: 20 Sep 2021, 01:25
by Estrobeda
Hello, I want to make a plugin that basically works like a RestAPI library that other plugins I want to make can use by simply requiring the RestAPI plugin when installing. (This can be done with $this->requires = array('MantisCore' => 'x.xx.x', 'PluginName' => 'x.xx.x'); in the register function.)

However, I want the config to be accessable to the api class.

So the plugin structure is basically

PluginName
-> PluginName.php
-> Pages
-> config_page.php
-> config_page_inc.php
-> Api
-> PluginNameClass.php
etc

So when you're using the api, you instantiate a new instance of PluginNameClass.php.
The issue with this is that api keys and other secrets are set in config_page_inc.php and are accessible through plugin_config_get().
But since another plugin instantiated PluginNameClass.php, those settings are unreachable.

Do someone know a way that allows you to configure the secrets in config_page_inc.php but are accessible to PluginNameClass.php regardless of where it's instantiated and still be unacessable for other plugins? for example setting the secrets in a private parameter in the class.

Or is it hardcoding I have to do....

Re: Api plugin that can be used by other plugins

Posted: 02 Feb 2022, 09:15
by dregad
Did you try to override the currently active plugin, before calling plugin_config_get() ?

Check plugin_push_current() / plugin_pop_current().

As an example, the Source Integration plugin framework uses this so VCS-specific child plugins (e.g. SourceGithub) can access settings defined in the "main" plugin Source.