WordPress

Quick Fix for Uncaught Error: Call to undefined function is_plugin_active()


In the WordPress development process, sometime you need to check if a certain plugin is active so that you can perform your task accordingly. The is_plugin_active() is the function available for that.

In some cases, you face an “Uncaught Error: Call to undefined function is_plugin_active()” which is because this function is defined in wp-admin/includes/plugin.php and in your specific case, this file isn’t being loaded.

A quick turnaround for this scenario is that you define the function by yourself. It is always better to put it in function_exists() check to be on the safe side.

if ( ! function_exists( 'is_plugin_active' ) ){
    require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
}

Again in some cases, you don’t want to put all the mess for just one function. You can create a new function with your own theme or plugin prefix.

function hr_is_plugin_active( $plugin ) {
    return in_array( $plugin, (array) get_option( 'active_plugins', array() ) );
}

You can use if( ! function_exists( ‘is_plugin_active’ ) ){ } for this purpose but it is better to create your own just to be on the safe side.

WordPress
Remove Category or Tag Slug from url
Quicky
Fixing Notice: Function _load_textdomain_just_in_time was called incorrectly for WordPress 6.7 update
There are currently no comments.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Hassan Raza