MyBB Community Forums

Full Version: Check if a plugin is installed and enabled
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How can I in code check if a plugin is installed and enabled?

I wish to check if a plugin is installed and enabled upon installation of another plugin that requires the first plugin.
How can this be done?
You'll get it in the cache.
Probably doing:
$actplugins = $cache->read('plugins');
if (in_array('theneeded', $actpugins['active'])) {
   // Plugin is active
} else {
   die('You need the plugin to be active');
}
(2021-02-08, 10:23 AM)Crazycat Wrote: [ -> ]You'll get it in the cache.
Probably doing:
$actplugins = $cache->read('plugins');
if (in_array('theneeded', $actpugins['active'])) {
   // Plugin is active
} else {
   die('You need the plugin to be active');
}

Thank you, how do I know if the plugin is installed but not yet activated?
I'm not sure you really can.

Peharps you can try to use the *_is_installed() function of the plugin you need, but it requires the plugin has this function.
(2021-02-08, 01:09 PM)Crazycat Wrote: [ -> ]I'm not sure you really can.

Peharps you can try to use the *_is_installed() function of the plugin you need, but it requires the plugin has this function.

If you know which specific plugin your plugin requires, you can check if it has plugin_is_installed() function.

In the below code I check if a random plugin 1. exists, 2. is active, 3. is installed:

<?php

global $cache;

if (function_exists('pluginName_info'))
{
  // The plugin exists
}

if (function_exists('pluginName_is_installed'))
{
  if (pluginName_is_installed())
  {
    // The plugin is installed
  }
}

if (in_array('pluginName', $cache->read('plugins')['active']))
{
  // The plugin is activated
}

I haven't tested the above code, but logically this should do the trick.