I have a starter theme I use for most websites I built myself. Because each site has different plugin dependencies, I'm trying to create a script that essentially collates a list of all plugins currently active and store them in a JSON file.

Then, I want to use TGM Plugin activation to loop that list and install any plugins that are not already there.

We use git to host our theme directory. When we push the changes, they are deployed onto our staging server automatically. The issue is, we don't want to have to login to FTP or run WP-CLI commands in order to install missing plugins. We would rather want the dependencies to come from the theme itself to install the plugins automatically if we have a missing one on our localhost.

We also have a very forgetful developer, that can't be relied upon to add the plugin manually to the TGM file.

So, my problem here lies that I cannot seem to find any hooks that are called immediately upon a plugin activation or deactivation, at which point to re-collate the plugin list and spit it out to a JSON file to be used to activate or deactivate plugins from that list.

Any help on this would be very much appreciated.


1 Answer 1


There are few solutions. You can use activate_plugin and deactivate_plugin hooks for example.

But... As far as I understand you right, you want to get notified whenever list of plugins get changed and not when a plugin is activated or deactivated.

So the easiest way will be hooking onto update_option.

add_action('updated_option', function( $option_name, $old_value, $value ) {
    if ( 'active_plugins' == $option_name ) {
        // update your json file based on $value
}, 10, 3);
  • Ah i see, so this detects when the options row for active plugins list changes right?
    – Tex0gen
    Jul 11, 2018 at 9:48
  • Yes, exactly. So any change will be detected. And you have current and old list of active plugins ready to use :) Jul 11, 2018 at 9:52
  • Another tip that you might find useful is if you wanna check whether or not a plugin is activated, use function_exists or class_exists instead of is_plugin_active as it's not reliable, in my experience. @SteveNorth
    – coolpasta
    Jul 18, 2018 at 8:03
  • @coolpasta Thank you, this works if I was going to check for a specific plugin but the idea was to be able to add all active plugins to a JSON file on activation/deactivation.
    – Tex0gen
    Jul 19, 2018 at 11:07

Your Answer

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

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