30
30
public function is_disabled() {
31
31
// Background updates are disabled if you don't want file changes.
32
if ( ! wp_is_file_mod_allowed( 'automatic_updater' ) )
32
if ( ! wp_is_file_mod_allowed( 'automatic_updater' ) ) {
35
if ( wp_installing() )
36
if ( wp_installing() ) {
38
40
// More fine grained control can be done through the WP_AUTO_UPDATE_CORE constant and filters.
39
41
$disabled = defined( 'AUTOMATIC_UPDATER_DISABLED' ) && AUTOMATIC_UPDATER_DISABLED;
72
74
public function is_vcs_checkout( $context ) {
73
75
$context_dirs = array( untrailingslashit( $context ) );
74
if ( $context !== ABSPATH )
76
if ( $context !== ABSPATH ) {
75
77
$context_dirs[] = untrailingslashit( ABSPATH );
77
$vcs_dirs = array( '.svn', '.git', '.hg', '.bzr' );
80
$vcs_dirs = array( '.svn', '.git', '.hg', '.bzr' );
78
81
$check_dirs = array();
80
83
foreach ( $context_dirs as $context_dir ) {
83
86
$check_dirs[] = $context_dir;
85
88
// Once we've hit '/' or 'C:\', we need to stop. dirname will keep returning the input here.
86
if ( $context_dir == dirname( $context_dir ) )
89
if ( $context_dir == dirname( $context_dir ) ) {
89
// Continue one level at a time.
93
// Continue one level at a time.
90
94
} while ( $context_dir = dirname( $context_dir ) );
95
99
// Search all directories we've found for evidence of version control.
96
100
foreach ( $vcs_dirs as $vcs_dir ) {
97
101
foreach ( $check_dirs as $check_dir ) {
98
if ( $checkout = @is_dir( rtrim( $check_dir, '\\/' ) . "/$vcs_dir" ) )
102
if ( $checkout = @is_dir( rtrim( $check_dir, '\\/' ) . "/$vcs_dir" ) ) {
131
136
// Used to see if WP_Filesystem is set up to allow unattended updates.
132
137
$skin = new Automatic_Upgrader_Skin;
134
if ( $this->is_disabled() )
139
if ( $this->is_disabled() ) {
137
143
// Only relax the filesystem checks when the update doesn't include new files
138
144
$allow_relaxed_file_ownership = false;
143
149
// If we can't do an auto core update, we may still be able to email the user.
144
150
if ( ! $skin->request_filesystem_credentials( false, $context, $allow_relaxed_file_ownership ) || $this->is_vcs_checkout( $context ) ) {
145
if ( 'core' == $type )
151
if ( 'core' == $type ) {
146
152
$this->send_core_update_notification_email( $item );
150
157
// Next up, is this an item we can update?
151
if ( 'core' == $type )
158
if ( 'core' == $type ) {
152
159
$update = Core_Upgrader::should_update_to_version( $item->current );
154
161
$update = ! empty( $item->autoupdate );
157
165
* Filters whether to automatically update core, a plugin, a theme, or a language.
163
171
* by default, while translations and minor and development versions for core
164
172
* are updated by default.
166
* See the {@see 'allow_dev_auto_core_updates', {@see 'allow_minor_auto_core_updates'},
174
* See the {@see 'allow_dev_auto_core_updates'}, {@see 'allow_minor_auto_core_updates'},
167
175
* and {@see 'allow_major_auto_core_updates'} filters for a more straightforward way to
168
176
* adjust core updates.
187
196
$php_compat = version_compare( phpversion(), $item->php_version, '>=' );
188
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) )
197
if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) {
189
198
$mysql_compat = true;
191
200
$mysql_compat = version_compare( $wpdb->db_version(), $item->mysql_version, '>=' );
193
if ( ! $php_compat || ! $mysql_compat )
203
if ( ! $php_compat || ! $mysql_compat ) {
208
219
$notified = get_site_option( 'auto_core_update_notified' );
210
221
// Don't notify if we've already notified the same email address of the same version.
211
if ( $notified && $notified['email'] == get_site_option( 'admin_email' ) && $notified['version'] == $item->current )
222
if ( $notified && $notified['email'] == get_site_option( 'admin_email' ) && $notified['version'] == $item->current ) {
214
226
// See if we need to notify users of a core update.
215
227
$notify = ! empty( $item->notify_email );
233
245
* @param bool $notify Whether the site administrator is notified.
234
246
* @param object $item The update offer.
236
if ( ! apply_filters( 'send_core_update_notification_email', $notify, $item ) )
248
if ( ! apply_filters( 'send_core_update_notification_email', $notify, $item ) ) {
239
252
$this->send_email( 'manual', $item );
277
290
// Determine whether we can and should perform this update.
278
if ( ! $this->should_update( $type, $item, $context ) )
291
if ( ! $this->should_update( $type, $item, $context ) ) {
282
296
* Fires immediately prior to an auto-update.
293
307
$upgrader_item = $item;
294
308
switch ( $type ) {
310
/* translators: %s: WordPress version */
296
311
$skin->feedback( __( 'Updating to WordPress %s' ), $item->version );
312
/* translators: %s: WordPress version */
297
313
$item_name = sprintf( __( 'WordPress %s' ), $item->version );
300
316
$upgrader_item = $item->theme;
301
$theme = wp_get_theme( $upgrader_item );
302
$item_name = $theme->Get( 'Name' );
317
$theme = wp_get_theme( $upgrader_item );
318
$item_name = $theme->Get( 'Name' );
319
/* translators: %s: Theme name */
303
320
$skin->feedback( __( 'Updating theme: %s' ), $item_name );
306
323
$upgrader_item = $item->plugin;
307
$plugin_data = get_plugin_data( $context . '/' . $upgrader_item );
308
$item_name = $plugin_data['Name'];
324
$plugin_data = get_plugin_data( $context . '/' . $upgrader_item );
325
$item_name = $plugin_data['Name'];
326
/* translators: %s: Plugin name */
309
327
$skin->feedback( __( 'Updating plugin: %s' ), $item_name );
311
329
case 'translation':
312
330
$language_item_name = $upgrader->get_name_for_update( $item );
331
/* translators: %s: Name of language item */
313
332
$item_name = sprintf( __( 'Translations for %s' ), $language_item_name );
333
/* translators: 1: Name of language item, 2: Language */
314
334
$skin->feedback( sprintf( __( 'Updating translations for %1$s (%2$s)…' ), $language_item_name, $item->language ) );
323
343
// Boom, This sites about to get a whole new splash of paint!
324
$upgrade_result = $upgrader->upgrade( $upgrader_item, array(
325
'clear_update_cache' => false,
326
// Always use partial builds if possible for core updates.
327
'pre_check_md5' => false,
328
// Only available for core updates.
329
'attempt_rollback' => true,
330
// Allow relaxed file ownership in some scenarios
331
'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership,
344
$upgrade_result = $upgrader->upgrade(
347
'clear_update_cache' => false,
348
// Always use partial builds if possible for core updates.
349
'pre_check_md5' => false,
350
// Only available for core updates.
351
'attempt_rollback' => true,
352
// Allow relaxed file ownership in some scenarios
353
'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership,
334
357
// If the filesystem is unavailable, false is returned.
335
358
if ( false === $upgrade_result ) {
368
391
public function run() {
369
if ( $this->is_disabled() )
372
if ( ! is_main_network() || ! is_main_site() )
375
if ( ! WP_Upgrader::create_lock( 'auto_updater' ) )
392
if ( $this->is_disabled() ) {
396
if ( ! is_main_network() || ! is_main_site() ) {
400
if ( ! WP_Upgrader::create_lock( 'auto_updater' ) ) {
378
404
// Don't automatically run these thins, as we'll handle it ourselves
379
405
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
385
411
wp_update_plugins(); // Check for Plugin updates
386
412
$plugin_updates = get_site_transient( 'update_plugins' );
387
if ( $plugin_updates && !empty( $plugin_updates->response ) ) {
413
if ( $plugin_updates && ! empty( $plugin_updates->response ) ) {
388
414
foreach ( $plugin_updates->response as $plugin ) {
389
415
$this->update( 'plugin', $plugin );
395
421
// Next, those themes we all love
396
422
wp_update_themes(); // Check for Theme updates
397
423
$theme_updates = get_site_transient( 'update_themes' );
398
if ( $theme_updates && !empty( $theme_updates->response ) ) {
424
if ( $theme_updates && ! empty( $theme_updates->response ) ) {
399
425
foreach ( $theme_updates->response as $theme ) {
400
426
$this->update( 'theme', (object) $theme );
407
433
wp_version_check(); // Check for Core updates
408
434
$core_update = find_core_auto_update();
436
if ( $core_update ) {
411
437
$this->update( 'core', $core_update );
413
440
// Clean up, and check for any pending translations
414
441
// (Core_Upgrader checks for core updates)
456
483
* install is a development version.
457
484
* Return false to avoid the email.
459
if ( apply_filters( 'automatic_updates_send_debug_email', $development_version ) )
486
if ( apply_filters( 'automatic_updates_send_debug_email', $development_version ) ) {
460
487
$this->send_debug_email();
462
if ( ! empty( $this->update_results['core'] ) )
490
if ( ! empty( $this->update_results['core'] ) ) {
463
491
$this->after_core_update( $this->update_results['core'][0] );
466
495
* Fires after all automatic updates have run.
503
532
$critical = true;
504
533
} elseif ( $error_code === 'rollback_was_required' && is_wp_error( $result->get_error_data()->rollback ) ) {
505
534
// A rollback is only critical if it failed too.
507
536
$rollback_result = $result->get_error_data()->rollback;
508
537
} elseif ( false !== strpos( $error_code, 'do_rollback' ) ) {
509
538
$critical = true;
538
567
* In fact, let's schedule a special update for an hour from now. (It's possible
539
568
* the issue could actually be on WordPress.org's side.) If that one fails, then email.
542
$transient_failures = array( 'incompatible_archive', 'download_failed', 'insane_distro', 'locked' );
543
if ( in_array( $error_code, $transient_failures ) && ! get_site_option( 'auto_core_update_failed' ) ) {
544
wp_schedule_single_event( time() + HOUR_IN_SECONDS, 'wp_maybe_auto_update' );
571
$transient_failures = array( 'incompatible_archive', 'download_failed', 'insane_distro', 'locked' );
572
if ( in_array( $error_code, $transient_failures ) && ! get_site_option( 'auto_core_update_failed' ) ) {
573
wp_schedule_single_event( time() + HOUR_IN_SECONDS, 'wp_maybe_auto_update' );
548
$n = get_site_option( 'auto_core_update_notified' );
577
$n = get_site_option( 'auto_core_update_notified' );
549
578
// Don't notify if we've already notified the same email address of the same version of the same notification type.
550
if ( $n && 'fail' == $n['type'] && $n['email'] == get_site_option( 'admin_email' ) && $n['version'] == $core_update->current )
579
if ( $n && 'fail' == $n['type'] && $n['email'] == get_site_option( 'admin_email' ) && $n['version'] == $core_update->current ) {
553
update_site_option( 'auto_core_update_failed', array(
554
'attempted' => $core_update->current,
555
'current' => $wp_version,
556
'error_code' => $error_code,
557
'error_data' => $result->get_error_data(),
558
'timestamp' => time(),
559
'retry' => in_array( $error_code, $transient_failures ),
584
'auto_core_update_failed',
586
'attempted' => $core_update->current,
587
'current' => $wp_version,
588
'error_code' => $error_code,
589
'error_data' => $result->get_error_data(),
590
'timestamp' => time(),
591
'retry' => in_array( $error_code, $transient_failures ),
563
596
$this->send_email( 'fail', $core_update, $result );
573
607
* @param mixed $result Optional. The result for the core update. Can be WP_Error.
575
609
protected function send_email( $type, $core_update, $result = null ) {
576
update_site_option( 'auto_core_update_notified', array(
578
'email' => get_site_option( 'admin_email' ),
579
'version' => $core_update->current,
580
'timestamp' => time(),
611
'auto_core_update_notified',
614
'email' => get_site_option( 'admin_email' ),
615
'version' => $core_update->current,
616
'timestamp' => time(),
583
620
$next_user_core_update = get_preferred_from_update_core();
584
621
// If the update transient is empty, use the update we just performed
585
if ( ! $next_user_core_update )
622
if ( ! $next_user_core_update ) {
586
623
$next_user_core_update = $core_update;
587
625
$newer_version_available = ( 'upgrade' == $next_user_core_update->response && version_compare( $next_user_core_update->version, $core_update->version, '>' ) );
597
635
* @param object $core_update The update offer that was attempted.
598
636
* @param mixed $result The result for the core update. Can be WP_Error.
600
if ( 'manual' !== $type && ! apply_filters( 'auto_core_update_send_email', true, $type, $core_update, $result ) )
638
if ( 'manual' !== $type && ! apply_filters( 'auto_core_update_send_email', true, $type, $core_update, $result ) ) {
603
642
switch ( $type ) {
604
case 'success' : // We updated.
643
case 'success': // We updated.
605
644
/* translators: 1: Site name, 2: WordPress version number. */
606
645
$subject = __( '[%1$s] Your site has updated to WordPress %2$s' );
609
case 'fail' : // We tried to update but couldn't.
610
case 'manual' : // We can't update (and made no attempt).
648
case 'fail': // We tried to update but couldn't.
649
case 'manual': // We can't update (and made no attempt).
611
650
/* translators: 1: Site name, 2: WordPress version number. */
612
651
$subject = __( '[%1$s] WordPress %2$s is available. Please update!' );
615
case 'critical' : // We tried to update, started to copy files, then things went wrong.
654
case 'critical': // We tried to update, started to copy files, then things went wrong.
616
655
/* translators: 1: Site name. */
617
656
$subject = __( '[%1$s] URGENT: Your site may be down due to a failed update' );
630
669
switch ( $type ) {
671
/* translators: 1: Home URL, 2: WordPress version */
632
672
$body .= sprintf( __( 'Howdy! Your site at %1$s has been updated automatically to WordPress %2$s.' ), home_url(), $core_update->current );
634
if ( ! $newer_version_available )
674
if ( ! $newer_version_available ) {
635
675
$body .= __( 'No further action is needed on your part.' ) . ' ';
637
678
// Can only reference the About screen if their update was successful.
638
679
list( $about_version ) = explode( '-', $core_update->current, 2 );
639
$body .= sprintf( __( "For more on version %s, see the About WordPress screen:" ), $about_version );
680
/* translators: %s: WordPress core version */
681
$body .= sprintf( __( 'For more on version %s, see the About WordPress screen:' ), $about_version );
640
682
$body .= "\n" . admin_url( 'about.php' );
642
684
if ( $newer_version_available ) {
685
/* translators: %s: WordPress core latest version */
643
686
$body .= "\n\n" . sprintf( __( 'WordPress %s is also now available.' ), $next_user_core_update->current ) . ' ';
644
687
$body .= __( 'Updating is easy and only takes a few moments:' );
645
688
$body .= "\n" . network_admin_url( 'update-core.php' );
695
/* translators: 1: Home URL, 2: WordPress core latest version */
652
696
$body .= sprintf( __( 'Please update your site at %1$s to WordPress %2$s.' ), home_url(), $next_user_core_update->current );
656
700
// Don't show this message if there is a newer version available.
657
701
// Potential for confusion, and also not useful for them to know at this point.
658
if ( 'fail' == $type && ! $newer_version_available )
702
if ( 'fail' == $type && ! $newer_version_available ) {
659
703
$body .= __( 'We tried but were unable to update your site automatically.' ) . ' ';
661
706
$body .= __( 'Updating is easy and only takes a few moments:' );
662
707
$body .= "\n" . network_admin_url( 'update-core.php' );
666
if ( $newer_version_available )
711
if ( $newer_version_available ) {
712
/* translators: 1: Home URL, 2: WordPress core latest version */
667
713
$body .= sprintf( __( 'Your site at %1$s experienced a critical failure while trying to update WordPress to version %2$s.' ), home_url(), $core_update->current );
715
/* translators: 1: Home URL, 2: Core update version */
669
716
$body .= sprintf( __( 'Your site at %1$s experienced a critical failure while trying to update to the latest version of WordPress, %2$s.' ), home_url(), $core_update->current );
671
719
$body .= "\n\n" . __( "This means your site may be offline or broken. Don't panic; this can be fixed." );
678
726
$critical_support = 'critical' === $type && ! empty( $core_update->support_email );
679
727
if ( $critical_support ) {
680
728
// Support offer if available.
681
$body .= "\n\n" . sprintf( __( "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." ), $core_update->support_email );
729
/* translators: %s: Support e-mail */
730
$body .= "\n\n" . sprintf( __( '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.' ), $core_update->support_email );
683
732
// Add a note about the support forums.
684
733
$body .= "\n\n" . __( 'If you experience any issues or need support, the volunteers in the WordPress.org support forums may be able to help.' );
693
742
if ( $critical_support ) {
694
$body .= " " . __( "If you reach out to us, we'll also ensure you'll never have this problem again." );
743
$body .= ' ' . __( "If you reach out to us, we'll also ensure you'll never have this problem again." );
697
746
// If things are successful and we're now on the latest, mention plugins and themes if any are out of date.
705
754
if ( 'critical' == $type && is_wp_error( $result ) ) {
706
755
$body .= "\n***\n\n";
756
/* translators: %s: WordPress version */
707
757
$body .= sprintf( __( 'Your site was running version %s.' ), get_bloginfo( 'version' ) );
708
758
$body .= ' ' . __( 'We have some data that describes the error your site encountered.' );
709
759
$body .= ' ' . __( 'Your hosting company, support forum volunteers, or a friendly developer may be able to use this information to help you:' );
711
761
// If we had a rollback and we're still critical, then the rollback failed too.
712
762
// Loop through all errors (the main WP_Error, the update result, the rollback result) for code, data, etc.
713
if ( 'rollback_was_required' == $result->get_error_code() )
763
if ( 'rollback_was_required' == $result->get_error_code() ) {
714
764
$errors = array( $result, $result->get_error_data()->update, $result->get_error_data()->rollback );
716
766
$errors = array( $result );
718
769
foreach ( $errors as $error ) {
719
if ( ! is_wp_error( $error ) )
770
if ( ! is_wp_error( $error ) ) {
721
773
$error_code = $error->get_error_code();
722
$body .= "\n\n" . sprintf( __( "Error code: %s" ), $error_code );
723
if ( 'rollback_was_required' == $error_code )
774
/* translators: %s: Error code */
775
$body .= "\n\n" . sprintf( __( 'Error code: %s' ), $error_code );
776
if ( 'rollback_was_required' == $error_code ) {
725
if ( $error->get_error_message() )
779
if ( $error->get_error_message() ) {
726
780
$body .= "\n" . $error->get_error_message();
727
782
$error_data = $error->get_error_data();
729
784
$body .= "\n" . implode( ', ', (array) $error_data );
734
$to = get_site_option( 'admin_email' );
790
$to = get_site_option( 'admin_email' );
737
793
$email = compact( 'to', 'subject', 'body', 'headers' );
768
824
protected function send_debug_email() {
769
825
$update_count = 0;
770
foreach ( $this->update_results as $type => $updates )
826
foreach ( $this->update_results as $type => $updates ) {
771
827
$update_count += count( $updates );
833
/* translators: %s: Network home URL */
776
834
$body[] = sprintf( __( 'WordPress site: %s' ), network_home_url( '/' ) );
779
837
if ( isset( $this->update_results['core'] ) ) {
780
838
$result = $this->update_results['core'][0];
781
839
if ( $result->result && ! is_wp_error( $result->result ) ) {
840
/* translators: %s: WordPress core version */
782
841
$body[] = sprintf( __( 'SUCCESS: WordPress was successfully updated to %s' ), $result->name );
843
/* translators: %s: WordPress core version */
784
844
$body[] = sprintf( __( 'FAILED: WordPress failed to update to %s' ), $result->name );
790
850
// Plugins, Themes, Translations
791
851
foreach ( array( 'plugin', 'theme', 'translation' ) as $type ) {
792
if ( ! isset( $this->update_results[ $type ] ) )
852
if ( ! isset( $this->update_results[ $type ] ) ) {
794
855
$success_items = wp_list_filter( $this->update_results[ $type ], array( 'result' => true ) );
795
856
if ( $success_items ) {
796
857
$messages = array(
802
863
$body[] = $messages[ $type ];
803
864
foreach ( wp_list_pluck( $success_items, 'name' ) as $name ) {
865
/* translators: %s: name of plugin / theme / translations */
804
866
$body[] = ' * ' . sprintf( __( 'SUCCESS: %s' ), $name );
815
877
$body[] = $messages[ $type ];
816
878
foreach ( $this->update_results[ $type ] as $item ) {
817
879
if ( ! $item->result || is_wp_error( $item->result ) ) {
880
/* translators: %s: name of plugin / theme / translations */
818
881
$body[] = ' * ' . sprintf( __( 'FAILED: %s' ), $item->name );
835
899
* Open a thread in the support forums: https://wordpress.org/support/forum/alphabeta
836
900
* Or, if you're comfortable writing a bug report: https://core.trac.wordpress.org/
838
Thanks! -- The WordPress Team" ) );
902
Thanks! -- The WordPress Team"
907
/* translators: %s: site title */
841
908
$subject = sprintf( __( '[%s] There were failures during background updates' ), $site_title );
910
/* translators: %s: site title */
843
911
$subject = sprintf( __( '[%s] Background updates have finished' ), $site_title );
851
922
foreach ( array( 'core', 'plugin', 'theme', 'translation' ) as $type ) {
852
if ( ! isset( $this->update_results[ $type ] ) )
923
if ( ! isset( $this->update_results[ $type ] ) ) {
854
926
foreach ( $this->update_results[ $type ] as $update ) {
855
927
$body[] = $update->name;
856
928
$body[] = str_repeat( '-', strlen( $update->name ) );
857
foreach ( $update->messages as $message )
858
$body[] = " " . html_entity_decode( str_replace( '…', '...', $message ) );
929
foreach ( $update->messages as $message ) {
930
$body[] = ' ' . html_entity_decode( str_replace( '…', '...', $message ) );
859
932
if ( is_wp_error( $update->result ) ) {
860
933
$results = array( 'update' => $update->result );
861
934
// If we rolled back, we want to know an error that occurred then too.
862
if ( 'rollback_was_required' === $update->result->get_error_code() )
935
if ( 'rollback_was_required' === $update->result->get_error_code() ) {
863
936
$results = (array) $update->result->get_error_data();
864
938
foreach ( $results as $result_type => $result ) {
865
if ( ! is_wp_error( $result ) )
939
if ( ! is_wp_error( $result ) ) {
868
943
if ( 'rollback' === $result_type ) {
869
944
/* translators: 1: Error code, 2: Error message. */
873
948
$body[] = ' ' . sprintf( __( 'Error: [%1$s] %2$s' ), $result->get_error_code(), $result->get_error_message() );
876
if ( $result->get_error_data() )
951
if ( $result->get_error_data() ) {
877
952
$body[] = ' ' . implode( ', ', (array) $result->get_error_data() );