[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Upgrade API: WP_Automatic_Updater class 4 * 5 * @package WordPress 6 * @subpackage Upgrader 7 * @since 4.6.0 8 */ 9 10 /** 11 * Core class used for handling automatic background updates. 12 * 13 * @since 3.7.0 14 * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader.php. 15 */ 16 class WP_Automatic_Updater { 17 18 /** 19 * Tracks update results during processing. 20 * 21 * @var array 22 */ 23 protected $update_results = array(); 24 25 /** 26 * Whether the entire automatic updater is disabled. 27 * 28 * @since 3.7.0 29 */ 30 public function is_disabled() { 31 // Background updates are disabled if you don't want file changes. 32 if ( ! wp_is_file_mod_allowed( 'automatic_updater' ) ) { 33 return true; 34 } 35 36 if ( wp_installing() ) { 37 return true; 38 } 39 40 // More fine grained control can be done through the WP_AUTO_UPDATE_CORE constant and filters. 41 $disabled = defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED; 42 43 /** 44 * Filters whether to entirely disable background updates. 45 * 46 * There are more fine-grained filters and controls for selective disabling. 47 * This filter parallels the AUTOMATIC_UPDATER_DISABLED constant in name. 48 * 49 * This also disables update notification emails. That may change in the future. 50 * 51 * @since 3.7.0 52 * 53 * @param bool $disabled Whether the updater should be disabled. 54 */ 55 return apply_filters( 'automatic_updater_disabled', $disabled ); 56 } 57 58 /** 59 * Check for version control checkouts. 60 * 61 * Checks for Subversion, Git, Mercurial, and Bazaar. It recursively looks up the 62 * filesystem to the top of the drive, erring on the side of detecting a VCS 63 * checkout somewhere. 64 * 65 * ABSPATH is always checked in addition to whatever `$context` is (which may be the 66 * wp-content directory, for example). The underlying assumption is that if you are 67 * using version control *anywhere*, then you should be making decisions for 68 * how things get updated. 69 * 70 * @since 3.7.0 71 * 72 * @param string $context The filesystem path to check, in addition to ABSPATH. 73 * @return bool True if a VCS checkout was discovered at `$context` or ABSPATH, 74 * or anywhere higher. False otherwise. 75 */ 76 public function is_vcs_checkout( $context ) { 77 $context_dirs = array( untrailingslashit( $context ) ); 78 if ( ABSPATH !== $context ) { 79 $context_dirs[] = untrailingslashit( ABSPATH ); 80 } 81 82 $vcs_dirs = array( '.svn', '.git', '.hg', '.bzr' ); 83 $check_dirs = array(); 84 85 foreach ( $context_dirs as $context_dir ) { 86 // Walk up from $context_dir to the root. 87 do { 88 $check_dirs[] = $context_dir; 89 90 // Once we've hit '/' or 'C:\', we need to stop. dirname will keep returning the input here. 91 if ( dirname( $context_dir ) === $context_dir ) { 92 break; 93 } 94 95 // Continue one level at a time. 96 } while ( $context_dir = dirname( $context_dir ) ); 97 } 98 99 $check_dirs = array_unique( $check_dirs ); 100 101 // Search all directories we've found for evidence of version control. 102 foreach ( $vcs_dirs as $vcs_dir ) { 103 foreach ( $check_dirs as $check_dir ) { 104 $checkout = @is_dir( rtrim( $check_dir, '\\/' ) . "/$vcs_dir" ); 105 if ( $checkout ) { 106 break 2; 107 } 108 } 109 } 110 111 /** 112 * Filters whether the automatic updater should consider a filesystem 113 * location to be potentially managed by a version control system. 114 * 115 * @since 3.7.0 116 * 117 * @param bool $checkout Whether a VCS checkout was discovered at `$context` 118 * or ABSPATH, or anywhere higher. 119 * @param string $context The filesystem context (a path) against which 120 * filesystem status should be checked. 121 */ 122 return apply_filters( 'automatic_updates_is_vcs_checkout', $checkout, $context ); 123 } 124 125 /** 126 * Tests to see if we can and should update a specific item. 127 * 128 * @since 3.7.0 129 * 130 * @global wpdb $wpdb WordPress database abstraction object. 131 * 132 * @param string $type The type of update being checked: 'core', 'theme', 133 * 'plugin', 'translation'. 134 * @param object $item The update offer. 135 * @param string $context The filesystem context (a path) against which filesystem 136 * access and status should be checked. 137 * @return bool True if the item should be updated, false otherwise. 138 */ 139 public function should_update( $type, $item, $context ) { 140 // Used to see if WP_Filesystem is set up to allow unattended updates. 141 $skin = new Automatic_Upgrader_Skin; 142 143 if ( $this->is_disabled() ) { 144 return false; 145 } 146 147 // Only relax the filesystem checks when the update doesn't include new files. 148 $allow_relaxed_file_ownership = false; 149 if ( 'core' === $type && isset( $item->new_files ) && ! $item->new_files ) { 150 $allow_relaxed_file_ownership = true; 151 } 152 153 // If we can't do an auto core update, we may still be able to email the user. 154 if ( ! $skin->request_filesystem_credentials( false, $context, $allow_relaxed_file_ownership ) || $this->is_vcs_checkout( $context ) ) { 155 if ( 'core' === $type ) { 156 $this->send_core_update_notification_email( $item ); 157 } 158 return false; 159 } 160 161 // Next up, is this an item we can update? 162 if ( 'core' === $type ) { 163 $update = Core_Upgrader::should_update_to_version( $item->current ); 164 } elseif ( 'plugin' === $type || 'theme' === $type ) { 165 $update = ! empty( $item->autoupdate ); 166 167 if ( ! $update && wp_is_auto_update_enabled_for_type( $type ) ) { 168 // Check if the site admin has enabled auto-updates by default for the specific item. 169 $auto_updates = (array) get_site_option( "auto_update_{$type}s", array() ); 170 $update = in_array( $item->{$type}, $auto_updates, true ); 171 } 172 } else { 173 $update = ! empty( $item->autoupdate ); 174 } 175 176 // If the `disable_autoupdate` flag is set, override any user-choice, but allow filters. 177 if ( ! empty( $item->disable_autoupdate ) ) { 178 $update = $item->disable_autoupdate; 179 } 180 181 /** 182 * Filters whether to automatically update core, a plugin, a theme, or a language. 183 * 184 * The dynamic portion of the hook name, `$type`, refers to the type of update 185 * being checked. Potential hook names include: 186 * 187 * - `auto_update_core` 188 * - `auto_update_plugin` 189 * - `auto_update_theme` 190 * - `auto_update_translation` 191 * 192 * Generally speaking, plugins, themes, and major core versions are not updated 193 * by default, while translations and minor and development versions for core 194 * are updated by default. 195 * 196 * See the {@see 'allow_dev_auto_core_updates'}, {@see 'allow_minor_auto_core_updates'}, 197 * and {@see 'allow_major_auto_core_updates'} filters for a more straightforward way to 198 * adjust core updates. 199 * 200 * @since 3.7.0 201 * @since 5.5.0 The `$update` parameter accepts the value of null. 202 * 203 * @param bool|null $update Whether to update. The value of null is internally used 204 * to detect whether nothing has hooked into this filter. 205 * @param object $item The update offer. 206 */ 207 $update = apply_filters( "auto_update_{$type}", $update, $item ); 208 209 if ( ! $update ) { 210 if ( 'core' === $type ) { 211 $this->send_core_update_notification_email( $item ); 212 } 213 return false; 214 } 215 216 // If it's a core update, are we actually compatible with its requirements? 217 if ( 'core' === $type ) { 218 global $wpdb; 219 220 $php_compat = version_compare( phpversion(), $item->php_version, '>=' ); 221 if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) { 222 $mysql_compat = true; 223 } else { 224 $mysql_compat = version_compare( $wpdb->db_version(), $item->mysql_version, '>=' ); 225 } 226 227 if ( ! $php_compat || ! $mysql_compat ) { 228 return false; 229 } 230 } 231 232 // If updating a plugin or theme, ensure the minimum PHP version requirements are satisfied. 233 if ( in_array( $type, array( 'plugin', 'theme' ), true ) ) { 234 if ( ! empty( $item->requires_php ) && version_compare( phpversion(), $item->requires_php, '<' ) ) { 235 return false; 236 } 237 } 238 239 return true; 240 } 241 242 /** 243 * Notifies an administrator of a core update. 244 * 245 * @since 3.7.0 246 * 247 * @param object $item The update offer. 248 * @return bool True if the site administrator is notified of a core update, 249 * false otherwise. 250 */ 251 protected function send_core_update_notification_email( $item ) { 252 $notified = get_site_option( 'auto_core_update_notified' ); 253 254 // Don't notify if we've already notified the same email address of the same version. 255 if ( $notified && get_site_option( 'admin_email' ) === $notified['email'] && $notified['version'] == $item->current ) { 256 return false; 257 } 258 259 // See if we need to notify users of a core update. 260 $notify = ! empty( $item->notify_email ); 261 262 /** 263 * Filters whether to notify the site administrator of a new core update. 264 * 265 * By default, administrators are notified when the update offer received 266 * from WordPress.org sets a particular flag. This allows some discretion 267 * in if and when to notify. 268 * 269 * This filter is only evaluated once per release. If the same email address 270 * was already notified of the same new version, WordPress won't repeatedly 271 * email the administrator. 272 * 273 * This filter is also used on about.php to check if a plugin has disabled 274 * these notifications. 275 * 276 * @since 3.7.0 277 * 278 * @param bool $notify Whether the site administrator is notified. 279 * @param object $item The update offer. 280 */ 281 if ( ! apply_filters( 'send_core_update_notification_email', $notify, $item ) ) { 282 return false; 283 } 284 285 $this->send_email( 'manual', $item ); 286 return true; 287 } 288 289 /** 290 * Update an item, if appropriate. 291 * 292 * @since 3.7.0 293 * 294 * @param string $type The type of update being checked: 'core', 'theme', 'plugin', 'translation'. 295 * @param object $item The update offer. 296 * @return null|WP_Error 297 */ 298 public function update( $type, $item ) { 299 $skin = new Automatic_Upgrader_Skin; 300 301 switch ( $type ) { 302 case 'core': 303 // The Core upgrader doesn't use the Upgrader's skin during the actual main part of the upgrade, instead, firing a filter. 304 add_filter( 'update_feedback', array( $skin, 'feedback' ) ); 305 $upgrader = new Core_Upgrader( $skin ); 306 $context = ABSPATH; 307 break; 308 case 'plugin': 309 $upgrader = new Plugin_Upgrader( $skin ); 310 $context = WP_PLUGIN_DIR; // We don't support custom Plugin directories, or updates for WPMU_PLUGIN_DIR. 311 break; 312 case 'theme': 313 $upgrader = new Theme_Upgrader( $skin ); 314 $context = get_theme_root( $item->theme ); 315 break; 316 case 'translation': 317 $upgrader = new Language_Pack_Upgrader( $skin ); 318 $context = WP_CONTENT_DIR; // WP_LANG_DIR; 319 break; 320 } 321 322 // Determine whether we can and should perform this update. 323 if ( ! $this->should_update( $type, $item, $context ) ) { 324 return false; 325 } 326 327 /** 328 * Fires immediately prior to an auto-update. 329 * 330 * @since 4.4.0 331 * 332 * @param string $type The type of update being checked: 'core', 'theme', 'plugin', or 'translation'. 333 * @param object $item The update offer. 334 * @param string $context The filesystem context (a path) against which filesystem access and status 335 * should be checked. 336 */ 337 do_action( 'pre_auto_update', $type, $item, $context ); 338 339 $upgrader_item = $item; 340 switch ( $type ) { 341 case 'core': 342 /* translators: %s: WordPress version. */ 343 $skin->feedback( __( 'Updating to WordPress %s' ), $item->version ); 344 /* translators: %s: WordPress version. */ 345 $item_name = sprintf( __( 'WordPress %s' ), $item->version ); 346 break; 347 case 'theme': 348 $upgrader_item = $item->theme; 349 $theme = wp_get_theme( $upgrader_item ); 350 $item_name = $theme->Get( 'Name' ); 351 // Add the current version so that it can be reported in the notification email. 352 $item->current_version = $theme->get( 'Version' ); 353 if ( empty( $item->current_version ) ) { 354 $item->current_version = false; 355 } 356 /* translators: %s: Theme name. */ 357 $skin->feedback( __( 'Updating theme: %s' ), $item_name ); 358 break; 359 case 'plugin': 360 $upgrader_item = $item->plugin; 361 $plugin_data = get_plugin_data( $context . '/' . $upgrader_item ); 362 $item_name = $plugin_data['Name']; 363 // Add the current version so that it can be reported in the notification email. 364 $item->current_version = $plugin_data['Version']; 365 if ( empty( $item->current_version ) ) { 366 $item->current_version = false; 367 } 368 /* translators: %s: Plugin name. */ 369 $skin->feedback( __( 'Updating plugin: %s' ), $item_name ); 370 break; 371 case 'translation': 372 $language_item_name = $upgrader->get_name_for_update( $item ); 373 /* translators: %s: Project name (plugin, theme, or WordPress). */ 374 $item_name = sprintf( __( 'Translations for %s' ), $language_item_name ); 375 /* translators: 1: Project name (plugin, theme, or WordPress), 2: Language. */ 376 $skin->feedback( sprintf( __( 'Updating translations for %1$s (%2$s)…' ), $language_item_name, $item->language ) ); 377 break; 378 } 379 380 $allow_relaxed_file_ownership = false; 381 if ( 'core' === $type && isset( $item->new_files ) && ! $item->new_files ) { 382 $allow_relaxed_file_ownership = true; 383 } 384 385 // Boom, this site's about to get a whole new splash of paint! 386 $upgrade_result = $upgrader->upgrade( 387 $upgrader_item, 388 array( 389 'clear_update_cache' => false, 390 // Always use partial builds if possible for core updates. 391 'pre_check_md5' => false, 392 // Only available for core updates. 393 'attempt_rollback' => true, 394 // Allow relaxed file ownership in some scenarios. 395 'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership, 396 ) 397 ); 398 399 // If the filesystem is unavailable, false is returned. 400 if ( false === $upgrade_result ) { 401 $upgrade_result = new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) ); 402 } 403 404 if ( 'core' === $type ) { 405 if ( is_wp_error( $upgrade_result ) 406 && ( 'up_to_date' === $upgrade_result->get_error_code() 407 || 'locked' === $upgrade_result->get_error_code() ) 408 ) { 409 // These aren't actual errors, treat it as a skipped-update instead 410 // to avoid triggering the post-core update failure routines. 411 return false; 412 } 413 414 // Core doesn't output this, so let's append it so we don't get confused. 415 if ( is_wp_error( $upgrade_result ) ) { 416 $skin->error( __( 'Installation failed.' ), $upgrade_result ); 417 } else { 418 $skin->feedback( __( 'WordPress updated successfully.' ) ); 419 } 420 } 421 422 $this->update_results[ $type ][] = (object) array( 423 'item' => $item, 424 'result' => $upgrade_result, 425 'name' => $item_name, 426 'messages' => $skin->get_upgrade_messages(), 427 ); 428 429 return $upgrade_result; 430 } 431 432 /** 433 * Kicks off the background update process, looping through all pending updates. 434 * 435 * @since 3.7.0 436 */ 437 public function run() { 438 if ( $this->is_disabled() ) { 439 return; 440 } 441 442 if ( ! is_main_network() || ! is_main_site() ) { 443 return; 444 } 445 446 if ( ! WP_Upgrader::create_lock( 'auto_updater' ) ) { 447 return; 448 } 449 450 // Don't automatically run these things, as we'll handle it ourselves. 451 remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 ); 452 remove_action( 'upgrader_process_complete', 'wp_version_check' ); 453 remove_action( 'upgrader_process_complete', 'wp_update_plugins' ); 454 remove_action( 'upgrader_process_complete', 'wp_update_themes' ); 455 456 // Next, plugins. 457 wp_update_plugins(); // Check for plugin updates. 458 $plugin_updates = get_site_transient( 'update_plugins' ); 459 if ( $plugin_updates && ! empty( $plugin_updates->response ) ) { 460 foreach ( $plugin_updates->response as $plugin ) { 461 $this->update( 'plugin', $plugin ); 462 } 463 // Force refresh of plugin update information. 464 wp_clean_plugins_cache(); 465 } 466 467 // Next, those themes we all love. 468 wp_update_themes(); // Check for theme updates. 469 $theme_updates = get_site_transient( 'update_themes' ); 470 if ( $theme_updates && ! empty( $theme_updates->response ) ) { 471 foreach ( $theme_updates->response as $theme ) { 472 $this->update( 'theme', (object) $theme ); 473 } 474 // Force refresh of theme update information. 475 wp_clean_themes_cache(); 476 } 477 478 // Next, process any core update. 479 wp_version_check(); // Check for core updates. 480 $core_update = find_core_auto_update(); 481 482 if ( $core_update ) { 483 $this->update( 'core', $core_update ); 484 } 485 486 // Clean up, and check for any pending translations. 487 // (Core_Upgrader checks for core updates.) 488 $theme_stats = array(); 489 if ( isset( $this->update_results['theme'] ) ) { 490 foreach ( $this->update_results['theme'] as $upgrade ) { 491 $theme_stats[ $upgrade->item->theme ] = ( true === $upgrade->result ); 492 } 493 } 494 wp_update_themes( $theme_stats ); // Check for theme updates. 495 496 $plugin_stats = array(); 497 if ( isset( $this->update_results['plugin'] ) ) { 498 foreach ( $this->update_results['plugin'] as $upgrade ) { 499 $plugin_stats[ $upgrade->item->plugin ] = ( true === $upgrade->result ); 500 } 501 } 502 wp_update_plugins( $plugin_stats ); // Check for plugin updates. 503 504 // Finally, process any new translations. 505 $language_updates = wp_get_translation_updates(); 506 if ( $language_updates ) { 507 foreach ( $language_updates as $update ) { 508 $this->update( 'translation', $update ); 509 } 510 511 // Clear existing caches. 512 wp_clean_update_cache(); 513 514 wp_version_check(); // Check for core updates. 515 wp_update_themes(); // Check for theme updates. 516 wp_update_plugins(); // Check for plugin updates. 517 } 518 519 // Send debugging email to admin for all development installations. 520 if ( ! empty( $this->update_results ) ) { 521 $development_version = false !== strpos( get_bloginfo( 'version' ), '-' ); 522 523 /** 524 * Filters whether to send a debugging email for each automatic background update. 525 * 526 * @since 3.7.0 527 * 528 * @param bool $development_version By default, emails are sent if the 529 * install is a development version. 530 * Return false to avoid the email. 531 */ 532 if ( apply_filters( 'automatic_updates_send_debug_email', $development_version ) ) { 533 $this->send_debug_email(); 534 } 535 536 if ( ! empty( $this->update_results['core'] ) ) { 537 $this->after_core_update( $this->update_results['core'][0] ); 538 } elseif ( ! empty( $this->update_results['plugin'] ) || ! empty( $this->update_results['theme'] ) ) { 539 $this->after_plugin_theme_update( $this->update_results ); 540 } 541 542 /** 543 * Fires after all automatic updates have run. 544 * 545 * @since 3.8.0 546 * 547 * @param array $update_results The results of all attempted updates. 548 */ 549 do_action( 'automatic_updates_complete', $this->update_results ); 550 } 551 552 WP_Upgrader::release_lock( 'auto_updater' ); 553 } 554 555 /** 556 * If we tried to perform a core update, check if we should send an email, 557 * and if we need to avoid processing future updates. 558 * 559 * @since 3.7.0 560 * 561 * @param object $update_result The result of the core update. Includes the update offer and result. 562 */ 563 protected function after_core_update( $update_result ) { 564 $wp_version = get_bloginfo( 'version' ); 565 566 $core_update = $update_result->item; 567 $result = $update_result->result; 568 569 if ( ! is_wp_error( $result ) ) { 570 $this->send_email( 'success', $core_update ); 571 return; 572 } 573 574 $error_code = $result->get_error_code(); 575 576 // Any of these WP_Error codes are critical failures, as in they occurred after we started to copy core files. 577 // We should not try to perform a background update again until there is a successful one-click update performed by the user. 578 $critical = false; 579 if ( 'disk_full' === $error_code || false !== strpos( $error_code, '__copy_dir' ) ) { 580 $critical = true; 581 } elseif ( 'rollback_was_required' === $error_code && is_wp_error( $result->get_error_data()->rollback ) ) { 582 // A rollback is only critical if it failed too. 583 $critical = true; 584 $rollback_result = $result->get_error_data()->rollback; 585 } elseif ( false !== strpos( $error_code, 'do_rollback' ) ) { 586 $critical = true; 587 } 588 589 if ( $critical ) { 590 $critical_data = array( 591 'attempted' => $core_update->current, 592 'current' => $wp_version, 593 'error_code' => $error_code, 594 'error_data' => $result->get_error_data(), 595 'timestamp' => time(), 596 'critical' => true, 597 ); 598 if ( isset( $rollback_result ) ) { 599 $critical_data['rollback_code'] = $rollback_result->get_error_code(); 600 $critical_data['rollback_data'] = $rollback_result->get_error_data(); 601 } 602 update_site_option( 'auto_core_update_failed', $critical_data ); 603 $this->send_email( 'critical', $core_update, $result ); 604 return; 605 } 606 607 /* 608 * Any other WP_Error code (like download_failed or files_not_writable) occurs before 609 * we tried to copy over core files. Thus, the failures are early and graceful. 610 * 611 * We should avoid trying to perform a background update again for the same version. 612 * But we can try again if another version is released. 613 * 614 * For certain 'transient' failures, like download_failed, we should allow retries. 615 * In fact, let's schedule a special update for an hour from now. (It's possible 616 * the issue could actually be on WordPress.org's side.) If that one fails, then email. 617 */ 618 $send = true; 619 $transient_failures = array( 'incompatible_archive', 'download_failed', 'insane_distro', 'locked' ); 620 if ( in_array( $error_code, $transient_failures, true ) && ! get_site_option( 'auto_core_update_failed' ) ) { 621 wp_schedule_single_event( time() + HOUR_IN_SECONDS, 'wp_maybe_auto_update' ); 622 $send = false; 623 } 624 625 $n = get_site_option( 'auto_core_update_notified' ); 626 // Don't notify if we've already notified the same email address of the same version of the same notification type. 627 if ( $n && 'fail' === $n['type'] && get_site_option( 'admin_email' ) === $n['email'] && $n['version'] == $core_update->current ) { 628 $send = false; 629 } 630 631 update_site_option( 632 'auto_core_update_failed', 633 array( 634 'attempted' => $core_update->current, 635 'current' => $wp_version, 636 'error_code' => $error_code, 637 'error_data' => $result->get_error_data(), 638 'timestamp' => time(), 639 'retry' => in_array( $error_code, $transient_failures, true ), 640 ) 641 ); 642 643 if ( $send ) { 644 $this->send_email( 'fail', $core_update, $result ); 645 } 646 } 647 648 /** 649 * Sends an email upon the completion or failure of a background core update. 650 * 651 * @since 3.7.0 652 * 653 * @param string $type The type of email to send. Can be one of 'success', 'fail', 'manual', 'critical'. 654 * @param object $core_update The update offer that was attempted. 655 * @param mixed $result Optional. The result for the core update. Can be WP_Error. 656 */ 657 protected function send_email( $type, $core_update, $result = null ) { 658 update_site_option( 659 'auto_core_update_notified', 660 array( 661 'type' => $type, 662 'email' => get_site_option( 'admin_email' ), 663 'version' => $core_update->current, 664 'timestamp' => time(), 665 ) 666 ); 667 668 $next_user_core_update = get_preferred_from_update_core(); 669 670 // If the update transient is empty, use the update we just performed. 671 if ( ! $next_user_core_update ) { 672 $next_user_core_update = $core_update; 673 } 674 675 $newer_version_available = ( 'upgrade' === $next_user_core_update->response && version_compare( $next_user_core_update->version, $core_update->version, '>' ) ); 676 677 /** 678 * Filters whether to send an email following an automatic background core update. 679 * 680 * @since 3.7.0 681 * 682 * @param bool $send Whether to send the email. Default true. 683 * @param string $type The type of email to send. Can be one of 684 * 'success', 'fail', 'critical'. 685 * @param object $core_update The update offer that was attempted. 686 * @param mixed $result The result for the core update. Can be WP_Error. 687 */ 688 if ( 'manual' !== $type && ! apply_filters( 'auto_core_update_send_email', true, $type, $core_update, $result ) ) { 689 return; 690 } 691 692 switch ( $type ) { 693 case 'success': // We updated. 694 /* translators: Site updated notification email subject. 1: Site title, 2: WordPress version. */ 695 $subject = __( '[%1$s] Your site has updated to WordPress %2$s' ); 696 break; 697 698 case 'fail': // We tried to update but couldn't. 699 case 'manual': // We can't update (and made no attempt). 700 /* translators: Update available notification email subject. 1: Site title, 2: WordPress version. */ 701 $subject = __( '[%1$s] WordPress %2$s is available. Please update!' ); 702 break; 703 704 case 'critical': // We tried to update, started to copy files, then things went wrong. 705 /* translators: Site down notification email subject. 1: Site title. */ 706 $subject = __( '[%1$s] URGENT: Your site may be down due to a failed update' ); 707 break; 708 709 default: 710 return; 711 } 712 713 // If the auto-update is not to the latest version, say that the current version of WP is available instead. 714 $version = 'success' === $type ? $core_update->current : $next_user_core_update->current; 715 $subject = sprintf( $subject, wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), $version ); 716 717 $body = ''; 718 719 switch ( $type ) { 720 case 'success': 721 $body .= sprintf( 722 /* translators: 1: Home URL, 2: WordPress version. */ 723 __( 'Howdy! Your site at %1$s has been updated automatically to WordPress %2$s.' ), 724 home_url(), 725 $core_update->current 726 ); 727 $body .= "\n\n"; 728 if ( ! $newer_version_available ) { 729 $body .= __( 'No further action is needed on your part.' ) . ' '; 730 } 731 732 // Can only reference the About screen if their update was successful. 733 list( $about_version ) = explode( '-', $core_update->current, 2 ); 734 /* translators: %s: WordPress version. */ 735 $body .= sprintf( __( 'For more on version %s, see the About WordPress screen:' ), $about_version ); 736 $body .= "\n" . admin_url( 'about.php' ); 737 738 if ( $newer_version_available ) { 739 /* translators: %s: WordPress latest version. */ 740 $body .= "\n\n" . sprintf( __( 'WordPress %s is also now available.' ), $next_user_core_update->current ) . ' '; 741 $body .= __( 'Updating is easy and only takes a few moments:' ); 742 $body .= "\n" . network_admin_url( 'update-core.php' ); 743 } 744 745 break; 746 747 case 'fail': 748 case 'manual': 749 $body .= sprintf( 750 /* translators: 1: Home URL, 2: WordPress version. */ 751 __( 'Please update your site at %1$s to WordPress %2$s.' ), 752 home_url(), 753 $next_user_core_update->current 754 ); 755 756 $body .= "\n\n"; 757 758 // Don't show this message if there is a newer version available. 759 // Potential for confusion, and also not useful for them to know at this point. 760 if ( 'fail' === $type && ! $newer_version_available ) { 761 $body .= __( 'We tried but were unable to update your site automatically.' ) . ' '; 762 } 763 764 $body .= __( 'Updating is easy and only takes a few moments:' ); 765 $body .= "\n" . network_admin_url( 'update-core.php' ); 766 break; 767 768 case 'critical': 769 if ( $newer_version_available ) { 770 $body .= sprintf( 771 /* translators: 1: Home URL, 2: WordPress version. */ 772 __( 'Your site at %1$s experienced a critical failure while trying to update WordPress to version %2$s.' ), 773 home_url(), 774 $core_update->current 775 ); 776 } else { 777 $body .= sprintf( 778 /* translators: 1: Home URL, 2: WordPress latest version. */ 779 __( 'Your site at %1$s experienced a critical failure while trying to update to the latest version of WordPress, %2$s.' ), 780 home_url(), 781 $core_update->current 782 ); 783 } 784 785 $body .= "\n\n" . __( "This means your site may be offline or broken. Don't panic; this can be fixed." ); 786 787 $body .= "\n\n" . __( "Please check out your site now. It's possible that everything is working. If it says you need to update, you should do so:" ); 788 $body .= "\n" . network_admin_url( 'update-core.php' ); 789 break; 790 } 791 792 $critical_support = 'critical' === $type && ! empty( $core_update->support_email ); 793 if ( $critical_support ) { 794 // Support offer if available. 795 $body .= "\n\n" . sprintf( 796 /* translators: %s: Support email address. */ 797 __( 'The WordPress team is willing to help you. Forward this email to %s and the team will work with you to make sure your site is working.' ), 798 $core_update->support_email 799 ); 800 } else { 801 // Add a note about the support forums. 802 $body .= "\n\n" . __( 'If you experience any issues or need support, the volunteers in the WordPress.org support forums may be able to help.' ); 803 $body .= "\n" . __( 'https://wordpress.org/support/forums/' ); 804 } 805 806 // Updates are important! 807 if ( 'success' !== $type || $newer_version_available ) { 808 $body .= "\n\n" . __( 'Keeping your site updated is important for security. It also makes the internet a safer place for you and your readers.' ); 809 } 810 811 if ( $critical_support ) { 812 $body .= ' ' . __( "If you reach out to us, we'll also ensure you'll never have this problem again." ); 813 } 814 815 // If things are successful and we're now on the latest, mention plugins and themes if any are out of date. 816 if ( 'success' === $type && ! $newer_version_available && ( get_plugin_updates() || get_theme_updates() ) ) { 817 $body .= "\n\n" . __( 'You also have some plugins or themes with updates available. Update them now:' ); 818 $body .= "\n" . network_admin_url(); 819 } 820 821 $body .= "\n\n" . __( 'The WordPress Team' ) . "\n"; 822 823 if ( 'critical' === $type && is_wp_error( $result ) ) { 824 $body .= "\n***\n\n"; 825 /* translators: %s: WordPress version. */ 826 $body .= sprintf( __( 'Your site was running version %s.' ), get_bloginfo( 'version' ) ); 827 $body .= ' ' . __( 'We have some data that describes the error your site encountered.' ); 828 $body .= ' ' . __( 'Your hosting company, support forum volunteers, or a friendly developer may be able to use this information to help you:' ); 829 830 // If we had a rollback and we're still critical, then the rollback failed too. 831 // Loop through all errors (the main WP_Error, the update result, the rollback result) for code, data, etc. 832 if ( 'rollback_was_required' === $result->get_error_code() ) { 833 $errors = array( $result, $result->get_error_data()->update, $result->get_error_data()->rollback ); 834 } else { 835 $errors = array( $result ); 836 } 837 838 foreach ( $errors as $error ) { 839 if ( ! is_wp_error( $error ) ) { 840 continue; 841 } 842 843 $error_code = $error->get_error_code(); 844 /* translators: %s: Error code. */ 845 $body .= "\n\n" . sprintf( __( 'Error code: %s' ), $error_code ); 846 847 if ( 'rollback_was_required' === $error_code ) { 848 continue; 849 } 850 851 if ( $error->get_error_message() ) { 852 $body .= "\n" . $error->get_error_message(); 853 } 854 855 $error_data = $error->get_error_data(); 856 if ( $error_data ) { 857 $body .= "\n" . implode( ', ', (array) $error_data ); 858 } 859 } 860 861 $body .= "\n"; 862 } 863 864 $to = get_site_option( 'admin_email' ); 865 $headers = ''; 866 867 $email = compact( 'to', 'subject', 'body', 'headers' ); 868 869 /** 870 * Filters the email sent following an automatic background core update. 871 * 872 * @since 3.7.0 873 * 874 * @param array $email { 875 * Array of email arguments that will be passed to wp_mail(). 876 * 877 * @type string $to The email recipient. An array of emails 878 * can be returned, as handled by wp_mail(). 879 * @type string $subject The email's subject. 880 * @type string $body The email message body. 881 * @type string $headers Any email headers, defaults to no headers. 882 * } 883 * @param string $type The type of email being sent. Can be one of 884 * 'success', 'fail', 'manual', 'critical'. 885 * @param object $core_update The update offer that was attempted. 886 * @param mixed $result The result for the core update. Can be WP_Error. 887 */ 888 $email = apply_filters( 'auto_core_update_email', $email, $type, $core_update, $result ); 889 890 wp_mail( $email['to'], wp_specialchars_decode( $email['subject'] ), $email['body'], $email['headers'] ); 891 } 892 893 894 /** 895 * If we tried to perform plugin or theme updates, check if we should send an email. 896 * 897 * @since 5.5.0 898 * 899 * @param array $update_results The results of update tasks. 900 */ 901 protected function after_plugin_theme_update( $update_results ) { 902 $successful_updates = array(); 903 $failed_updates = array(); 904 905 if ( ! empty( $update_results['plugin'] ) ) { 906 /** 907 * Filters whether to send an email following an automatic background plugin update. 908 * 909 * @since 5.5.0 910 * @since 5.5.1 Added the `$update_results` parameter. 911 * 912 * @param bool $enabled True if plugin update notifications are enabled, false otherwise. 913 * @param array $update_results The results of plugins update tasks. 914 */ 915 $notifications_enabled = apply_filters( 'auto_plugin_update_send_email', true, $update_results['plugin'] ); 916 917 if ( $notifications_enabled ) { 918 foreach ( $update_results['plugin'] as $update_result ) { 919 if ( true === $update_result->result ) { 920 $successful_updates['plugin'][] = $update_result; 921 } else { 922 $failed_updates['plugin'][] = $update_result; 923 } 924 } 925 } 926 } 927 928 if ( ! empty( $update_results['theme'] ) ) { 929 /** 930 * Filters whether to send an email following an automatic background theme update. 931 * 932 * @since 5.5.0 933 * @since 5.5.1 Added the `$update_results` parameter. 934 * 935 * @param bool $enabled True if theme update notifications are enabled, false otherwise. 936 * @param array $update_results The results of theme update tasks. 937 */ 938 $notifications_enabled = apply_filters( 'auto_theme_update_send_email', true, $update_results['theme'] ); 939 940 if ( $notifications_enabled ) { 941 foreach ( $update_results['theme'] as $update_result ) { 942 if ( true === $update_result->result ) { 943 $successful_updates['theme'][] = $update_result; 944 } else { 945 $failed_updates['theme'][] = $update_result; 946 } 947 } 948 } 949 } 950 951 if ( empty( $successful_updates ) && empty( $failed_updates ) ) { 952 return; 953 } 954 955 if ( empty( $failed_updates ) ) { 956 $this->send_plugin_theme_email( 'success', $successful_updates, $failed_updates ); 957 } elseif ( empty( $successful_updates ) ) { 958 $this->send_plugin_theme_email( 'fail', $successful_updates, $failed_updates ); 959 } else { 960 $this->send_plugin_theme_email( 'mixed', $successful_updates, $failed_updates ); 961 } 962 } 963 964 /** 965 * Sends an email upon the completion or failure of a plugin or theme background update. 966 * 967 * @since 5.5.0 968 * 969 * @param string $type The type of email to send. Can be one of 'success', 'fail', 'mixed'. 970 * @param array $successful_updates A list of updates that succeeded. 971 * @param array $failed_updates A list of updates that failed. 972 */ 973 protected function send_plugin_theme_email( $type, $successful_updates, $failed_updates ) { 974 // No updates were attempted. 975 if ( empty( $successful_updates ) && empty( $failed_updates ) ) { 976 return; 977 } 978 979 $unique_failures = false; 980 $past_failure_emails = get_option( 'auto_plugin_theme_update_emails', array() ); 981 982 /* 983 * When only failures have occurred, an email should only be sent if there are unique failures. 984 * A failure is considered unique if an email has not been sent for an update attempt failure 985 * to a plugin or theme with the same new_version. 986 */ 987 if ( 'fail' === $type ) { 988 foreach ( $failed_updates as $update_type => $failures ) { 989 foreach ( $failures as $failed_update ) { 990 if ( ! isset( $past_failure_emails[ $failed_update->item->{$update_type} ] ) ) { 991 $unique_failures = true; 992 continue; 993 } 994 995 // Check that the failure represents a new failure based on the new_version. 996 if ( version_compare( $past_failure_emails[ $failed_update->item->{$update_type} ], $failed_update->item->new_version, '<' ) ) { 997 $unique_failures = true; 998 } 999 } 1000 } 1001 1002 if ( ! $unique_failures ) { 1003 return; 1004 } 1005 } 1006 1007 $body = array(); 1008 $successful_plugins = ( ! empty( $successful_updates['plugin'] ) ); 1009 $successful_themes = ( ! empty( $successful_updates['theme'] ) ); 1010 $failed_plugins = ( ! empty( $failed_updates['plugin'] ) ); 1011 $failed_themes = ( ! empty( $failed_updates['theme'] ) ); 1012 1013 switch ( $type ) { 1014 case 'success': 1015 if ( $successful_plugins && $successful_themes ) { 1016 /* translators: %s: Site title. */ 1017 $subject = __( '[%s] Some plugins and themes have automatically updated' ); 1018 $body[] = sprintf( 1019 /* translators: %s: Home URL. */ 1020 __( 'Howdy! Some plugins and themes have automatically updated to their latest versions on your site at %s. No further action is needed on your part.' ), 1021 home_url() 1022 ); 1023 } elseif ( $successful_plugins ) { 1024 /* translators: %s: Site title. */ 1025 $subject = __( '[%s] Some plugins were automatically updated' ); 1026 $body[] = sprintf( 1027 /* translators: %s: Home URL. */ 1028 __( 'Howdy! Some plugins have automatically updated to their latest versions on your site at %s. No further action is needed on your part.' ), 1029 home_url() 1030 ); 1031 } else { 1032 /* translators: %s: Site title. */ 1033 $subject = __( '[%s] Some themes were automatically updated' ); 1034 $body[] = sprintf( 1035 /* translators: %s: Home URL. */ 1036 __( 'Howdy! Some themes have automatically updated to their latest versions on your site at %s. No further action is needed on your part.' ), 1037 home_url() 1038 ); 1039 } 1040 1041 break; 1042 case 'fail': 1043 case 'mixed': 1044 if ( $failed_plugins && $failed_themes ) { 1045 /* translators: %s: Site title. */ 1046 $subject = __( '[%s] Some plugins and themes have failed to update' ); 1047 $body[] = sprintf( 1048 /* translators: %s: Home URL. */ 1049 __( 'Howdy! Plugins and themes failed to update on your site at %s.' ), 1050 home_url() 1051 ); 1052 } elseif ( $failed_plugins ) { 1053 /* translators: %s: Site title. */ 1054 $subject = __( '[%s] Some plugins have failed to update' ); 1055 $body[] = sprintf( 1056 /* translators: %s: Home URL. */ 1057 __( 'Howdy! Plugins failed to update on your site at %s.' ), 1058 home_url() 1059 ); 1060 } else { 1061 /* translators: %s: Site title. */ 1062 $subject = __( '[%s] Some themes have failed to update' ); 1063 $body[] = sprintf( 1064 /* translators: %s: Home URL. */ 1065 __( 'Howdy! Themes failed to update on your site at %s.' ), 1066 home_url() 1067 ); 1068 } 1069 1070 break; 1071 } 1072 1073 if ( in_array( $type, array( 'fail', 'mixed' ), true ) ) { 1074 $body[] = "\n"; 1075 $body[] = __( 'Please check your site now. It’s possible that everything is working. If there are updates available, you should update.' ); 1076 $body[] = "\n"; 1077 1078 // List failed plugin updates. 1079 if ( ! empty( $failed_updates['plugin'] ) ) { 1080 $body[] = __( 'These plugins failed to update:' ); 1081 1082 foreach ( $failed_updates['plugin'] as $item ) { 1083 if ( $item->item->current_version ) { 1084 $body[] = sprintf( 1085 /* translators: 1: Plugin name, 2: Current version number, 3: New version number. */ 1086 __( '- %1$s (from version %2$s to %3$s)' ), 1087 $item->name, 1088 $item->item->current_version, 1089 $item->item->new_version 1090 ); 1091 } else { 1092 $body[] = sprintf( 1093 /* translators: 1: Plugin name, 2: Version number. */ 1094 __( '- %1$s version %2$s' ), 1095 $item->name, 1096 $item->item->new_version 1097 ); 1098 } 1099 1100 $past_failure_emails[ $item->item->plugin ] = $item->item->new_version; 1101 } 1102 1103 $body[] = "\n"; 1104 } 1105 1106 // List failed theme updates. 1107 if ( ! empty( $failed_updates['theme'] ) ) { 1108 $body[] = __( 'These themes failed to update:' ); 1109 1110 foreach ( $failed_updates['theme'] as $item ) { 1111 if ( $item->item->current_version ) { 1112 $body[] = sprintf( 1113 /* translators: 1: Theme name, 2: Current version number, 3: New version number. */ 1114 __( '- %1$s (from version %2$s to %3$s)' ), 1115 $item->name, 1116 $item->item->current_version, 1117 $item->item->new_version 1118 ); 1119 } else { 1120 $body[] = sprintf( 1121 /* translators: 1: Theme name, 2: Version number. */ 1122 __( '- %1$s version %2$s' ), 1123 $item->name, 1124 $item->item->new_version 1125 ); 1126 } 1127 1128 $past_failure_emails[ $item->item->theme ] = $item->item->new_version; 1129 } 1130 1131 $body[] = "\n"; 1132 } 1133 } 1134 1135 // List successful updates. 1136 if ( in_array( $type, array( 'success', 'mixed' ), true ) ) { 1137 $body[] = "\n"; 1138 1139 // List successful plugin updates. 1140 if ( ! empty( $successful_updates['plugin'] ) ) { 1141 $body[] = __( 'These plugins are now up to date:' ); 1142 1143 foreach ( $successful_updates['plugin'] as $item ) { 1144 if ( $item->item->current_version ) { 1145 $body[] = sprintf( 1146 /* translators: 1: Plugin name, 2: Current version number, 3: New version number. */ 1147 __( '- %1$s (from version %2$s to %3$s)' ), 1148 $item->name, 1149 $item->item->current_version, 1150 $item->item->new_version 1151 ); 1152 } else { 1153 $body[] = sprintf( 1154 /* translators: 1: Plugin name, 2: Version number. */ 1155 __( '- %1$s version %2$s' ), 1156 $item->name, 1157 $item->item->new_version 1158 ); 1159 } 1160 1161 unset( $past_failure_emails[ $item->item->plugin ] ); 1162 } 1163 1164 $body[] = "\n"; 1165 } 1166 1167 // List successful theme updates. 1168 if ( ! empty( $successful_updates['theme'] ) ) { 1169 $body[] = __( 'These themes are now up to date:' ); 1170 1171 foreach ( $successful_updates['theme'] as $item ) { 1172 if ( $item->item->current_version ) { 1173 $body[] = sprintf( 1174 /* translators: 1: Theme name, 2: Current version number, 3: New version number. */ 1175 __( '- %1$s (from version %2$s to %3$s)' ), 1176 $item->name, 1177 $item->item->current_version, 1178 $item->item->new_version 1179 ); 1180 } else { 1181 $body[] = sprintf( 1182 /* translators: 1: Theme name, 2: Version number. */ 1183 __( '- %1$s version %2$s' ), 1184 $item->name, 1185 $item->item->new_version 1186 ); 1187 } 1188 1189 unset( $past_failure_emails[ $item->item->theme ] ); 1190 } 1191 1192 $body[] = "\n"; 1193 } 1194 } 1195 1196 if ( $failed_plugins ) { 1197 $body[] = sprintf( 1198 /* translators: %s: Plugins screen URL. */ 1199 __( 'To manage plugins on your site, visit the Plugins page: %s' ), 1200 admin_url( 'plugins.php' ) 1201 ); 1202 $body[] = "\n"; 1203 } 1204 1205 if ( $failed_themes ) { 1206 $body[] = sprintf( 1207 /* translators: %s: Themes screen URL. */ 1208 __( 'To manage themes on your site, visit the Themes page: %s' ), 1209 admin_url( 'themes.php' ) 1210 ); 1211 $body[] = "\n"; 1212 } 1213 1214 // Add a note about the support forums. 1215 $body[] = __( 'If you experience any issues or need support, the volunteers in the WordPress.org support forums may be able to help.' ); 1216 $body[] = __( 'https://wordpress.org/support/forums/' ); 1217 $body[] = "\n" . __( 'The WordPress Team' ); 1218 1219 $body = implode( "\n", $body ); 1220 $to = get_site_option( 'admin_email' ); 1221 $subject = sprintf( $subject, wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) ); 1222 $headers = ''; 1223 1224 $email = compact( 'to', 'subject', 'body', 'headers' ); 1225 1226 /** 1227 * Filters the email sent following an automatic background update for plugins and themes. 1228 * 1229 * @since 5.5.0 1230 * 1231 * @param array $email { 1232 * Array of email arguments that will be passed to wp_mail(). 1233 * 1234 * @type string $to The email recipient. An array of emails 1235 * can be returned, as handled by wp_mail(). 1236 * @type string $subject The email's subject. 1237 * @type string $body The email message body. 1238 * @type string $headers Any email headers, defaults to no headers. 1239 * } 1240 * @param string $type The type of email being sent. Can be one of 'success', 'fail', 'mixed'. 1241 * @param array $successful_updates A list of updates that succeeded. 1242 * @param array $failed_updates A list of updates that failed. 1243 */ 1244 $email = apply_filters( 'auto_plugin_theme_update_email', $email, $type, $successful_updates, $failed_updates ); 1245 1246 $result = wp_mail( $email['to'], wp_specialchars_decode( $email['subject'] ), $email['body'], $email['headers'] ); 1247 1248 if ( $result ) { 1249 update_option( 'auto_plugin_theme_update_emails', $past_failure_emails ); 1250 } 1251 } 1252 1253 /** 1254 * Prepares and sends an email of a full log of background update results, useful for debugging and geekery. 1255 * 1256 * @since 3.7.0 1257 */ 1258 protected function send_debug_email() { 1259 $update_count = 0; 1260 foreach ( $this->update_results as $type => $updates ) { 1261 $update_count += count( $updates ); 1262 } 1263 1264 $body = array(); 1265 $failures = 0; 1266 1267 /* translators: %s: Network home URL. */ 1268 $body[] = sprintf( __( 'WordPress site: %s' ), network_home_url( '/' ) ); 1269 1270 // Core. 1271 if ( isset( $this->update_results['core'] ) ) { 1272 $result = $this->update_results['core'][0]; 1273 if ( $result->result && ! is_wp_error( $result->result ) ) { 1274 /* translators: %s: WordPress version. */ 1275 $body[] = sprintf( __( 'SUCCESS: WordPress was successfully updated to %s' ), $result->name ); 1276 } else { 1277 /* translators: %s: WordPress version. */ 1278 $body[] = sprintf( __( 'FAILED: WordPress failed to update to %s' ), $result->name ); 1279 $failures++; 1280 } 1281 $body[] = ''; 1282 } 1283 1284 // Plugins, Themes, Translations. 1285 foreach ( array( 'plugin', 'theme', 'translation' ) as $type ) { 1286 if ( ! isset( $this->update_results[ $type ] ) ) { 1287 continue; 1288 } 1289 $success_items = wp_list_filter( $this->update_results[ $type ], array( 'result' => true ) ); 1290 if ( $success_items ) { 1291 $messages = array( 1292 'plugin' => __( 'The following plugins were successfully updated:' ), 1293 'theme' => __( 'The following themes were successfully updated:' ), 1294 'translation' => __( 'The following translations were successfully updated:' ), 1295 ); 1296 1297 $body[] = $messages[ $type ]; 1298 foreach ( wp_list_pluck( $success_items, 'name' ) as $name ) { 1299 /* translators: %s: Name of plugin / theme / translation. */ 1300 $body[] = ' * ' . sprintf( __( 'SUCCESS: %s' ), $name ); 1301 } 1302 } 1303 if ( $success_items != $this->update_results[ $type ] ) { 1304 // Failed updates. 1305 $messages = array( 1306 'plugin' => __( 'The following plugins failed to update:' ), 1307 'theme' => __( 'The following themes failed to update:' ), 1308 'translation' => __( 'The following translations failed to update:' ), 1309 ); 1310 1311 $body[] = $messages[ $type ]; 1312 foreach ( $this->update_results[ $type ] as $item ) { 1313 if ( ! $item->result || is_wp_error( $item->result ) ) { 1314 /* translators: %s: Name of plugin / theme / translation. */ 1315 $body[] = ' * ' . sprintf( __( 'FAILED: %s' ), $item->name ); 1316 $failures++; 1317 } 1318 } 1319 } 1320 $body[] = ''; 1321 } 1322 1323 $site_title = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); 1324 if ( $failures ) { 1325 $body[] = trim( 1326 __( 1327 "BETA TESTING? 1328 ============= 1329 1330 This debugging email is sent when you are using a development version of WordPress. 1331 1332 If you think these failures might be due to a bug in WordPress, could you report it? 1333 * Open a thread in the support forums: https://wordpress.org/support/forum/alphabeta 1334 * Or, if you're comfortable writing a bug report: https://core.trac.wordpress.org/ 1335 1336 Thanks! -- The WordPress Team" 1337 ) 1338 ); 1339 $body[] = ''; 1340 1341 /* translators: Background update failed notification email subject. %s: Site title. */ 1342 $subject = sprintf( __( '[%s] Background Update Failed' ), $site_title ); 1343 } else { 1344 /* translators: Background update finished notification email subject. %s: Site title. */ 1345 $subject = sprintf( __( '[%s] Background Update Finished' ), $site_title ); 1346 } 1347 1348 $body[] = trim( 1349 __( 1350 'UPDATE LOG 1351 ==========' 1352 ) 1353 ); 1354 $body[] = ''; 1355 1356 foreach ( array( 'core', 'plugin', 'theme', 'translation' ) as $type ) { 1357 if ( ! isset( $this->update_results[ $type ] ) ) { 1358 continue; 1359 } 1360 foreach ( $this->update_results[ $type ] as $update ) { 1361 $body[] = $update->name; 1362 $body[] = str_repeat( '-', strlen( $update->name ) ); 1363 foreach ( $update->messages as $message ) { 1364 $body[] = ' ' . html_entity_decode( str_replace( '…', '...', $message ) ); 1365 } 1366 if ( is_wp_error( $update->result ) ) { 1367 $results = array( 'update' => $update->result ); 1368 // If we rolled back, we want to know an error that occurred then too. 1369 if ( 'rollback_was_required' === $update->result->get_error_code() ) { 1370 $results = (array) $update->result->get_error_data(); 1371 } 1372 foreach ( $results as $result_type => $result ) { 1373 if ( ! is_wp_error( $result ) ) { 1374 continue; 1375 } 1376 1377 if ( 'rollback' === $result_type ) { 1378 /* translators: 1: Error code, 2: Error message. */ 1379 $body[] = ' ' . sprintf( __( 'Rollback Error: [%1$s] %2$s' ), $result->get_error_code(), $result->get_error_message() ); 1380 } else { 1381 /* translators: 1: Error code, 2: Error message. */ 1382 $body[] = ' ' . sprintf( __( 'Error: [%1$s] %2$s' ), $result->get_error_code(), $result->get_error_message() ); 1383 } 1384 1385 if ( $result->get_error_data() ) { 1386 $body[] = ' ' . implode( ', ', (array) $result->get_error_data() ); 1387 } 1388 } 1389 } 1390 $body[] = ''; 1391 } 1392 } 1393 1394 $email = array( 1395 'to' => get_site_option( 'admin_email' ), 1396 'subject' => $subject, 1397 'body' => implode( "\n", $body ), 1398 'headers' => '', 1399 ); 1400 1401 /** 1402 * Filters the debug email that can be sent following an automatic 1403 * background core update. 1404 * 1405 * @since 3.8.0 1406 * 1407 * @param array $email { 1408 * Array of email arguments that will be passed to wp_mail(). 1409 * 1410 * @type string $to The email recipient. An array of emails 1411 * can be returned, as handled by wp_mail(). 1412 * @type string $subject Email subject. 1413 * @type string $body Email message body. 1414 * @type string $headers Any email headers. Default empty. 1415 * } 1416 * @param int $failures The number of failures encountered while upgrading. 1417 * @param mixed $results The results of all attempted updates. 1418 */ 1419 $email = apply_filters( 'automatic_updates_debug_email', $email, $failures, $this->update_results ); 1420 1421 wp_mail( $email['to'], wp_specialchars_decode( $email['subject'] ), $email['body'], $email['headers'] ); 1422 } 1423 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Thu Jan 21 08:20:02 2021 | Cross-referenced by PHPXref |