Many times, developers would come across a requirement to check if a module is enabled or disabled in a Magento 2 store.
It happens when one needs to check about the module’s status is a multi-store or when you are using third-party modules.
Use the isEnabled() function as shown below to check if a module is enabled or not programmatically in Magento 2.
Method to check if a module is enabled or not programmatically in Magento 2:
<?php namespace [Vendor]\[Module]\Helper; use Magento\Framework\App\Helper\AbstractHelper; use Magento\Framework\App\Helper\Context; use Magento\Framework\Module\Manager; class Data extends AbstractHelper { protected $moduleManager; public function __construct( Context $context, Manager $moduleManager ) { $this->moduleManager = $moduleManager; parent::__construct($context); } public function isEnable() { if ($this->moduleManager->isEnabled('[Vendor]_[Module]')) { //code for Module is enabled return 1; } else { //code for Module is disabled return 0; } } }
Note: The above method checks only if the module is enabled in the configuration or not. It does not support checking the status for the admin panel.
That’s it.
Also, please share the solution with the Magento community via social media.
Thank you.