Title: function is_plugin_active()
Last modified: December 2, 2019

---

# function is_plugin_active()

 *  Resolved [Hannes Etzelstorfer](https://wordpress.org/support/users/haet/)
 * (@haet)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-is_plugin_active/)
 * Hello,
    I just tried to install the plugin on a multisite installation and for
   some reason there has been an conflict with Klaviyo for WooCommerce. I had a 
   look at the code of both plugins and could fix the problem by replacing your 
   check for active WooCommerce and active Pro-Version by the function is_plugin_active().
   In my opinion the statements used before were absolutely correct, I just wanted
   to simplify the code and solved the conflict “by mistake” 😉 Here are the new
   first lines in left-to-free-shipping-for-woocommerce.php:
 *     ```
       if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
   
       // Check if WooCommerce is active
       if ( !is_plugin_active('woocommerce/woocommerce.php') ) {
       	return;
       }
   
       if ( 'left-to-free-shipping-for-woocommerce.php' === basename( __FILE__ ) ) {
       	// Check if Pro is active, if so then return
       	if ( is_plugin_active( 'left-to-free-shipping-for-woocommerce-pro/left-to-free-shipping-for-woocommerce-pro.php' ) ) {
       		return;
       	}
       }
   
       if ( ! class_exists( 'Alg_WC_Left_To_Free_Shipping' ) ) :
       ```
   

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [Algoritmika](https://wordpress.org/support/users/algoritmika/)
 * (@algoritmika)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-is_plugin_active/#post-12196470)
 * Hi [@haet](https://wordpress.org/support/users/haet/),
 * Thanks for the `is_plugin_active()`, really appreciate it. To be honest, I didn’t
   know about this function. Will have to change it in all my plugins now :/ Not
   sure what could cause the compatibility issue with the old code though…
 *  Plugin Author [Algoritmika](https://wordpress.org/support/users/algoritmika/)
 * (@algoritmika)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-is_plugin_active/#post-12196696)
 * Hi again, [@haet](https://wordpress.org/support/users/haet/),
 * I’ve tried it out and now I remembered that I actually already tried using `is_plugin_active()`–
   it produces `Call to undefined function is_plugin_active()` error on my server.
   The problem that this function is only defined in `wp-admin/includes/plugin.php`
   file, which loads later. So basically `is_plugin_active()` should be used in `
   admin_init` hook for example. In your case, I assume, some other plugin is requiring`
   wp-admin/includes/plugin.php` file earlier, which I’m not sure is a good idea.
   Anyway, I think I found a solution that should work on all servers – it will 
   be added in next plugin version.
 *  Thread Starter [Hannes Etzelstorfer](https://wordpress.org/support/users/haet/)
 * (@haet)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-is_plugin_active/#post-12196865)
 * You could / should wrap your initialization code in
 *     ```
       add_action( 'plugins_loaded', function(){
         //  your init code here
       });
       ```
   
 * so you can make sure the WordPress core is initialized.
 *  Plugin Author [Algoritmika](https://wordpress.org/support/users/algoritmika/)
 * (@algoritmika)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-is_plugin_active/#post-12196934)
 * [@haet](https://wordpress.org/support/users/haet/),
 * Yes, I’ve also thought of `plugins_loaded` hook.
 *  Thread Starter [Hannes Etzelstorfer](https://wordpress.org/support/users/haet/)
 * (@haet)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-is_plugin_active/#post-12196950)
 * Thanks for the fast reply!
 *  Plugin Author [Algoritmika](https://wordpress.org/support/users/algoritmika/)
 * (@algoritmika)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-is_plugin_active/#post-12203907)
 * Hi [@haet](https://wordpress.org/support/users/haet/),
 * I’ve just tried it with `plugins_loaded`, but it looks like `is_plugin_active()`
   is still not defined yet. The only hook that I found which has this function 
   already defined is `admin_init`. Also it looks like it’s available in admin only–
   I’ve tried it in `init` hook and it’s not defined there.
 * So I’m thinking about defining my own function:
 *     ```
       /*
        * alg_is_plugin_active.
        */
       function alg_is_plugin_active( $plugin ) {
           return ( function_exists( 'is_plugin_active' ) ? is_plugin_active( $plugin ) :
               (
                   in_array( $plugin, apply_filters( 'active_plugins', (array) get_option( 'active_plugins', array() ) ) ) ||
                   ( is_multisite() && array_key_exists( $plugin, (array) get_site_option( 'active_sitewide_plugins', array() ) ) )
               )
           );
       }
       ```
   
 * So basically I’m using `is_plugin_active()` if it’s already defined (like in 
   your case) and otherwise I’m using my own code (which is basically same code 
   copied from `is_plugin_active()` source). This should solve the issue on your
   server. Still not sure why your server doesn’t like my old code though – it’s
   basically the same code as in original WP.
 *  Plugin Author [Algoritmika](https://wordpress.org/support/users/algoritmika/)
 * (@algoritmika)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-is_plugin_active/#post-12203982)
 * P.S. The only difference I’m seeing in the original WP code and my code is that
   I’m applying `active_plugins` filter on `get_option( 'active_plugins', array())`.
   I’ve copied this filter from WooCommerce – in `class-wc-helper.php` file:
 *     ```
       $active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
       ```
   
 *  Plugin Author [Algoritmika](https://wordpress.org/support/users/algoritmika/)
 * (@algoritmika)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/function-is_plugin_active/#post-12204026)
 * P.P.S. I’ve just released new plugin v1.4.1 with the updated code as described
   above.
 *  [SoN9ne](https://wordpress.org/support/users/son9ne/)
 * (@son9ne)
 * [6 years, 1 month ago](https://wordpress.org/support/topic/function-is_plugin_active/#post-12674028)
 * FYI, it would be better practice to use:
 *     ```
       // Include file if function does not exist
       if (!function_exists('is_plugin_active')) {
           include_once(ABSPATH . 'wp-admin/includes/plugin.php');
       }
       ```
   
 * Other than making your own. Sure it works but be careful with copying from core,
   especially if they change how that works. Minor issue but worth mentioning.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘function is_plugin_active()’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/amount-left-free-shipping-woocommerce_bfd7ef.
   svg)
 * [Free Shipping Bar: Amount Left for Free Shipping for WooCommerce](https://wordpress.org/plugins/amount-left-free-shipping-woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/amount-left-free-shipping-woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/amount-left-free-shipping-woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/amount-left-free-shipping-woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/amount-left-free-shipping-woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/amount-left-free-shipping-woocommerce/reviews/)

 * 9 replies
 * 3 participants
 * Last reply from: [SoN9ne](https://wordpress.org/support/users/son9ne/)
 * Last activity: [6 years, 1 month ago](https://wordpress.org/support/topic/function-is_plugin_active/#post-12674028)
 * Status: resolved