Forums / Code Collaboration / Encapsulated Plugins - frontend is_enabled() check

Encapsulated Plugins - frontend is_enabled() check

Views: 2,075

Results 1 to 6 of 6
23 Mar 2026, 9:59 AM
#1
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,808
Plugin Contributions:
22

Encapsulated Plugins - frontend is_enabled() check

Unless I'm missing something obvious, it seems like there's no frontend function available to check if a certain plugin is installed and enabled?

I have built an Encapsulated Plugin that runs on both frontend and backend (Testimonials). Everything is fine, but I'd like to add a "centerbox" to the home page with some testimonials displayed there. Since there are no hooks to attach it to (@drbyte looking at you - remember the solution I had presented?), I'll just modify the template file. However, I'd like it to be dynamic and displayed only if the plugin is installed and enabled. In case the plugin gets disabled, the centerbox would need to be disabled as well. Turns out there's no function available (at least to my knowledge) that would allow me to check if a certain plugin is installed/enabled or not.

Am I missing something here? If not, I'm happy to PR:

function is_zc_plugin_enabled($plugin_key) {
    global $db;
    
    // Querying the correct plugin_control table
    $sql = "SELECT status 
            FROM " . TABLE_PLUGIN_CONTROL . " 
            WHERE unique_key = :pluginKey: 
            LIMIT 1";
            
    $sql = $db->bindVars($sql, ':pluginKey:', $plugin_key, 'string');
    $check_plugin = $db->Execute($sql);

    // If the record exists AND its status is 1, it is installed and enabled
    if ($check_plugin->RecordCount() > 0 && (int)$check_plugin->fields['status'] === 1) {
        return true;
    }
    
    return false;
}

My site - Pro ZC Help
My portfolio | My plugins

23 Mar 2026, 8:55 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Encapsulated Plugins - frontend is_enabled() check

I'm AFK just now, but I remember doing front-end things with the MAP Pricing encapsulated plugin. That's where I'd look first. Might even just be the presence of a config key being defined.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

23 Mar 2026, 10:01 PM
#3
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,808
Plugin Contributions:
22

Re: Encapsulated Plugins - frontend is_enabled() check

I was thinking of using a constant, but my plugin has no constants added to config. Besides, what's the point of adding a single config setting to enable/disable a plugin when you have that feature in Plugin Manager that allows you to disable a plugin? Imagine the confusion when a user disables the plugin in Plugin Manager, but the constant MY_PLUGIN_ENABLED is still set to true and we're relying on that constant.

The only thing I probably could hook onto is one single function and use function_exists, but I'm not too thrilled with the idea, especially not as a long-term solution in general. Also not 100% sure if it will exist in frontend when a plugin is disabled (not un-installed) - probably worth testing to find out. What if a plugin doesn't have any custom functions or custom classes?
I could also use the $sniffer->table_exists(), but that doesn't tell me if the plugin is disabled or not.

My site - Pro ZC Help
My portfolio | My plugins

24 Mar 2026, 12:49 PM
#4
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: Encapsulated Plugins - frontend is_enabled() check

You could have an auto-loaded observer as part of the encapsulated plugin's file-set and code that observer such that it sets a 'global' variable that indicates its presence.

The code that's deciding whether/not to include that centerbox could then simply check for !empty($plugin_presence_indicator) to do its thing.

24 Mar 2026, 3:27 PM
#5
brittainmark avatar

brittainmark

Totally Zenned

Join Date:
Apr 2009
Posts:
509
Plugin Contributions:
1

Re: Encapsulated Plugins - frontend is_enabled() check

in the up coming release zc 2.2 there is the getInstalledPlugins method in includes/classes/DbRepositories/PluginControlRepository.php which would give you a list of installed plugins that are enabled. If you were to add a check function I would suggest that that is where it needs to go.

Mark Brittain
http:\innerlightcrystals.co.uk\sales\

24 Mar 2026, 4:21 PM
#6
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,808
Plugin Contributions:
22

Re: Encapsulated Plugins - frontend is_enabled() check

lat9:

You could have an auto-loaded observer as part of the encapsulated plugin's file-set and code that observer such that it sets a 'global' variable that indicates its presence.

The code that's deciding whether/not to include that centerbox could then simply check for !empty($plugin_presence_indicator) to do its thing.

Damn it, Cindy, that was a brilliant idea - I would never have thought of that! Many thanks! :cheers:

For anyone who would like to do the same, here's the solution:
Add a new file in your zc_plugins/your_plugin/version/catalog/includes/classes/observers/ named auto.yourplugin_plugin_presence_indicator.php (in my case auto.testimonials_plugin_presence_indicator) with the following content:

<?php
/**
 * Observer class used to indicate the plugin is active
 */
class zcObserverTestimonialsPluginPresenceIndicator extends base
{
    public function __construct()
    {
        // Declare the global variable and set it to true
        global $testimonials_plugin_presence_indicator;
        $testimonials_plugin_presence_indicator = true;
    }
}

Don't forget to change the class name based on file name.

That's it - now you have a global variable you can use anywhere in the system. In my case, I'm using it like this:

<?php
if (!empty($testimonials_plugin_presence_indicator)) {
    require($template->get_template_dir('tpl_modules_testimonials.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_testimonials.php');
}
?>

My site - Pro ZC Help
My portfolio | My plugins