admin管理员组

文章数量:1389783

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

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

Share Improve this question asked Feb 23, 2019 at 15:33 Laurence CopeLaurence Cope 15012 bronze badges 1
  • 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 Commented Feb 23, 2019 at 18:41
Add a comment  | 

2 Answers 2

Reset to default 3

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.

wp-disable-plugin-update.php smart updating knowledge growth WordPress code

/**
 * Prevent update notification for plugin
 * http://www.thecreativedev/disable-updates-for-specific-plugin-in-wordpress/
 * Place in theme functions.php or at bottom of wp-config.php
 */
function disable_plugin_updates( $value ) {
  if ( isset($value) && is_object($value) ) {
    if ( isset( $value->response['plugin-folder/plugin.php'] ) ) {
      unset( $value->response['plugin-folder/plugin.php'] );
    }
  }
  return $value;
}
add_filter( 'site_transient_update_plugins', 'disable_plugin_updates' );

本文标签: functionsHow to update Wordpress and plugins at specific day and time in PHP