Powered by Blogger.

How to get WordPress activated plugin version


In some cases, you may need to check WordPress’s activated plugin version. Maybe you consider using function get_plugin_data, but I don’t recommend it as it needs to give out the plugin file with an absolute path.

I find out another way to get a plugin version easier. Please see the following codes.

//get all activated plugins first
$activated_plugins = get_option( 'active_plugins' );
if( in_array('akismet/akismet.php', $activated_plugins) ) {
    $all_plugins = get_plugins();
    $akismet_version = $all_plugins['akismet/akismet.php']['Version'];
    
    if( version_compare( $akismet_version, '4.0', '>=' ){
         //version above or same 4.0
    }else{
         //version below 4.0
    }
}


No comments