How to check if an add-on is installed and active?

Mr. Goodie2Shoes

Well-known member
well, the title says it all... how do I check if a dependent add-on is installed?
and no, not during installation, when my add-on is 'listening'...
 
Waindigo's Library addon does this with the Nodes As Tabs addon. Here is example code:

Rich (BB code):
<?php

class Waindigo_Library_Listener_LoadClassController extends Waindigo_Listener_LoadClass
{
	public static function loadClassController($class, array &$extend)
	{
		switch ($class)
		{
			case 'Waindigo_Library_ControllerAdmin_Library':
				if (file_exists(XenForo_Autoloader::getInstance()->autoloaderClassToFile('NodesAsTabs_ControllerAdmin_AllNodes')))
				{
					$db = XenForo_Application::get('db');
					if ($db->fetchOne('SELECT active FROM xf_addon WHERE addon_id = \'NodesAsTabs\''))
					{
						self::_extend('NodesAsTabs_ControllerAdmin_AllNodes', $extend);
					}
				}
				break;
				
			case 'XenForo_ControllerAdmin_Tools':
				XenForo_CacheRebuilder_Abstract::$builders['Library'] = 'Waindigo_Library_CacheRebuilder_Library';
				break;
				
			case 'XenForo_ControllerPublic_Thread':
				self::_extend('Waindigo_Library_ControllerPublic_Thread', $extend);
				break;
		}
	}
}
 
Top Bottom