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

3 s
3

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.

Leave a Reply

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