0

I want to check if the plugin is active without using is_plugin_active() from Wordpress because the plugin might not be in the default path. I would like to check using the plugin version constant instead (this one is available). I have other plugin with constant for example ACME_VERSION. To check if this plugin is activated in another plugin, I am using the PHP defined:

if(defined('ACME_VERSION')) {
//plugin is activated, add the hooks
}

However, it is not working. Other Wordpress constants like WP_DEBUG returns true (I have enabled it in wp-config).

Am I missing something? What's the proper way of doing this? Thank you for any tips.

4

1 回答 1

0

You are probably testing the constant before it is defined (e.g. your plugin is loaded before the other plugin). Put your test inside a function called by an action hook, e.g. the 'init' action:

add_action('init', 'my_plugin_init');
function my_plugin_init() {
    if(defined('ACME_VERSION')) {
        //plugin is activated, add the hooks
    }
}
于 2012-12-11T03:47:02.603 回答