XF 2.1 Addon is active

Ozzy47

Well-known member
How would I check in my Listener.php file if the addon is enabled? Seems as of now my code is still executed if I disable the addon.
 
There are at least two ways to find out if the add-on is enabled.
First one is to query the entity directly:
$this->finder('XF:AddOn')->where('addon_id', 'myAddOn')->pluckFrom('active')->fetchOne();

The other is to get the list of active add-ons and see if yours is there:
\XF::Repository('XF:AddOn')->getEnabledAddOns();
 
There are at least two ways to find out if the add-on is enabled.
First one is to query the entity directly:
$this->finder('XF:AddOn')->where('addon_id', 'myAddOn')->pluckFrom('active')->fetchOne();

The other is to get the list of active add-ons and see if yours is there:
\XF::Repository('XF:AddOn')->getEnabledAddOns();


Excellent, thank you once again. :)
 
Best way (ie zero query way, and how the XF template helper is_addon_active does it) is;

PHP:
        $addOns = \XF::app()->container('addon.cache');
        $notActive = empty($addOns['MyAddon']));

$addOns is actually add-on id => version list, so you can check the version that is installed.

Note; your add-on code may partially fail to execute even if your add-on is installed! As is_processing means most avenues for code execution gets disabled, but not all cases.
 
Back
Top Bottom