How to avoid WordPress plugins update during office hours using PHP codes

How to avoid WordPress plugins update during office hours using PHP codes?

Due to WordPress plugin updates having the possibility to break our site, we don’t know when WordPress would actually do the updates which could also occur slowly down the website and shows the message ‘Site is under maintenance’ to end users.  

We would like to programmatically update WordPress plugins at specific times or avoid updates during office hours to run the website properly and gain more end-user attention, also we can know the exact time it will run, and know to check for problems afterward.

The below codes go to function.php or use the Code snippets tools to add the codes to your website.

date_default_timezone_set('Asia/Kolkata');
$now = date( 'H:i:s', time () );
echo $now;
$start = '06:00:00'; 
$end = '17:00:00'; 
if($now >= $start && $now <= $end){  
define( 'AUTOMATIC_UPDATER_DISABLED', $now );
}
else{
 }

The above code is working correctly and it’s disabling the auto-update plugin from morning 6 am till evening 5 pm. You can change the timing in a specified format as per your requirement.

Leave a Comment