• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

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

Jake Bunce

XenForo moderator
Staff member
#2
Waindigo's Library addon does this with the Nodes As Tabs addon. Here is example code:

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;
		}
	}
}