I’m using WordPress 3.0.5 and have tested with 3.1rc4. In the main PHP file of my plugin, when I try to call is_plugin_active I get Call to undefined function is_plugin_active()
. I can call add_action and add_filter. What should I check/change to fix this?
This is happening inside of the admin on the Plugins page. At the top of my main plugin file I have, if (function_exists('is_plugin_active')) {
which always returns false.
I also can’t see the functions from my main plugin file in other plugins (if that helps any).
That’s because the file in which is_plugin_active() is defined –
wp-admin/includes/plugin.php
– is only loaded in the admin, after your plugin is loaded.Thus, you can only call it after ‘admin_init’ has fired:
You can call is_plugin_active() in templates and from user pages as well, which can be useful for related plugins (i.e. require plugin ‘xyz’ to operate my new plugin). You need to manually include the plugin.php file as noted in the is_plugin_active() docs on Codex.
Here is a functional example I use in my premium add-on packs to make sure the free base plugin is active before invoking a the add-on object. It requires certain hooks & filters to be available in the base plugin or it will crash.
As an aside, if you are having problems with is_plugin_active() from within an active admin login it is likely because you are testing before admin_init fires. admin_menu fires before admin_init and doing tests in admin_menu has “bitten” me before. The name “admin_init” which seems counter-intuitive to me since admin_menu is already run. I think of init as “first thing to run”… maybe admin_kinda_init() would be better. 🙂
A quick and dirty workaround would be to duplicate the function manually:
It’s pretty short so it shouldn’t be too hard to implement in your own code as a workaround.
I preferred Tom Auger’s answer with how to define your own is_plugin_active function instead of including plugin.php. However, using the same function name caused my admin area to crash. Using a different function name solved it:
Simple and easy. Taken from WP
and then any instances of
get the function check. SO no more errors.
Are you using
is_plugin_active
inside the admin or the front-end? I am pretty sure thatis_plugin_active
is only an admin function that is found inside wp-admin/includes/plugin.php.Additionally, does your main plugin file make use of WordPress File Header? Is your plugin being included after the above plugin.php file is loaded?
To debug active plugins:
To check for a specific plugin:
The action is called “
active_plugins
” IIRC.If you’re using elementor and facing the issue only in the frontend and it’s working in the editor view.
You can use the
is_edit_mode()
function of elementor, so the condition will only run in the editor view.You can check if a plugin is active as follows:
None of these solutions worked for me, but this did:
I found this solution at codebangers.com