admin管理员组

文章数量:1122832

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.

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.

Share Improve this question edited Jul 18, 2018 at 5:56 Krzysiek Dróżdż 25.5k9 gold badges53 silver badges74 bronze badges asked Jul 11, 2018 at 9:18 Tex0genTex0gen 5722 silver badges13 bronze badges 2
  • wordpress.stackexchange.com/questions/54742/… – Shir Gans Commented Jul 11, 2018 at 9:41
  • @ShirGans Not what i want but thanks. – Tex0gen Commented Jul 11, 2018 at 10:43
Add a comment  | 

2 Answers 2

Reset to default 4

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);

There are a few plugins that can track this plugin data. One of them is https://wordpress.org/plugins/plugin-activation-tracker/

本文标签: actionsDetect when any plugin is activated or deactivated