How To Get a List of All Active Plugins Programmatically

To get a list of all active plugins programmatically in WordPress, you can use the WordPress API functions. WordPress provides functions that allow you to retrieve information about active plugins. You can use either the get_option function or the wp_get_active_and_valid_plugins function. Here’s how you can use both methods:

  • Method 1: Using get_option:
$active_plugins = get_option('active_plugins');

if (!empty($active_plugins)) {
    foreach ($active_plugins as $plugin) {
        echo $plugin . '<br>';
    }
} else {
    echo 'No active plugins.';
}
  • Using wp_get_active_and_valid_plugins:
$active_plugins = wp_get_active_and_valid_plugins();

if (!empty($active_plugins)) {
    foreach ($active_plugins as $plugin) {
        echo $plugin . '<br>';
    }
} else {
    echo 'No active plugins.';
}

Both of these methods will give you an array of active plugin file paths. You can loop through the array and display the list of active plugins or perform any other operations you need programmatically.

Leave a comment

Your email address will not be published. Required fields are marked *