: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$upgrader->maintenance_mode( true );
// If the filesystem is unavailable, false is returned.
if ( false === $upgrade_result ) {
$upgrade_result = new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) );
if ( 'core' === $type ) {
if ( is_wp_error( $upgrade_result )
&& ( 'up_to_date' === $upgrade_result->get_error_code()
|| 'locked' === $upgrade_result->get_error_code() )
// Allow visitors to browse the site again.
$upgrader->maintenance_mode( false );
* These aren't actual errors, treat it as a skipped-update instead
* to avoid triggering the post-core update failure routines.
// Core doesn't output this, so let's append it, so we don't get confused.
if ( is_wp_error( $upgrade_result ) ) {
$upgrade_result->add( 'installation_failed', __( 'Installation failed.' ) );
$skin->error( $upgrade_result );
$skin->feedback( __( 'WordPress updated successfully.' ) );
$is_debug = WP_DEBUG && WP_DEBUG_LOG;
if ( 'theme' === $type && $is_debug ) {
error_log( ' Theme ' . var_export( $item->theme, true ) . ' has been upgraded.' );
if ( 'plugin' === $type ) {
error_log( ' Plugin ' . var_export( $item->slug, true ) . ' has been upgraded.' );
if ( is_plugin_inactive( $upgrader_item ) ) {
error_log( ' ' . var_export( $upgrader_item, true ) . ' is inactive and will not be checked for fatal errors.' );
if ( $was_active && ! is_wp_error( $upgrade_result ) ) {
* The usual time limit is five minutes. However, as a loopback request
* is about to be performed, increase the time limit to account for this.
if ( function_exists( 'set_time_limit' ) ) {
set_time_limit( 10 * MINUTE_IN_SECONDS );
* Avoids a race condition when there are 2 sequential plugins that have
* fatal errors. It seems a slight delay is required for the loopback to
* use the updated plugin code in the request. This can cause the second
* plugin's fatal error checking to be inaccurate, and may also affect
* subsequent plugin checks.
if ( $this->has_fatal_error() ) {
$upgrade_result = new WP_Error();
$backup_restored = $upgrader->restore_temp_backup( $temp_backup );
if ( is_wp_error( $backup_restored ) ) {
'plugin_update_fatal_error_rollback_failed',
/* translators: %s: The plugin's slug. */
__( "The update for '%s' contained a fatal error. The previously installed version could not be restored." ),
$upgrade_result->merge_from( $backup_restored );
'plugin_update_fatal_error_rollback_successful',
/* translators: %s: The plugin's slug. */
__( "The update for '%s' contained a fatal error. The previously installed version has been restored." ),
$backup_deleted = $upgrader->delete_temp_backup( $temp_backup );
if ( is_wp_error( $backup_deleted ) ) {
$upgrade_result->merge_from( $backup_deleted );
* Should emails not be working, log the message(s) so that
* the log file contains context for the fatal error,
* and whether a rollback was performed.
* `trigger_error()` is not used as it outputs a stack trace
* to this location rather than to the fatal error, which will
* appear above this entry in the log file.
error_log( ' ' . implode( "\n", $upgrade_result->get_error_messages() ) );
error_log( ' The update for ' . var_export( $item->slug, true ) . ' has no fatal errors.' );
// All processes are complete. Allow visitors to browse the site again.
if ( 'translation' !== $type ) {
$upgrader->maintenance_mode( false );
$this->update_results[ $type ][] = (object) array(
'result' => $upgrade_result,
'messages' => $skin->get_upgrade_messages(),
* Kicks off the background update process, looping through all pending updates.
if ( $this->is_disabled() ) {
if ( ! is_main_network() || ! is_main_site() ) {
if ( ! WP_Upgrader::create_lock( 'auto_updater' ) ) {
$is_debug = WP_DEBUG && WP_DEBUG_LOG;
error_log( 'Automatic updates starting...' );
// Don't automatically run these things, as we'll handle it ourselves.
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
remove_action( 'upgrader_process_complete', 'wp_version_check' );
remove_action( 'upgrader_process_complete', 'wp_update_plugins' );
remove_action( 'upgrader_process_complete', 'wp_update_themes' );
wp_update_plugins(); // Check for plugin updates.
$plugin_updates = get_site_transient( 'update_plugins' );
if ( $plugin_updates && ! empty( $plugin_updates->response ) ) {
error_log( ' Automatic plugin updates starting...' );
foreach ( $plugin_updates->response as $plugin ) {
$this->update( 'plugin', $plugin );
// Force refresh of plugin update information.
wp_clean_plugins_cache();
error_log( ' Automatic plugin updates complete.' );
// Next, those themes we all love.
wp_update_themes(); // Check for theme updates.
$theme_updates = get_site_transient( 'update_themes' );
if ( $theme_updates && ! empty( $theme_updates->response ) ) {
error_log( ' Automatic theme updates starting...' );
foreach ( $theme_updates->response as $theme ) {
$this->update( 'theme', (object) $theme );
// Force refresh of theme update information.
error_log( ' Automatic theme updates complete.' );
error_log( 'Automatic updates complete.' );
// Next, process any core update.
wp_version_check(); // Check for core updates.
$core_update = find_core_auto_update();
$this->update( 'core', $core_update );
* Clean up, and check for any pending translations.
* (Core_Upgrader checks for core updates.)
if ( isset( $this->update_results['theme'] ) ) {
foreach ( $this->update_results['theme'] as $upgrade ) {
$theme_stats[ $upgrade->item->theme ] = ( true === $upgrade->result );
wp_update_themes( $theme_stats ); // Check for theme updates.
if ( isset( $this->update_results['plugin'] ) ) {
foreach ( $this->update_results['plugin'] as $upgrade ) {
$plugin_stats[ $upgrade->item->plugin ] = ( true === $upgrade->result );
wp_update_plugins( $plugin_stats ); // Check for plugin updates.
// Finally, process any new translations.
$language_updates = wp_get_translation_updates();
if ( $language_updates ) {
foreach ( $language_updates as $update ) {
$this->update( 'translation', $update );
// Clear existing caches.
wp_version_check(); // Check for core updates.
wp_update_themes(); // Check for theme updates.
wp_update_plugins(); // Check for plugin updates.
// Send debugging email to admin for all development installations.
if ( ! empty( $this->update_results ) ) {
$development_version = str_contains( get_bloginfo( 'version' ), '-' );
* Filters whether to send a debugging email for each automatic background update.
* @param bool $development_version By default, emails are sent if the
* install is a development version.
* Return false to avoid the email.
if ( apply_filters( 'automatic_updates_send_debug_email', $development_version ) ) {
$this->send_debug_email();
if ( ! empty( $this->update_results['core'] ) ) {
$this->after_core_update( $this->update_results['core'][0] );
} elseif ( ! empty( $this->update_results['plugin'] ) || ! empty( $this->update_results['theme'] ) ) {
$this->after_plugin_theme_update( $this->update_results );
* Fires after all automatic updates have run.
* @param array $update_results The results of all attempted updates.
do_action( 'automatic_updates_complete', $this->update_results );
WP_Upgrader::release_lock( 'auto_updater' );
* Checks whether to send an email and avoid processing future updates after
* attempting a core update.
* @param object $update_result The result of the core update. Includes the update offer and result.
protected function after_core_update( $update_result ) {
$wp_version = get_bloginfo( 'version' );
$core_update = $update_result->item;
$result = $update_result->result;
if ( ! is_wp_error( $result ) ) {
$this->send_email( 'success', $core_update );
$error_code = $result->get_error_code();
* Any of these WP_Error codes are critical failures, as in they occurred after we started to copy core files.
* We should not try to perform a background update again until there is a successful one-click update performed by the user.
if ( 'disk_full' === $error_code || str_contains( $error_code, '__copy_dir' ) ) {
} elseif ( 'rollback_was_required' === $error_code && is_wp_error( $result->get_error_data()->rollback ) ) {
// A rollback is only critical if it failed too.
$rollback_result = $result->get_error_data()->rollback;
} elseif ( str_contains( $error_code, 'do_rollback' ) ) {
'attempted' => $core_update->current,
'current' => $wp_version,
'error_code' => $error_code,
'error_data' => $result->get_error_data(),
if ( isset( $rollback_result ) ) {
$critical_data['rollback_code'] = $rollback_result->get_error_code();
$critical_data['rollback_data'] = $rollback_result->get_error_data();
update_site_option( 'auto_core_update_failed', $critical_data );
$this->send_email( 'critical', $core_update, $result );
* Any other WP_Error code (like download_failed or files_not_writable) occurs before
* we tried to copy over core files. Thus, the failures are early and graceful.
* We should avoid trying to perform a background update again for the same version.
* But we can try again if another version is released.
* For certain 'transient' failures, like download_failed, we should allow retries.
* In fact, let's schedule a special update for an hour from now. (It's possible
* the issue could actually be on WordPress.org's side.) If that one fails, then email.
$transient_failures = array( 'incompatible_archive', 'download_failed', 'insane_distro', 'locked' );
if ( in_array( $error_code, $transient_failures, true ) && ! get_site_option( 'auto_core_update_failed' ) ) {
wp_schedule_single_event( time() + HOUR_IN_SECONDS, 'wp_maybe_auto_update' );
$notified = get_site_option( 'auto_core_update_notified' );
// Don't notify if we've already notified the same email address of the same version of the same notification type.
&& 'fail' === $notified['type']
&& get_site_option( 'admin_email' ) === $notified['email']
&& $notified['version'] === $core_update->current
'auto_core_update_failed',
'attempted' => $core_update->current,
'current' => $wp_version,
'error_code' => $error_code,
'error_data' => $result->get_error_data(),
'retry' => in_array( $error_code, $transient_failures, true ),
$this->send_email( 'fail', $core_update, $result );
* Sends an email upon the completion or failure of a background core update.
* @param string $type The type of email to send. Can be one of 'success', 'fail', 'manual', 'critical'.
* @param object $core_update The update offer that was attempted.
* @param mixed $result Optional. The result for the core update. Can be WP_Error.
protected function send_email( $type, $core_update, $result = null ) {
'auto_core_update_notified',
'email' => get_site_option( 'admin_email' ),
'version' => $core_update->current,
$next_user_core_update = get_preferred_from_update_core();
// If the update transient is empty, use the update we just performed.
if ( ! $next_user_core_update ) {
$next_user_core_update = $core_update;
if ( 'upgrade' === $next_user_core_update->response
&& version_compare( $next_user_core_update->version, $core_update->version, '>' )
$newer_version_available = true;
$newer_version_available = false;
* Filters whether to send an email following an automatic background core update.
* @param bool $send Whether to send the email. Default true.
* @param string $type The type of email to send. Can be one of
* 'success', 'fail', 'critical'.
* @param object $core_update The update offer that was attempted.
* @param mixed $result The result for the core update. Can be WP_Error.
if ( 'manual' !== $type && ! apply_filters( 'auto_core_update_send_email', true, $type, $core_update, $result ) ) {
case 'success': // We updated.
/* translators: Site updated notification email subject. 1: Site title, 2: WordPress version. */
$subject = __( '[%1$s] Your site has updated to WordPress %2$s' );
case 'fail': // We tried to update but couldn't.
case 'manual': // We can't update (and made no attempt).
/* translators: Update available notification email subject. 1: Site title, 2: WordPress version. */
$subject = __( '[%1$s] WordPress %2$s is available. Please update!' );
case 'critical': // We tried to update, started to copy files, then things went wrong.
/* translators: Site down notification email subject. 1: Site title. */
$subject = __( '[%1$s] URGENT: Your site may be down due to a failed update' );
// If the auto-update is not to the latest version, say that the current version of WP is available instead.
$version = 'success' === $type ? $core_update->current : $next_user_core_update->current;
$subject = sprintf( $subject, wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $version );
/* translators: 1: Home URL, 2: WordPress version. */
__( 'Howdy! Your site at %1$s has been updated automatically to WordPress %2$s.' ),
if ( ! $newer_version_available ) {
$body .= __( 'No further action is needed on your part.' ) . ' ';
// Can only reference the About screen if their update was successful.
list( $about_version ) = explode( '-', $core_update->current, 2 );
/* translators: %s: WordPress version. */
$body .= sprintf( __( 'For more on version %s, see the About WordPress screen:' ), $about_version );
$body .= "\n" . admin_url( 'about.php' );
if ( $newer_version_available ) {
/* translators: %s: WordPress latest version. */
$body .= "\n\n" . sprintf( __( 'WordPress %s is also now available.' ), $next_user_core_update->current ) . ' ';
$body .= __( 'Updating is easy and only takes a few moments:' );
$body .= "\n" . network_admin_url( 'update-core.php' );
/* translators: 1: Home URL, 2: WordPress version. */
__( 'Please update your site at %1$s to WordPress %2$s.' ),
$next_user_core_update->current