WordPress has a handy method available to check if a plugin is installed and active before calling and making use of one of its functons.
is_plugin_active()
An example of its use might be a WooCommerce cart repeater included within the header of a theme. clearly If the WooCommerce plugin isn’t active then we don’t wish the cart value to be represented. And more importantly it’s likely to error with the missing code.
<?php
if ( is_plugin_active('woocommerce/woocommerce.php')){ ?>
<a class="cart-contents" href="<?php echo wc_get_cart_url(); ?>"
title="<?php _e( 'View your shopping cart' );
?>">
<?php echo WC()->cart->get_cart_contents_count(); ?>
</a>
<?php } ?>
However, without further action the above will error as shown below:
Fatal error: Uncaught Error: Call to undefined function is_plugin_active()
To resolve this add an early reference to the WordPress plugin.php file.
<?php include_once ABSPATH . 'wp-admin/includes/plugin.php'; ?>
With the addition of a reference to the in-built WordPress plugin.php file the method is_plugin_active can be used to check whether a plugin is installed and active before calling one of its functions.


