4

I'm using the mingle plugin and the mingle-forum plugin.

I want to show a certain part on my site only if those two plugins are active. How can I solve this?

<?php if ( is_plugin_active('mingle-forum') ) { ?>
                    <div id="login"><?php include (TEMPLATEPATH . '/inc/userlogin.php' ); ?></div>
                <?php } ?>

This throws a php error. Call to undefined function is_plugin_active

Any idea what I'm doing wrong?

update:

<?php if ( plugin_active('plugin-directory/mingle-forum/wpf-main.php') ) { ?>
                    <div id="login"><?php include (TEMPLATEPATH . '/inc/userlogin.php' ); ?></div>
                <?php } ?>
1
  • Where (what file or hook) do you use this function? Apr 21, 2011 at 12:51

5 Answers 5

6

This function exists in wp-admin/includes/plugin.php so I'm assuming it doesn't get included by the theme.

You can either require it, or just create your own version of it - see here: http://wordpress.org/support/topic/is_plugin_active

UPDATED:

Please check is_plugin_active

3
  • thank you, i might have found a solution but I still can't get it working. The function plugin_active is set in my functions.php file and doesn't through an error. However my div.login does NEVER show up, doesn't matter if the plugin is active or not. Maybe I'm checking for the wrong path? Any idea what I could do wrong here? Apr 22, 2011 at 7:41
  • 1
    found the solution. "plugin-directory" of course has to be the name of the directory where the actual plugin file is in. I thought "plugin-directory" is the path to the dir where all the plugin files are in. Apr 22, 2011 at 7:43
  • exactly mathiregster, that's what everyone seems to be missing here. plugin-directory is most likely going to be the name of your plugin Sep 15, 2021 at 14:20
5

There are two way by which you can check plugin is active or not.

  1. You can use is_plugin_active function to check plugin active or not.
  2. If plugin have class then you can check like below-

    if (class_exists('YITH_Woocompare_Frontend')) 
    {
    echo 'your code';
    }
    

The above class related to YITH WooCommerce Compare plugin . The above code check if class exist then only you code inside the bracket will execute.

1
  • was about to upvote, but the class thing is just totally false. What happens if the class name is changed? and is_plugin_active is basically the accepted answer :( Aug 3, 2016 at 6:50
3

You can also try to check plugin is Active or Not

$pluginList = get_option( 'active_plugins' );
$plugin = 'PLUGIN_DIR/FILE_NAME.php'; 
if ( in_array( $plugin , $pluginList ) ) {
    // Plugin 'mg-post-contributors' is Active
}

Also try below code for simplicity

if ( is_plugin_active( 'PLUGIN_DIR/FILE_NAME.php' ) ) {
  //plugin is activated
} 
2
  • The poster was unable to use is_plugin_active because it is only available from admin pages.
    – jeteon
    Oct 13, 2015 at 9:06
  • This solution helped me verify the plugin name. Tks
    – Memonic
    Apr 23, 2020 at 16:02
1

You can simply use the WordPress default function. This function exists in wp-admin/includes/plugin.php.

Simply pass the Path to the plugin file relative to the plugins directory.

$pluginPath = 'akismet/akismet.php';
if ( is_plugin_active( $pluginPath ) ) {
    echo 'Plugin is activated';
} else {
   echo 'Plugin is not activated';
}

For more details on is_plugin_active please see the below link:

https://developer.wordpress.org/reference/functions/is_plugin_active/

1
  • Thank you, @Sohel Khan; that hint was really useful to me; I use/d it to start building a health bar for my site :) Cheers!
    – eLeXeM
    Nov 14, 2020 at 18:03
0

the correct and actual way to check if a plugin is active or not is to set a

function_exists ()

function for your code

1
  • 2
    Welcome to wpse! the correct and actual way to check if a plugin is active or not is to set function_exists. What if a plugin is OO and doesn't use any functions, only methods, your answer fails to address this situation. Oct 14, 2021 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.