Wordpress - is_plugin_active function doesn't exist

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' );

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.

include_once(ABSPATH.'wp-admin/includes/plugin.php');
if (!function_exists('is_plugin_active') || !is_plugin_active('store-locator-le/store-locator-le.php')) { 
   return;
}

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:

if ( ! function_exists( 'is_plugin_active' ) ) {
    function is_plugin_active( $plugin ) {
        return in_array( $plugin, (array) get_option( 'active_plugins', array() ) );
    }
}

It's pretty short so it shouldn't be too hard to implement in your own code as a workaround.