4

I'd like to query the database directly, and determine which plugins are enabled.

How can I do this?

3 Answers 3

7

You can do it like this:

SQL

SELECT * FROM wp_options WHERE option_name = 'active_plugins';

But for better approach will be the WordPress way:

Wordpress

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

$active_plugins = get_option('active_plugins');
$all_plugins = get_plugins();
$activated_plugins = array();

foreach ($active_plugins as $plugin){           
    if(isset($all_plugins[$plugin])){
         array_push($activated_plugins, $all_plugins[$plugin]);
    }           
}
1

You can use get_options('active_plugins') to retrieve all active plugins.

For checking against one plugin active or not you can use it like this :

if (in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )) { 
   //Woocommerce Active
}
else{
   //Woocommerce Deactive
}
2
  • I'd like to query the database directly Nov 23, 2017 at 12:25
  • it is located in wp_options table in field option_name = active_plugins Nov 23, 2017 at 12:28
1

Here is a solution that outputs the values in a human readable format:

mysql -h 127.0.0.1 -u wordpress -p wordpress -ss --raw -N -e 'SELECT option_value FROM wp_options WHERE option_name="active_plugins"' | php -r "var_dump(unserialize(stream_get_contents(STDIN)));"
1
  • 1
    yeah it is stored in serialized format, so you had to unserialize it if directly accessing the database Nov 23, 2017 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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