0

I need a good trigger to use in my plugin to kick off changes to the website.

I've got a custom plugin that goes on all WordPress sites that I build. I've got it set up to auto-update the plugin.

Occasionally, I need to push out an update across all websites. For instance, there was a plugin that started causing issues across all sites so I wrote code in my function to deactivate it across all sites.

Now I'm writing code to remove some old users that should no longer have access to the site. To deactivate the plugin, I used the action 'plugins_loaded'. Of course the problem there is that it runs EVERY time the plugins are loaded so it runs on EVERY page load. It's pretty fast but still not the right way to do it.

I tried to find some sort of way to kick that one off only when the plugin is updated. Really, I just need these functions to run once ever.

Is there a good action I could use to make sure that happens?

6
  • Well, you could use the admin_init hook which runs when the WP dashboard is accessed. Jul 9, 2022 at 2:04
  • Worth checking out (although is probably not 100% up-to-date): codex.wordpress.org/Plugin_API/… Jul 9, 2022 at 2:06
  • @cabrerahector If I use admin_init, it will run every time admin pages load. I just want to guarantee that it runs one time
    – dovidev
    Jul 11, 2022 at 21:30
  • 1
    You will always need to do at least some sort of checking on every page load. There's no way around it. For example, you could store the plugin version on the database (eg. update_option( 'my_plugin_version', '1.2.3' );) then on every page load you'd check if the plugin version has changed (eg. by making a call to a remote URL) and if so then you do something, otherwise you do nothing. Jul 11, 2022 at 21:35
  • 1
    Alternatively, there's also scheduled tasks. Jul 11, 2022 at 21:36

0

Your Answer

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