2

We use automatic updates on our sites due to having many sites and so manual updates not being feasible in the low hosting costs.

But due to Wordpress or mainly plugin updates having the possibility to break your site, and due to not knowing when Wordpress would actually do the updates which could also occur every day, I would like to programatically update Wordpress and plugins in a functions.php or plugin so I can know the exact date and time it will run, and so we know to check for problems afterwards.

For example, I may choose Monday mornings 3am so our first action that morning is check all sites are working well, fix any issues, and then I know the rest of the week will be problem free :)

Does anyone know how to initiate a Wordpress and plugin update in the functions file or a plugin?

My idea is to disable all automatic updates generally, but then at a certain day and time to call the update function which would check if updates exist, and if they do, update them. I will add an email function to inform me what has been updated on what site so I can check that site.

If using automatic updates, this approach is far more controlled than if leaving Wordpress do it as and when it likes however many times every day.

Thanks

  • You can do a scheduled task everyday and put in the wp update function if the wp version has changed or if it is a new w version. – Ayed Mohamed Amine Feb 23 at 18:41
1

There's a question and an answer regarding WP (auto) updates here, How To/What triggers a Wordpress auto update?

The answer also has a link to a blog post on how to force WordPress auto-update.

Code snippet posted on the referenced blog,

<?php
  // request-update.php
  require( dirname(__FILE__) . '/wp-load.php' );
  wp_maybe_auto_update();
?>

and

php ./request-update.php

Perhaps you can use this and a real (not WP) cron job to update your site(s) at a certain day and time.

Edit

Then there's the do_core_upgrade function.

Edit 2

Oh, and then there's wp_update_plugins and wp_update_themes, too. These are defined in wp-includes/update.php (trac).

Edit 3

Actually, wp_ajax_update_plugin might be better reference point for creating a custom plugin update process. There's also the Plugin_Upgrader class. For themes there's wp_ajax_update_theme for reference and Theme_Upgrader class.

  • So the WP update functions will check if an update exists in WP AND plugins, and only update if it does? So we dont need to worry about checking if updates exist, just run the update at a scheduled time and all is taken care of? – Laurence Cope Feb 25 at 10:34
  • It looks like the runmethod from WP_Automatic_Updater which the wp_maybe_auto_update uses does exaclty that. It checks if there are any updates for plugins, themes and core. If there is, it processes them. – Antti Koskinen Feb 25 at 15:15

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.