5

We've turned on WordPress Auto-Updates (yey!), but, just in case this does break anything, we'd like to only run Auto-Updates during daylight hours (e.g. 09:00 - 17:30).

We have the "on init" WP-Cron disabled, and are calling it from the servers crontab every 10 minutes.

How can adapt the AutoUpdate, so all updates are run during these times? I've looked at hooks for WP-Cron, but got a little lost.

Additionally - is there a hook that fires once an auto-updated is complete? Our code is in source control, and I'm looking at ways to 'auto-commit' a new branch into our code after an update (rather than having to do it manually).

(The duplicate question doesn't provide any guidance into the hooks to check - simply suggesting to edit the Database - it also talks about WP Cron being fired 'on load' - rather than running on a dedicated cron).

Cheers, Darren

  • 1
    A simple time check in the callback should it, but I'd just turn off the auto-update. It is a bit crazy, IMHO, to run updates "now and then whenever an update comes out" on a production server in a business environment. – s_ha_dum Jun 5 '15 at 17:35
  • possible duplicate of Alter how often WordPress Auto-Updates Plugins – Howdy_McGee Jun 5 '15 at 18:50
  • @s_ha_dum ... we run a LOT (1,000+) WordPress websites. Keeping them all up to date after a security issue is a major logistical challenge! We decided to take the approach of auto-update minor versions, with automated monitoring where needed. If an update causes an issue, we simply rollback to the previous version. We also don't use many "off the shelf" plugins (or plugins in general). We'd prefer a site to be secure (but broken), than insecure (but working). – Darren Jun 8 '15 at 9:46
4

This one is actually surprisingly simple; add this to your wp-config.php file and all automatic updates will be blocked when outside of the specified hours:

// Suspend updates when outside of business hours, 9:00 AM to 5:30 PM
$updates_suspended = (date('Hi') < 0900 || date('Hi') > 1730);

define( 'AUTOMATIC_UPDATER_DISABLED', $updates_suspended );

You can also use these other constants and filters to control which automatic updates are allowed to run if you need to make this more specific.

Make sure you use the server timezone when you set this. The function date() might be configured to use a timezone that is different from your local timezone.

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.