1. 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?

Discussion in 'XenForo Development Discussions' started by Mr. Goodie2Shoes, Jul 15, 2012.

  1. Mr. Goodie2Shoes

    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'...
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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;
    		}
    	}
    }
    
     
    EQnoble and Mr. Goodie2Shoes like this.
  3. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    Thanks! :D
    I thought there was a much easier way :p
     

Share This Page