MyBB Community Forums

Full Version: Quick way of checking plugin activation state?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm creating a plugin that adds a page, and I wanted to check to see if the plugin was active before trying to continue loading it. The way I've used before is... sub-optimal. I was wondering if there was some array or something that contained a list of only the activated plugins, or the state of the various plugins that I could check.

The way I had before was to create a setting that was set to one value on activation and another on deactivation but I'm sure this is redundant and I don't want to do something that's already done for me more automatically and reliably.
^ Pretty much what he said. Toungue
$plugins_cache = $cache->read("plugins");
if(isset($plugins_cache['active']['plugincodename']))
{
	// do something
}
What Pirata said Smile

I personally prefer the reverse though.

$plugins_cache = $cache->read("plugins");
if (!isset($plugins_cache['active']['plugincodename']))
{
     // We aren't currently active, let the user know...
     eval("\$notactive = \"".$templates->get("pluginname_notactive")."\";");
     output_page($notactive);
     exit();
}

// Ok, so we're active... do whatever this file is supposed to do.

This way the user gets some notification that what they want to do isn't gonna happen Smile
assuming that mybb is active and loading the plugins before it hits your outside-of-plugin code

if(function_exists("your_plugin_function"))

for inside-of-plugin code it's active or it wouldn't've been loaded in the first place. only exception to that is the plugins page itself that loads all plugins to list them.
@frostschutz: What I'm doing is adding a custom page that the user directly accesses similar to index.php and the like, so it loads plugins the same as all of the real MyBB pages. However, I don't want users to be able to use the page if I take it down for maintenance (i.e. updating database table structure). Therefore, I want the page to exit out nicely if the plugin isn't installed or activated so it doesn't crash and burn.

@ralgith: Funnily enough, that's eventually what I basically did. It would be kind of nice if MyBB provided a function in $plugins that did this so that plugins wouldn't break if they changed the way the activation state storage works.

Now, if only adding to the toplinks section didn't require editing the template (i.e. having a {$pluginToplinks} that plugins could append to in a hook).
your plugin should have a configuration setting that gets created upon install that allows the setting of am On/Off or Enabled/Disabled option. Then simply test that setting to exit out or not.

that is how the overall board disable function works.

so, on install of your plugin, create a setting group for the plugin (your_plugin), create an on/off setting (your_plugin_enabled) and then in your page test $myy->settings['your_plugin_enabled'] to decide if you exit nicely or continue to process the page.

that is all of course assuming you are including the MyBB global files in your page.

if you are outside of MyBB, just do a simply db query to the settings table where name='your_plugin_enabled' and use that return value
But the only reason the page will be inaccessible is if the plugin is inactive. There's no reason to create my own storage space for something MyBB already stores itself, that's redundant and useless.
okay, then do a simple test of the plugins array as mentioned above. i would have thought that you would have some form of config for whole new pages.