Api plugin that can be used by other plugins

General discussion about MantisBT Plugins

Moderators: Developer, Contributor

Post Reply
Posts: 1
Joined: 20 Sep 2021, 01:08

Api plugin that can be used by other plugins

Post 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.php
-> Pages
-> config_page.php
-> config_page_inc.php
-> Api
-> PluginNameClass.php

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....
Posts: 76
Joined: 26 Jul 2010, 14:24

Re: Api plugin that can be used by other plugins

Post 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.
Post Reply