]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/update.php
WordPress 3.9.1
[autoinstalls/wordpress.git] / wp-includes / update.php
1 <?php
2 /**
3  * A simple set of functions to check our version 1.0 update service.
4  *
5  * @package WordPress
6  * @since 2.3.0
7  */
8
9 /**
10  * Check WordPress version against the newest version.
11  *
12  * The WordPress version, PHP version, and Locale is sent. Checks against the
13  * WordPress server at api.wordpress.org server. Will only check if WordPress
14  * isn't installing.
15  *
16  * @since 2.3.0
17  * @uses $wp_version Used to check against the newest WordPress version.
18  *
19  * @param array $extra_stats Extra statistics to report to the WordPress.org API.
20  * @param bool $force_check Whether to bypass the transient cache and force a fresh update check. Defaults to false, true if $extra_stats is set.
21  * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
22  */
23 function wp_version_check( $extra_stats = array(), $force_check = false ) {
24         if ( defined('WP_INSTALLING') )
25                 return;
26
27         global $wpdb, $wp_local_package;
28         include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
29         $php_version = phpversion();
30
31         $current = get_site_transient( 'update_core' );
32         $translations = wp_get_installed_translations( 'core' );
33
34         // Invalidate the transient when $wp_version changes
35         if ( is_object( $current ) && $wp_version != $current->version_checked )
36                 $current = false;
37
38         if ( ! is_object($current) ) {
39                 $current = new stdClass;
40                 $current->updates = array();
41                 $current->version_checked = $wp_version;
42         }
43
44         if ( ! empty( $extra_stats ) )
45                 $force_check = true;
46
47         // Wait 60 seconds between multiple version check requests
48         $timeout = 60;
49         $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );
50         if ( ! $force_check && $time_not_changed )
51                 return false;
52
53         $locale = get_locale();
54         /**
55          * Filter the locale requested for WordPress core translations.
56          *
57          * @since 2.8.0
58          *
59          * @param string $locale Current locale.
60          */
61         $locale = apply_filters( 'core_version_check_locale', $locale );
62
63         // Update last_checked for current to prevent multiple blocking requests if request hangs
64         $current->last_checked = time();
65         set_site_transient( 'update_core', $current );
66
67         if ( method_exists( $wpdb, 'db_version' ) )
68                 $mysql_version = preg_replace('/[^0-9.].*/', '', $wpdb->db_version());
69         else
70                 $mysql_version = 'N/A';
71
72         if ( is_multisite() ) {
73                 $user_count = get_user_count();
74                 $num_blogs = get_blog_count();
75                 $wp_install = network_site_url();
76                 $multisite_enabled = 1;
77         } else {
78                 $user_count = count_users();
79                 $user_count = $user_count['total_users'];
80                 $multisite_enabled = 0;
81                 $num_blogs = 1;
82                 $wp_install = home_url( '/' );
83         }
84
85         $query = array(
86                 'version'           => $wp_version,
87                 'php'               => $php_version,
88                 'locale'            => $locale,
89                 'mysql'             => $mysql_version,
90                 'local_package'     => isset( $wp_local_package ) ? $wp_local_package : '',
91                 'blogs'             => $num_blogs,
92                 'users'             => $user_count,
93                 'multisite_enabled' => $multisite_enabled,
94         );
95
96         $post_body = array(
97                 'translations' => json_encode( $translations ),
98         );
99
100         if ( is_array( $extra_stats ) )
101                 $post_body = array_merge( $post_body, $extra_stats );
102
103         $url = $http_url = 'http://api.wordpress.org/core/version-check/1.7/?' . http_build_query( $query, null, '&' );
104         if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
105                 $url = set_url_scheme( $url, 'https' );
106
107         $options = array(
108                 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ),
109                 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
110                 'headers' => array(
111                         'wp_install' => $wp_install,
112                         'wp_blog' => home_url( '/' )
113                 ),
114                 'body' => $post_body,
115         );
116
117         $response = wp_remote_post( $url, $options );
118         if ( $ssl && is_wp_error( $response ) ) {
119                 trigger_error( __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE );
120                 $response = wp_remote_post( $http_url, $options );
121         }
122
123         if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
124                 return false;
125
126         $body = trim( wp_remote_retrieve_body( $response ) );
127         $body = json_decode( $body, true );
128
129         if ( ! is_array( $body ) || ! isset( $body['offers'] ) )
130                 return false;
131
132         $offers = $body['offers'];
133
134         foreach ( $offers as &$offer ) {
135                 foreach ( $offer as $offer_key => $value ) {
136                         if ( 'packages' == $offer_key )
137                                 $offer['packages'] = (object) array_intersect_key( array_map( 'esc_url', $offer['packages'] ),
138                                         array_fill_keys( array( 'full', 'no_content', 'new_bundled', 'partial', 'rollback' ), '' ) );
139                         elseif ( 'download' == $offer_key )
140                                 $offer['download'] = esc_url( $value );
141                         else
142                                 $offer[ $offer_key ] = esc_html( $value );
143                 }
144                 $offer = (object) array_intersect_key( $offer, array_fill_keys( array( 'response', 'download', 'locale',
145                         'packages', 'current', 'version', 'php_version', 'mysql_version', 'new_bundled', 'partial_version', 'notify_email', 'support_email' ), '' ) );
146         }
147
148         $updates = new stdClass();
149         $updates->updates = $offers;
150         $updates->last_checked = time();
151         $updates->version_checked = $wp_version;
152
153         if ( isset( $body['translations'] ) )
154                 $updates->translations = $body['translations'];
155
156         set_site_transient( 'update_core', $updates );
157
158         if ( ! empty( $body['ttl'] ) ) {
159                 $ttl = (int) $body['ttl'];
160                 if ( $ttl && ( time() + $ttl < wp_next_scheduled( 'wp_version_check' ) ) ) {
161                         // Queue an event to re-run the update check in $ttl seconds.
162                         wp_schedule_single_event( time() + $ttl, 'wp_version_check' );
163                 }
164         }
165
166         // Trigger a background updates check if running non-interactively, and we weren't called from the update handler.
167         if ( defined( 'DOING_CRON' ) && DOING_CRON && ! doing_action( 'wp_maybe_auto_update' ) ) {
168                 do_action( 'wp_maybe_auto_update' );
169         }
170 }
171
172 /**
173  * Check plugin versions against the latest versions hosted on WordPress.org.
174  *
175  * The WordPress version, PHP version, and Locale is sent along with a list of
176  * all plugins installed. Checks against the WordPress server at
177  * api.wordpress.org. Will only check if WordPress isn't installing.
178  *
179  * @since 2.3.0
180  * @uses $wp_version Used to notify the WordPress version.
181  *
182  * @param array $extra_stats Extra statistics to report to the WordPress.org API.
183  * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
184  */
185 function wp_update_plugins( $extra_stats = array() ) {
186         include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
187
188         if ( defined('WP_INSTALLING') )
189                 return false;
190
191         // If running blog-side, bail unless we've not checked in the last 12 hours
192         if ( !function_exists( 'get_plugins' ) )
193                 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
194
195         $plugins = get_plugins();
196         $translations = wp_get_installed_translations( 'plugins' );
197
198         $active  = get_option( 'active_plugins', array() );
199         $current = get_site_transient( 'update_plugins' );
200         if ( ! is_object($current) )
201                 $current = new stdClass;
202
203         $new_option = new stdClass;
204         $new_option->last_checked = time();
205
206         // Check for update on a different schedule, depending on the page.
207         switch ( current_filter() ) {
208                 case 'upgrader_process_complete' :
209                         $timeout = 0;
210                         break;
211                 case 'load-update-core.php' :
212                         $timeout = MINUTE_IN_SECONDS;
213                         break;
214                 case 'load-plugins.php' :
215                 case 'load-update.php' :
216                         $timeout = HOUR_IN_SECONDS;
217                         break;
218                 default :
219                         if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
220                                 $timeout = 0;
221                         } else {
222                                 $timeout = 12 * HOUR_IN_SECONDS;
223                         }
224         }
225
226         $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked );
227
228         if ( $time_not_changed && ! $extra_stats ) {
229                 $plugin_changed = false;
230                 foreach ( $plugins as $file => $p ) {
231                         $new_option->checked[ $file ] = $p['Version'];
232
233                         if ( !isset( $current->checked[ $file ] ) || strval($current->checked[ $file ]) !== strval($p['Version']) )
234                                 $plugin_changed = true;
235                 }
236
237                 if ( isset ( $current->response ) && is_array( $current->response ) ) {
238                         foreach ( $current->response as $plugin_file => $update_details ) {
239                                 if ( ! isset($plugins[ $plugin_file ]) ) {
240                                         $plugin_changed = true;
241                                         break;
242                                 }
243                         }
244                 }
245
246                 // Bail if we've checked recently and if nothing has changed
247                 if ( ! $plugin_changed )
248                         return false;
249         }
250
251         // Update last_checked for current to prevent multiple blocking requests if request hangs
252         $current->last_checked = time();
253         set_site_transient( 'update_plugins', $current );
254
255         $to_send = compact( 'plugins', 'active' );
256
257         $locales = array( get_locale() );
258         /**
259          * Filter the locales requested for plugin translations.
260          *
261          * @since 3.7.0
262          *
263          * @param array $locales Plugin locale. Default is current locale of the site.
264          */
265         $locales = apply_filters( 'plugins_update_check_locales', $locales );
266
267         $options = array(
268                 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
269                 'body' => array(
270                         'plugins'      => json_encode( $to_send ),
271                         'translations' => json_encode( $translations ),
272                         'locale'       => json_encode( $locales ),
273                 ),
274                 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
275         );
276
277         if ( $extra_stats ) {
278                 $options['body']['update_stats'] = json_encode( $extra_stats );
279         }
280
281         $url = $http_url = 'http://api.wordpress.org/plugins/update-check/1.1/';
282         if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
283                 $url = set_url_scheme( $url, 'https' );
284
285         $raw_response = wp_remote_post( $url, $options );
286         if ( $ssl && is_wp_error( $raw_response ) ) {
287                 trigger_error( __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE );
288                 $raw_response = wp_remote_post( $http_url, $options );
289         }
290
291         if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )
292                 return false;
293
294         $response = json_decode( wp_remote_retrieve_body( $raw_response ), true );
295         foreach ( $response['plugins'] as &$plugin ) {
296                 $plugin = (object) $plugin;
297         }
298         unset( $plugin );
299
300         if ( is_array( $response ) ) {
301                 $new_option->response = $response['plugins'];
302                 $new_option->translations = $response['translations'];
303         } else {
304                 $new_option->response = array();
305                 $new_option->translations = array();
306         }
307
308         set_site_transient( 'update_plugins', $new_option );
309 }
310
311 /**
312  * Check theme versions against the latest versions hosted on WordPress.org.
313  *
314  * A list of all themes installed in sent to WP. Checks against the
315  * WordPress server at api.wordpress.org. Will only check if WordPress isn't
316  * installing.
317  *
318  * @since 2.7.0
319  * @uses $wp_version Used to notify the WordPress version.
320  *
321  * @param array $extra_stats Extra statistics to report to the WordPress.org API.
322  * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
323  */
324 function wp_update_themes( $extra_stats = array() ) {
325         include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
326
327         if ( defined( 'WP_INSTALLING' ) )
328                 return false;
329
330         $installed_themes = wp_get_themes();
331         $translations = wp_get_installed_translations( 'themes' );
332
333         $last_update = get_site_transient( 'update_themes' );
334         if ( ! is_object($last_update) )
335                 $last_update = new stdClass;
336
337         $themes = $checked = $request = array();
338
339         // Put slug of current theme into request.
340         $request['active'] = get_option( 'stylesheet' );
341
342         foreach ( $installed_themes as $theme ) {
343                 $checked[ $theme->get_stylesheet() ] = $theme->get('Version');
344
345                 $themes[ $theme->get_stylesheet() ] = array(
346                         'Name'       => $theme->get('Name'),
347                         'Title'      => $theme->get('Name'),
348                         'Version'    => $theme->get('Version'),
349                         'Author'     => $theme->get('Author'),
350                         'Author URI' => $theme->get('AuthorURI'),
351                         'Template'   => $theme->get_template(),
352                         'Stylesheet' => $theme->get_stylesheet(),
353                 );
354         }
355
356         // Check for update on a different schedule, depending on the page.
357         switch ( current_filter() ) {
358                 case 'upgrader_process_complete' :
359                         $timeout = 0;
360                         break;
361                 case 'load-update-core.php' :
362                         $timeout = MINUTE_IN_SECONDS;
363                         break;
364                 case 'load-themes.php' :
365                 case 'load-update.php' :
366                         $timeout = HOUR_IN_SECONDS;
367                         break;
368                 default :
369                         if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
370                                 $timeout = 0;
371                         } else {
372                                 $timeout = 12 * HOUR_IN_SECONDS;
373                         }
374         }
375
376         $time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time() - $last_update->last_checked );
377
378         if ( $time_not_changed && ! $extra_stats ) {
379                 $theme_changed = false;
380                 foreach ( $checked as $slug => $v ) {
381                         if ( !isset( $last_update->checked[ $slug ] ) || strval($last_update->checked[ $slug ]) !== strval($v) )
382                                 $theme_changed = true;
383                 }
384
385                 if ( isset ( $last_update->response ) && is_array( $last_update->response ) ) {
386                         foreach ( $last_update->response as $slug => $update_details ) {
387                                 if ( ! isset($checked[ $slug ]) ) {
388                                         $theme_changed = true;
389                                         break;
390                                 }
391                         }
392                 }
393
394                 // Bail if we've checked recently and if nothing has changed
395                 if ( ! $theme_changed )
396                         return false;
397         }
398
399         // Update last_checked for current to prevent multiple blocking requests if request hangs
400         $last_update->last_checked = time();
401         set_site_transient( 'update_themes', $last_update );
402
403         $request['themes'] = $themes;
404
405         $locales = array( get_locale() );
406         /**
407          * Filter the locales requested for theme translations.
408          *
409          * @since 3.7.0
410          *
411          * @param array $locales Theme locale. Default is current locale of the site.
412          */
413         $locales = apply_filters( 'themes_update_check_locales', $locales );
414
415         $options = array(
416                 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
417                 'body' => array(
418                         'themes'       => json_encode( $request ),
419                         'translations' => json_encode( $translations ),
420                         'locale'       => json_encode( $locales ),
421                 ),
422                 'user-agent'    => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
423         );
424
425         if ( $extra_stats ) {
426                 $options['body']['update_stats'] = json_encode( $extra_stats );
427         }
428
429         $url = $http_url = 'http://api.wordpress.org/themes/update-check/1.1/';
430         if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
431                 $url = set_url_scheme( $url, 'https' );
432
433         $raw_response = wp_remote_post( $url, $options );
434         if ( $ssl && is_wp_error( $raw_response ) ) {
435                 trigger_error( __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE );
436                 $raw_response = wp_remote_post( $http_url, $options );
437         }
438
439         if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )
440                 return false;
441
442         $new_update = new stdClass;
443         $new_update->last_checked = time();
444         $new_update->checked = $checked;
445
446         $response = json_decode( wp_remote_retrieve_body( $raw_response ), true );
447
448         if ( is_array( $response ) ) {
449                 $new_update->response     = $response['themes'];
450                 $new_update->translations = $response['translations'];
451         }
452
453         set_site_transient( 'update_themes', $new_update );
454 }
455
456 /**
457  * Performs WordPress automatic background updates.
458  *
459  * @since 3.7.0
460  */
461 function wp_maybe_auto_update() {
462         include_once ABSPATH . '/wp-admin/includes/admin.php';
463         include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
464
465         $upgrader = new WP_Automatic_Updater;
466         $upgrader->run();
467 }
468
469 /**
470  * Retrieves a list of all language updates available.
471  *
472  * @since 3.7.0
473  */
474 function wp_get_translation_updates() {
475         $updates = array();
476         $transients = array( 'update_core' => 'core', 'update_plugins' => 'plugin', 'update_themes' => 'theme' );
477         foreach ( $transients as $transient => $type ) {
478
479                 $transient = get_site_transient( $transient );
480                 if ( empty( $transient->translations ) )
481                         continue;
482
483                 foreach ( $transient->translations as $translation ) {
484                         $updates[] = (object) $translation;
485                 }
486         }
487
488         return $updates;
489 }
490
491 /**
492  * Collect counts and UI strings for available updates
493  *
494  * @since 3.3.0
495  *
496  * @return array
497  */
498 function wp_get_update_data() {
499         $counts = array( 'plugins' => 0, 'themes' => 0, 'wordpress' => 0, 'translations' => 0 );
500
501         if ( $plugins = current_user_can( 'update_plugins' ) ) {
502                 $update_plugins = get_site_transient( 'update_plugins' );
503                 if ( ! empty( $update_plugins->response ) )
504                         $counts['plugins'] = count( $update_plugins->response );
505         }
506
507         if ( $themes = current_user_can( 'update_themes' ) ) {
508                 $update_themes = get_site_transient( 'update_themes' );
509                 if ( ! empty( $update_themes->response ) )
510                         $counts['themes'] = count( $update_themes->response );
511         }
512
513         if ( ( $core = current_user_can( 'update_core' ) ) && function_exists( 'get_core_updates' ) ) {
514                 $update_wordpress = get_core_updates( array('dismissed' => false) );
515                 if ( ! empty( $update_wordpress ) && ! in_array( $update_wordpress[0]->response, array('development', 'latest') ) && current_user_can('update_core') )
516                         $counts['wordpress'] = 1;
517         }
518
519         if ( ( $core || $plugins || $themes ) && wp_get_translation_updates() )
520                 $counts['translations'] = 1;
521
522         $counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress'] + $counts['translations'];
523         $titles = array();
524         if ( $counts['wordpress'] )
525                 $titles['wordpress'] = sprintf( __( '%d WordPress Update'), $counts['wordpress'] );
526         if ( $counts['plugins'] )
527                 $titles['plugins'] = sprintf( _n( '%d Plugin Update', '%d Plugin Updates', $counts['plugins'] ), $counts['plugins'] );
528         if ( $counts['themes'] )
529                 $titles['themes'] = sprintf( _n( '%d Theme Update', '%d Theme Updates', $counts['themes'] ), $counts['themes'] );
530         if ( $counts['translations'] )
531                 $titles['translations'] = __( 'Translation Updates' );
532
533         $update_title = $titles ? esc_attr( implode( ', ', $titles ) ) : '';
534
535         $update_data = array( 'counts' => $counts, 'title' => $update_title );
536         /**
537          * Filter the returned array of update data for plugins, themes, and WordPress core.
538          *
539          * @since 3.5.0
540          *
541          * @param array $update_data {
542          *     Fetched update data.
543          *
544          *     @type array   $counts       An array of counts for available plugin, theme, and WordPress updates.
545          *     @type string  $update_title Titles of available updates.
546          * }
547          * @param array $titles An array of update counts and UI strings for available updates.
548          */
549         return apply_filters( 'wp_get_update_data', $update_data, $titles );
550 }
551
552 function _maybe_update_core() {
553         include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
554
555         $current = get_site_transient( 'update_core' );
556
557         if ( isset( $current->last_checked ) &&
558                 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) &&
559                 isset( $current->version_checked ) &&
560                 $current->version_checked == $wp_version )
561                 return;
562
563         wp_version_check();
564 }
565 /**
566  * Check the last time plugins were run before checking plugin versions.
567  *
568  * This might have been backported to WordPress 2.6.1 for performance reasons.
569  * This is used for the wp-admin to check only so often instead of every page
570  * load.
571  *
572  * @since 2.7.0
573  * @access private
574  */
575 function _maybe_update_plugins() {
576         $current = get_site_transient( 'update_plugins' );
577         if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) )
578                 return;
579         wp_update_plugins();
580 }
581
582 /**
583  * Check themes versions only after a duration of time.
584  *
585  * This is for performance reasons to make sure that on the theme version
586  * checker is not run on every page load.
587  *
588  * @since 2.7.0
589  * @access private
590  */
591 function _maybe_update_themes() {
592         $current = get_site_transient( 'update_themes' );
593         if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) )
594                 return;
595
596         wp_update_themes();
597 }
598
599 /**
600  * Schedule core, theme, and plugin update checks.
601  *
602  * @since 3.1.0
603  */
604 function wp_schedule_update_checks() {
605         if ( !wp_next_scheduled('wp_version_check') && !defined('WP_INSTALLING') )
606                 wp_schedule_event(time(), 'twicedaily', 'wp_version_check');
607
608         if ( !wp_next_scheduled('wp_update_plugins') && !defined('WP_INSTALLING') )
609                 wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins');
610
611         if ( !wp_next_scheduled('wp_update_themes') && !defined('WP_INSTALLING') )
612                 wp_schedule_event(time(), 'twicedaily', 'wp_update_themes');
613
614         if ( ! wp_next_scheduled( 'wp_maybe_auto_update' ) && ! defined( 'WP_INSTALLING' ) ) {
615                 // Schedule auto updates for 7 a.m. and 7 p.m. in the timezone of the site.
616                 $next = strtotime( 'today 7am' );
617                 $now = time();
618                 // Find the next instance of 7 a.m. or 7 p.m., but skip it if it is within 3 hours from now.
619                 while ( ( $now + 3 * HOUR_IN_SECONDS ) > $next ) {
620                         $next += 12 * HOUR_IN_SECONDS;
621                 }
622                 $next = $next - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
623                 // Add a random number of minutes, so we don't have all sites trying to update exactly on the hour
624                 $next = $next + rand( 0, 59 ) * MINUTE_IN_SECONDS;
625                 wp_schedule_event( $next, 'twicedaily', 'wp_maybe_auto_update' );
626         }
627 }
628
629 if ( ( ! is_main_site() && ! is_network_admin() ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) )
630         return;
631
632 add_action( 'admin_init', '_maybe_update_core' );
633 add_action( 'wp_version_check', 'wp_version_check' );
634 add_action( 'upgrader_process_complete', 'wp_version_check', 10, 0 );
635
636 add_action( 'load-plugins.php', 'wp_update_plugins' );
637 add_action( 'load-update.php', 'wp_update_plugins' );
638 add_action( 'load-update-core.php', 'wp_update_plugins' );
639 add_action( 'admin_init', '_maybe_update_plugins' );
640 add_action( 'wp_update_plugins', 'wp_update_plugins' );
641 add_action( 'upgrader_process_complete', 'wp_update_plugins', 10, 0 );
642
643 add_action( 'load-themes.php', 'wp_update_themes' );
644 add_action( 'load-update.php', 'wp_update_themes' );
645 add_action( 'load-update-core.php', 'wp_update_themes' );
646 add_action( 'admin_init', '_maybe_update_themes' );
647 add_action( 'wp_update_themes', 'wp_update_themes' );
648 add_action( 'upgrader_process_complete', 'wp_update_themes', 10, 0 );
649
650 add_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' );
651
652 add_action('init', 'wp_schedule_update_checks');