is_plugin_active function doesn’t exist

Question

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).

in progress 0
, , Carl 12 years 2011-02-14T17:59:14-05:00 0 Answer 91 views 0

Answer ( 1 )

    0
    2021-08-01T10:26:14-05:00

    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:

    function check_some_other_plugin() {
      if ( is_plugin_active('some-plugin.php') ) {
        ...
      }
    }
    add_action( 'admin_init', 'check_some_other_plugin' );
    

Leave an answer

Browse
Browse