29 global $wpdb, $wp_local_package; |
29 global $wpdb, $wp_local_package; |
30 // include an unmodified $wp_version |
30 // include an unmodified $wp_version |
31 include( ABSPATH . WPINC . '/version.php' ); |
31 include( ABSPATH . WPINC . '/version.php' ); |
32 $php_version = phpversion(); |
32 $php_version = phpversion(); |
33 |
33 |
34 $current = get_site_transient( 'update_core' ); |
34 $current = get_site_transient( 'update_core' ); |
35 $translations = wp_get_installed_translations( 'core' ); |
35 $translations = wp_get_installed_translations( 'core' ); |
36 |
36 |
37 // Invalidate the transient when $wp_version changes |
37 // Invalidate the transient when $wp_version changes |
38 if ( is_object( $current ) && $wp_version != $current->version_checked ) |
38 if ( is_object( $current ) && $wp_version != $current->version_checked ) { |
39 $current = false; |
39 $current = false; |
40 |
40 } |
41 if ( ! is_object($current) ) { |
41 |
42 $current = new stdClass; |
42 if ( ! is_object( $current ) ) { |
43 $current->updates = array(); |
43 $current = new stdClass; |
|
44 $current->updates = array(); |
44 $current->version_checked = $wp_version; |
45 $current->version_checked = $wp_version; |
45 } |
46 } |
46 |
47 |
47 if ( ! empty( $extra_stats ) ) |
48 if ( ! empty( $extra_stats ) ) { |
48 $force_check = true; |
49 $force_check = true; |
|
50 } |
49 |
51 |
50 // Wait 60 seconds between multiple version check requests |
52 // Wait 60 seconds between multiple version check requests |
51 $timeout = 60; |
53 $timeout = 60; |
52 $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked ); |
54 $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked ); |
53 if ( ! $force_check && $time_not_changed ) { |
55 if ( ! $force_check && $time_not_changed ) { |
54 return; |
56 return; |
55 } |
57 } |
56 |
58 |
65 |
67 |
66 // Update last_checked for current to prevent multiple blocking requests if request hangs |
68 // Update last_checked for current to prevent multiple blocking requests if request hangs |
67 $current->last_checked = time(); |
69 $current->last_checked = time(); |
68 set_site_transient( 'update_core', $current ); |
70 set_site_transient( 'update_core', $current ); |
69 |
71 |
70 if ( method_exists( $wpdb, 'db_version' ) ) |
72 if ( method_exists( $wpdb, 'db_version' ) ) { |
71 $mysql_version = preg_replace('/[^0-9.].*/', '', $wpdb->db_version()); |
73 $mysql_version = preg_replace( '/[^0-9.].*/', '', $wpdb->db_version() ); |
72 else |
74 } else { |
73 $mysql_version = 'N/A'; |
75 $mysql_version = 'N/A'; |
|
76 } |
74 |
77 |
75 if ( is_multisite() ) { |
78 if ( is_multisite() ) { |
76 $user_count = get_user_count(); |
79 $user_count = get_user_count(); |
77 $num_blogs = get_blog_count(); |
80 $num_blogs = get_blog_count(); |
78 $wp_install = network_site_url(); |
81 $wp_install = network_site_url(); |
79 $multisite_enabled = 1; |
82 $multisite_enabled = 1; |
80 } else { |
83 } else { |
81 $user_count = count_users(); |
84 $user_count = count_users(); |
82 $user_count = $user_count['total_users']; |
85 $user_count = $user_count['total_users']; |
83 $multisite_enabled = 0; |
86 $multisite_enabled = 0; |
84 $num_blogs = 1; |
87 $num_blogs = 1; |
85 $wp_install = home_url( '/' ); |
88 $wp_install = home_url( '/' ); |
86 } |
89 } |
87 |
90 |
88 $query = array( |
91 $query = array( |
89 'version' => $wp_version, |
92 'version' => $wp_version, |
90 'php' => $php_version, |
93 'php' => $php_version, |
123 |
126 |
124 $post_body = array( |
127 $post_body = array( |
125 'translations' => wp_json_encode( $translations ), |
128 'translations' => wp_json_encode( $translations ), |
126 ); |
129 ); |
127 |
130 |
128 if ( is_array( $extra_stats ) ) |
131 if ( is_array( $extra_stats ) ) { |
129 $post_body = array_merge( $post_body, $extra_stats ); |
132 $post_body = array_merge( $post_body, $extra_stats ); |
|
133 } |
130 |
134 |
131 $url = $http_url = 'http://api.wordpress.org/core/version-check/1.7/?' . http_build_query( $query, null, '&' ); |
135 $url = $http_url = 'http://api.wordpress.org/core/version-check/1.7/?' . http_build_query( $query, null, '&' ); |
132 if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) |
136 if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) { |
133 $url = set_url_scheme( $url, 'https' ); |
137 $url = set_url_scheme( $url, 'https' ); |
|
138 } |
134 |
139 |
135 $doing_cron = wp_doing_cron(); |
140 $doing_cron = wp_doing_cron(); |
136 |
141 |
137 $options = array( |
142 $options = array( |
138 'timeout' => $doing_cron ? 30 : 3, |
143 'timeout' => $doing_cron ? 30 : 3, |
139 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), |
144 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), |
140 'headers' => array( |
145 'headers' => array( |
141 'wp_install' => $wp_install, |
146 'wp_install' => $wp_install, |
142 'wp_blog' => home_url( '/' ) |
147 'wp_blog' => home_url( '/' ), |
143 ), |
148 ), |
144 'body' => $post_body, |
149 'body' => $post_body, |
145 ); |
150 ); |
146 |
151 |
147 $response = wp_remote_post( $url, $options ); |
152 $response = wp_remote_post( $url, $options ); |
148 if ( $ssl && is_wp_error( $response ) ) { |
153 if ( $ssl && is_wp_error( $response ) ) { |
149 trigger_error( |
154 trigger_error( |
170 |
175 |
171 $offers = $body['offers']; |
176 $offers = $body['offers']; |
172 |
177 |
173 foreach ( $offers as &$offer ) { |
178 foreach ( $offers as &$offer ) { |
174 foreach ( $offer as $offer_key => $value ) { |
179 foreach ( $offer as $offer_key => $value ) { |
175 if ( 'packages' == $offer_key ) |
180 if ( 'packages' == $offer_key ) { |
176 $offer['packages'] = (object) array_intersect_key( array_map( 'esc_url', $offer['packages'] ), |
181 $offer['packages'] = (object) array_intersect_key( |
177 array_fill_keys( array( 'full', 'no_content', 'new_bundled', 'partial', 'rollback' ), '' ) ); |
182 array_map( 'esc_url', $offer['packages'] ), |
178 elseif ( 'download' == $offer_key ) |
183 array_fill_keys( array( 'full', 'no_content', 'new_bundled', 'partial', 'rollback' ), '' ) |
|
184 ); |
|
185 } elseif ( 'download' == $offer_key ) { |
179 $offer['download'] = esc_url( $value ); |
186 $offer['download'] = esc_url( $value ); |
180 else |
187 } else { |
181 $offer[ $offer_key ] = esc_html( $value ); |
188 $offer[ $offer_key ] = esc_html( $value ); |
182 } |
189 } |
183 $offer = (object) array_intersect_key( $offer, array_fill_keys( array( 'response', 'download', 'locale', |
190 } |
184 'packages', 'current', 'version', 'php_version', 'mysql_version', 'new_bundled', 'partial_version', 'notify_email', 'support_email', 'new_files' ), '' ) ); |
191 $offer = (object) array_intersect_key( |
185 } |
192 $offer, |
186 |
193 array_fill_keys( |
187 $updates = new stdClass(); |
194 array( |
188 $updates->updates = $offers; |
195 'response', |
189 $updates->last_checked = time(); |
196 'download', |
|
197 'locale', |
|
198 'packages', |
|
199 'current', |
|
200 'version', |
|
201 'php_version', |
|
202 'mysql_version', |
|
203 'new_bundled', |
|
204 'partial_version', |
|
205 'notify_email', |
|
206 'support_email', |
|
207 'new_files', |
|
208 ), |
|
209 '' |
|
210 ) |
|
211 ); |
|
212 } |
|
213 |
|
214 $updates = new stdClass(); |
|
215 $updates->updates = $offers; |
|
216 $updates->last_checked = time(); |
190 $updates->version_checked = $wp_version; |
217 $updates->version_checked = $wp_version; |
191 |
218 |
192 if ( isset( $body['translations'] ) ) |
219 if ( isset( $body['translations'] ) ) { |
193 $updates->translations = $body['translations']; |
220 $updates->translations = $body['translations']; |
|
221 } |
194 |
222 |
195 set_site_transient( 'update_core', $updates ); |
223 set_site_transient( 'update_core', $updates ); |
196 |
224 |
197 if ( ! empty( $body['ttl'] ) ) { |
225 if ( ! empty( $body['ttl'] ) ) { |
198 $ttl = (int) $body['ttl']; |
226 $ttl = (int) $body['ttl']; |
227 |
260 |
228 // include an unmodified $wp_version |
261 // include an unmodified $wp_version |
229 include( ABSPATH . WPINC . '/version.php' ); |
262 include( ABSPATH . WPINC . '/version.php' ); |
230 |
263 |
231 // If running blog-side, bail unless we've not checked in the last 12 hours |
264 // If running blog-side, bail unless we've not checked in the last 12 hours |
232 if ( !function_exists( 'get_plugins' ) ) |
265 if ( ! function_exists( 'get_plugins' ) ) { |
233 require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
266 require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
234 |
267 } |
235 $plugins = get_plugins(); |
268 |
|
269 $plugins = get_plugins(); |
236 $translations = wp_get_installed_translations( 'plugins' ); |
270 $translations = wp_get_installed_translations( 'plugins' ); |
237 |
271 |
238 $active = get_option( 'active_plugins', array() ); |
272 $active = get_option( 'active_plugins', array() ); |
239 $current = get_site_transient( 'update_plugins' ); |
273 $current = get_site_transient( 'update_plugins' ); |
240 if ( ! is_object($current) ) |
274 if ( ! is_object( $current ) ) { |
241 $current = new stdClass; |
275 $current = new stdClass; |
242 |
276 } |
243 $new_option = new stdClass; |
277 |
|
278 $new_option = new stdClass; |
244 $new_option->last_checked = time(); |
279 $new_option->last_checked = time(); |
245 |
280 |
246 $doing_cron = wp_doing_cron(); |
281 $doing_cron = wp_doing_cron(); |
247 |
282 |
248 // Check for update on a different schedule, depending on the page. |
283 // Check for update on a different schedule, depending on the page. |
249 switch ( current_filter() ) { |
284 switch ( current_filter() ) { |
250 case 'upgrader_process_complete' : |
285 case 'upgrader_process_complete': |
251 $timeout = 0; |
286 $timeout = 0; |
252 break; |
287 break; |
253 case 'load-update-core.php' : |
288 case 'load-update-core.php': |
254 $timeout = MINUTE_IN_SECONDS; |
289 $timeout = MINUTE_IN_SECONDS; |
255 break; |
290 break; |
256 case 'load-plugins.php' : |
291 case 'load-plugins.php': |
257 case 'load-update.php' : |
292 case 'load-update.php': |
258 $timeout = HOUR_IN_SECONDS; |
293 $timeout = HOUR_IN_SECONDS; |
259 break; |
294 break; |
260 default : |
295 default: |
261 if ( $doing_cron ) { |
296 if ( $doing_cron ) { |
262 $timeout = 2 * HOUR_IN_SECONDS; |
297 $timeout = 2 * HOUR_IN_SECONDS; |
263 } else { |
298 } else { |
264 $timeout = 12 * HOUR_IN_SECONDS; |
299 $timeout = 12 * HOUR_IN_SECONDS; |
265 } |
300 } |
270 if ( $time_not_changed && ! $extra_stats ) { |
305 if ( $time_not_changed && ! $extra_stats ) { |
271 $plugin_changed = false; |
306 $plugin_changed = false; |
272 foreach ( $plugins as $file => $p ) { |
307 foreach ( $plugins as $file => $p ) { |
273 $new_option->checked[ $file ] = $p['Version']; |
308 $new_option->checked[ $file ] = $p['Version']; |
274 |
309 |
275 if ( !isset( $current->checked[ $file ] ) || strval($current->checked[ $file ]) !== strval($p['Version']) ) |
310 if ( ! isset( $current->checked[ $file ] ) || strval( $current->checked[ $file ] ) !== strval( $p['Version'] ) ) { |
276 $plugin_changed = true; |
311 $plugin_changed = true; |
277 } |
312 } |
278 |
313 } |
279 if ( isset ( $current->response ) && is_array( $current->response ) ) { |
314 |
|
315 if ( isset( $current->response ) && is_array( $current->response ) ) { |
280 foreach ( $current->response as $plugin_file => $update_details ) { |
316 foreach ( $current->response as $plugin_file => $update_details ) { |
281 if ( ! isset($plugins[ $plugin_file ]) ) { |
317 if ( ! isset( $plugins[ $plugin_file ] ) ) { |
282 $plugin_changed = true; |
318 $plugin_changed = true; |
283 break; |
319 break; |
284 } |
320 } |
285 } |
321 } |
286 } |
322 } |
316 // Three seconds, plus one extra second for every 10 plugins |
352 // Three seconds, plus one extra second for every 10 plugins |
317 $timeout = 3 + (int) ( count( $plugins ) / 10 ); |
353 $timeout = 3 + (int) ( count( $plugins ) / 10 ); |
318 } |
354 } |
319 |
355 |
320 $options = array( |
356 $options = array( |
321 'timeout' => $timeout, |
357 'timeout' => $timeout, |
322 'body' => array( |
358 'body' => array( |
323 'plugins' => wp_json_encode( $to_send ), |
359 'plugins' => wp_json_encode( $to_send ), |
324 'translations' => wp_json_encode( $translations ), |
360 'translations' => wp_json_encode( $translations ), |
325 'locale' => wp_json_encode( $locales ), |
361 'locale' => wp_json_encode( $locales ), |
326 'all' => wp_json_encode( true ), |
362 'all' => wp_json_encode( true ), |
327 ), |
363 ), |
328 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ) |
364 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), |
329 ); |
365 ); |
330 |
366 |
331 if ( $extra_stats ) { |
367 if ( $extra_stats ) { |
332 $options['body']['update_stats'] = wp_json_encode( $extra_stats ); |
368 $options['body']['update_stats'] = wp_json_encode( $extra_stats ); |
333 } |
369 } |
334 |
370 |
335 $url = $http_url = 'http://api.wordpress.org/plugins/update-check/1.1/'; |
371 $url = $http_url = 'http://api.wordpress.org/plugins/update-check/1.1/'; |
336 if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) |
372 if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) { |
337 $url = set_url_scheme( $url, 'https' ); |
373 $url = set_url_scheme( $url, 'https' ); |
|
374 } |
338 |
375 |
339 $raw_response = wp_remote_post( $url, $options ); |
376 $raw_response = wp_remote_post( $url, $options ); |
340 if ( $ssl && is_wp_error( $raw_response ) ) { |
377 if ( $ssl && is_wp_error( $raw_response ) ) { |
341 trigger_error( |
378 trigger_error( |
342 sprintf( |
379 sprintf( |
368 $plugin = (object) $plugin; |
405 $plugin = (object) $plugin; |
369 } |
406 } |
370 unset( $plugin ); |
407 unset( $plugin ); |
371 |
408 |
372 if ( is_array( $response ) ) { |
409 if ( is_array( $response ) ) { |
373 $new_option->response = $response['plugins']; |
410 $new_option->response = $response['plugins']; |
374 $new_option->translations = $response['translations']; |
411 $new_option->translations = $response['translations']; |
375 // TODO: Perhaps better to store no_update in a separate transient with an expiry? |
412 // TODO: Perhaps better to store no_update in a separate transient with an expiry? |
376 $new_option->no_update = $response['no_update']; |
413 $new_option->no_update = $response['no_update']; |
377 } else { |
414 } else { |
378 $new_option->response = array(); |
415 $new_option->response = array(); |
379 $new_option->translations = array(); |
416 $new_option->translations = array(); |
380 $new_option->no_update = array(); |
417 $new_option->no_update = array(); |
381 } |
418 } |
382 |
419 |
383 set_site_transient( 'update_plugins', $new_option ); |
420 set_site_transient( 'update_plugins', $new_option ); |
384 } |
421 } |
385 |
422 |
401 |
438 |
402 // include an unmodified $wp_version |
439 // include an unmodified $wp_version |
403 include( ABSPATH . WPINC . '/version.php' ); |
440 include( ABSPATH . WPINC . '/version.php' ); |
404 |
441 |
405 $installed_themes = wp_get_themes(); |
442 $installed_themes = wp_get_themes(); |
406 $translations = wp_get_installed_translations( 'themes' ); |
443 $translations = wp_get_installed_translations( 'themes' ); |
407 |
444 |
408 $last_update = get_site_transient( 'update_themes' ); |
445 $last_update = get_site_transient( 'update_themes' ); |
409 if ( ! is_object($last_update) ) |
446 if ( ! is_object( $last_update ) ) { |
410 $last_update = new stdClass; |
447 $last_update = new stdClass; |
|
448 } |
411 |
449 |
412 $themes = $checked = $request = array(); |
450 $themes = $checked = $request = array(); |
413 |
451 |
414 // Put slug of current theme into request. |
452 // Put slug of current theme into request. |
415 $request['active'] = get_option( 'stylesheet' ); |
453 $request['active'] = get_option( 'stylesheet' ); |
416 |
454 |
417 foreach ( $installed_themes as $theme ) { |
455 foreach ( $installed_themes as $theme ) { |
418 $checked[ $theme->get_stylesheet() ] = $theme->get('Version'); |
456 $checked[ $theme->get_stylesheet() ] = $theme->get( 'Version' ); |
419 |
457 |
420 $themes[ $theme->get_stylesheet() ] = array( |
458 $themes[ $theme->get_stylesheet() ] = array( |
421 'Name' => $theme->get('Name'), |
459 'Name' => $theme->get( 'Name' ), |
422 'Title' => $theme->get('Name'), |
460 'Title' => $theme->get( 'Name' ), |
423 'Version' => $theme->get('Version'), |
461 'Version' => $theme->get( 'Version' ), |
424 'Author' => $theme->get('Author'), |
462 'Author' => $theme->get( 'Author' ), |
425 'Author URI' => $theme->get('AuthorURI'), |
463 'Author URI' => $theme->get( 'AuthorURI' ), |
426 'Template' => $theme->get_template(), |
464 'Template' => $theme->get_template(), |
427 'Stylesheet' => $theme->get_stylesheet(), |
465 'Stylesheet' => $theme->get_stylesheet(), |
428 ); |
466 ); |
429 } |
467 } |
430 |
468 |
431 $doing_cron = wp_doing_cron(); |
469 $doing_cron = wp_doing_cron(); |
432 |
470 |
433 // Check for update on a different schedule, depending on the page. |
471 // Check for update on a different schedule, depending on the page. |
434 switch ( current_filter() ) { |
472 switch ( current_filter() ) { |
435 case 'upgrader_process_complete' : |
473 case 'upgrader_process_complete': |
436 $timeout = 0; |
474 $timeout = 0; |
437 break; |
475 break; |
438 case 'load-update-core.php' : |
476 case 'load-update-core.php': |
439 $timeout = MINUTE_IN_SECONDS; |
477 $timeout = MINUTE_IN_SECONDS; |
440 break; |
478 break; |
441 case 'load-themes.php' : |
479 case 'load-themes.php': |
442 case 'load-update.php' : |
480 case 'load-update.php': |
443 $timeout = HOUR_IN_SECONDS; |
481 $timeout = HOUR_IN_SECONDS; |
444 break; |
482 break; |
445 default : |
483 default: |
446 if ( $doing_cron ) { |
484 if ( $doing_cron ) { |
447 $timeout = 2 * HOUR_IN_SECONDS; |
485 $timeout = 2 * HOUR_IN_SECONDS; |
448 } else { |
486 } else { |
449 $timeout = 12 * HOUR_IN_SECONDS; |
487 $timeout = 12 * HOUR_IN_SECONDS; |
450 } |
488 } |
453 $time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time() - $last_update->last_checked ); |
491 $time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time() - $last_update->last_checked ); |
454 |
492 |
455 if ( $time_not_changed && ! $extra_stats ) { |
493 if ( $time_not_changed && ! $extra_stats ) { |
456 $theme_changed = false; |
494 $theme_changed = false; |
457 foreach ( $checked as $slug => $v ) { |
495 foreach ( $checked as $slug => $v ) { |
458 if ( !isset( $last_update->checked[ $slug ] ) || strval($last_update->checked[ $slug ]) !== strval($v) ) |
496 if ( ! isset( $last_update->checked[ $slug ] ) || strval( $last_update->checked[ $slug ] ) !== strval( $v ) ) { |
459 $theme_changed = true; |
497 $theme_changed = true; |
460 } |
498 } |
461 |
499 } |
462 if ( isset ( $last_update->response ) && is_array( $last_update->response ) ) { |
500 |
|
501 if ( isset( $last_update->response ) && is_array( $last_update->response ) ) { |
463 foreach ( $last_update->response as $slug => $update_details ) { |
502 foreach ( $last_update->response as $slug => $update_details ) { |
464 if ( ! isset($checked[ $slug ]) ) { |
503 if ( ! isset( $checked[ $slug ] ) ) { |
465 $theme_changed = true; |
504 $theme_changed = true; |
466 break; |
505 break; |
467 } |
506 } |
468 } |
507 } |
469 } |
508 } |
499 // Three seconds, plus one extra second for every 10 themes |
538 // Three seconds, plus one extra second for every 10 themes |
500 $timeout = 3 + (int) ( count( $themes ) / 10 ); |
539 $timeout = 3 + (int) ( count( $themes ) / 10 ); |
501 } |
540 } |
502 |
541 |
503 $options = array( |
542 $options = array( |
504 'timeout' => $timeout, |
543 'timeout' => $timeout, |
505 'body' => array( |
544 'body' => array( |
506 'themes' => wp_json_encode( $request ), |
545 'themes' => wp_json_encode( $request ), |
507 'translations' => wp_json_encode( $translations ), |
546 'translations' => wp_json_encode( $translations ), |
508 'locale' => wp_json_encode( $locales ), |
547 'locale' => wp_json_encode( $locales ), |
509 ), |
548 ), |
510 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ) |
549 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), |
511 ); |
550 ); |
512 |
551 |
513 if ( $extra_stats ) { |
552 if ( $extra_stats ) { |
514 $options['body']['update_stats'] = wp_json_encode( $extra_stats ); |
553 $options['body']['update_stats'] = wp_json_encode( $extra_stats ); |
515 } |
554 } |
516 |
555 |
517 $url = $http_url = 'http://api.wordpress.org/themes/update-check/1.1/'; |
556 $url = $http_url = 'http://api.wordpress.org/themes/update-check/1.1/'; |
518 if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) |
557 if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) { |
519 $url = set_url_scheme( $url, 'https' ); |
558 $url = set_url_scheme( $url, 'https' ); |
|
559 } |
520 |
560 |
521 $raw_response = wp_remote_post( $url, $options ); |
561 $raw_response = wp_remote_post( $url, $options ); |
522 if ( $ssl && is_wp_error( $raw_response ) ) { |
562 if ( $ssl && is_wp_error( $raw_response ) ) { |
523 trigger_error( |
563 trigger_error( |
524 sprintf( |
564 sprintf( |
553 * Performs WordPress automatic background updates. |
593 * Performs WordPress automatic background updates. |
554 * |
594 * |
555 * @since 3.7.0 |
595 * @since 3.7.0 |
556 */ |
596 */ |
557 function wp_maybe_auto_update() { |
597 function wp_maybe_auto_update() { |
558 include_once( ABSPATH . '/wp-admin/includes/admin.php' ); |
598 include_once( ABSPATH . 'wp-admin/includes/admin.php' ); |
559 include_once( ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' ); |
599 include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
560 |
600 |
561 $upgrader = new WP_Automatic_Updater; |
601 $upgrader = new WP_Automatic_Updater; |
562 $upgrader->run(); |
602 $upgrader->run(); |
563 } |
603 } |
564 |
604 |
565 /** |
605 /** |
566 * Retrieves a list of all language updates available. |
606 * Retrieves a list of all language updates available. |
567 * |
607 * |
568 * @since 3.7.0 |
608 * @since 3.7.0 |
569 * |
609 * |
570 * @return array |
610 * @return object[] Array of translation objects that have available updates. |
571 */ |
611 */ |
572 function wp_get_translation_updates() { |
612 function wp_get_translation_updates() { |
573 $updates = array(); |
613 $updates = array(); |
574 $transients = array( 'update_core' => 'core', 'update_plugins' => 'plugin', 'update_themes' => 'theme' ); |
614 $transients = array( |
|
615 'update_core' => 'core', |
|
616 'update_plugins' => 'plugin', |
|
617 'update_themes' => 'theme', |
|
618 ); |
575 foreach ( $transients as $transient => $type ) { |
619 foreach ( $transients as $transient => $type ) { |
576 $transient = get_site_transient( $transient ); |
620 $transient = get_site_transient( $transient ); |
577 if ( empty( $transient->translations ) ) |
621 if ( empty( $transient->translations ) ) { |
578 continue; |
622 continue; |
|
623 } |
579 |
624 |
580 foreach ( $transient->translations as $translation ) { |
625 foreach ( $transient->translations as $translation ) { |
581 $updates[] = (object) $translation; |
626 $updates[] = (object) $translation; |
582 } |
627 } |
583 } |
628 } |
590 * @since 3.3.0 |
635 * @since 3.3.0 |
591 * |
636 * |
592 * @return array |
637 * @return array |
593 */ |
638 */ |
594 function wp_get_update_data() { |
639 function wp_get_update_data() { |
595 $counts = array( 'plugins' => 0, 'themes' => 0, 'wordpress' => 0, 'translations' => 0 ); |
640 $counts = array( |
|
641 'plugins' => 0, |
|
642 'themes' => 0, |
|
643 'wordpress' => 0, |
|
644 'translations' => 0, |
|
645 ); |
596 |
646 |
597 if ( $plugins = current_user_can( 'update_plugins' ) ) { |
647 if ( $plugins = current_user_can( 'update_plugins' ) ) { |
598 $update_plugins = get_site_transient( 'update_plugins' ); |
648 $update_plugins = get_site_transient( 'update_plugins' ); |
599 if ( ! empty( $update_plugins->response ) ) |
649 if ( ! empty( $update_plugins->response ) ) { |
600 $counts['plugins'] = count( $update_plugins->response ); |
650 $counts['plugins'] = count( $update_plugins->response ); |
|
651 } |
601 } |
652 } |
602 |
653 |
603 if ( $themes = current_user_can( 'update_themes' ) ) { |
654 if ( $themes = current_user_can( 'update_themes' ) ) { |
604 $update_themes = get_site_transient( 'update_themes' ); |
655 $update_themes = get_site_transient( 'update_themes' ); |
605 if ( ! empty( $update_themes->response ) ) |
656 if ( ! empty( $update_themes->response ) ) { |
606 $counts['themes'] = count( $update_themes->response ); |
657 $counts['themes'] = count( $update_themes->response ); |
|
658 } |
607 } |
659 } |
608 |
660 |
609 if ( ( $core = current_user_can( 'update_core' ) ) && function_exists( 'get_core_updates' ) ) { |
661 if ( ( $core = current_user_can( 'update_core' ) ) && function_exists( 'get_core_updates' ) ) { |
610 $update_wordpress = get_core_updates( array('dismissed' => false) ); |
662 $update_wordpress = get_core_updates( array( 'dismissed' => false ) ); |
611 if ( ! empty( $update_wordpress ) && ! in_array( $update_wordpress[0]->response, array('development', 'latest') ) && current_user_can('update_core') ) |
663 if ( ! empty( $update_wordpress ) && ! in_array( $update_wordpress[0]->response, array( 'development', 'latest' ) ) && current_user_can( 'update_core' ) ) { |
612 $counts['wordpress'] = 1; |
664 $counts['wordpress'] = 1; |
613 } |
665 } |
614 |
666 } |
615 if ( ( $core || $plugins || $themes ) && wp_get_translation_updates() ) |
667 |
|
668 if ( ( $core || $plugins || $themes ) && wp_get_translation_updates() ) { |
616 $counts['translations'] = 1; |
669 $counts['translations'] = 1; |
|
670 } |
617 |
671 |
618 $counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress'] + $counts['translations']; |
672 $counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress'] + $counts['translations']; |
619 $titles = array(); |
673 $titles = array(); |
620 if ( $counts['wordpress'] ) { |
674 if ( $counts['wordpress'] ) { |
621 /* translators: 1: Number of updates available to WordPress */ |
675 /* translators: %d: number of updates available to WordPress */ |
622 $titles['wordpress'] = sprintf( __( '%d WordPress Update'), $counts['wordpress'] ); |
676 $titles['wordpress'] = sprintf( __( '%d WordPress Update' ), $counts['wordpress'] ); |
623 } |
677 } |
624 if ( $counts['plugins'] ) { |
678 if ( $counts['plugins'] ) { |
625 /* translators: 1: Number of updates available to plugins */ |
679 /* translators: %d: number of updates available to plugins */ |
626 $titles['plugins'] = sprintf( _n( '%d Plugin Update', '%d Plugin Updates', $counts['plugins'] ), $counts['plugins'] ); |
680 $titles['plugins'] = sprintf( _n( '%d Plugin Update', '%d Plugin Updates', $counts['plugins'] ), $counts['plugins'] ); |
627 } |
681 } |
628 if ( $counts['themes'] ) { |
682 if ( $counts['themes'] ) { |
629 /* translators: 1: Number of updates available to themes */ |
683 /* translators: %d: number of updates available to themes */ |
630 $titles['themes'] = sprintf( _n( '%d Theme Update', '%d Theme Updates', $counts['themes'] ), $counts['themes'] ); |
684 $titles['themes'] = sprintf( _n( '%d Theme Update', '%d Theme Updates', $counts['themes'] ), $counts['themes'] ); |
631 } |
685 } |
632 if ( $counts['translations'] ) { |
686 if ( $counts['translations'] ) { |
633 $titles['translations'] = __( 'Translation Updates' ); |
687 $titles['translations'] = __( 'Translation Updates' ); |
634 } |
688 } |
635 |
689 |
636 $update_title = $titles ? esc_attr( implode( ', ', $titles ) ) : ''; |
690 $update_title = $titles ? esc_attr( implode( ', ', $titles ) ) : ''; |
637 |
691 |
638 $update_data = array( 'counts' => $counts, 'title' => $update_title ); |
692 $update_data = array( |
|
693 'counts' => $counts, |
|
694 'title' => $update_title, |
|
695 ); |
639 /** |
696 /** |
640 * Filters the returned array of update data for plugins, themes, and WordPress core. |
697 * Filters the returned array of update data for plugins, themes, and WordPress core. |
641 * |
698 * |
642 * @since 3.5.0 |
699 * @since 3.5.0 |
643 * |
700 * |
698 * @since 2.7.0 |
756 * @since 2.7.0 |
699 * @access private |
757 * @access private |
700 */ |
758 */ |
701 function _maybe_update_themes() { |
759 function _maybe_update_themes() { |
702 $current = get_site_transient( 'update_themes' ); |
760 $current = get_site_transient( 'update_themes' ); |
703 if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) ) |
761 if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) ) { |
704 return; |
762 return; |
|
763 } |
705 wp_update_themes(); |
764 wp_update_themes(); |
706 } |
765 } |
707 |
766 |
708 /** |
767 /** |
709 * Schedule core, theme, and plugin update checks. |
768 * Schedule core, theme, and plugin update checks. |
710 * |
769 * |
711 * @since 3.1.0 |
770 * @since 3.1.0 |
712 */ |
771 */ |
713 function wp_schedule_update_checks() { |
772 function wp_schedule_update_checks() { |
714 if ( ! wp_next_scheduled( 'wp_version_check' ) && ! wp_installing() ) |
773 if ( ! wp_next_scheduled( 'wp_version_check' ) && ! wp_installing() ) { |
715 wp_schedule_event(time(), 'twicedaily', 'wp_version_check'); |
774 wp_schedule_event( time(), 'twicedaily', 'wp_version_check' ); |
716 |
775 } |
717 if ( ! wp_next_scheduled( 'wp_update_plugins' ) && ! wp_installing() ) |
776 |
718 wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins'); |
777 if ( ! wp_next_scheduled( 'wp_update_plugins' ) && ! wp_installing() ) { |
719 |
778 wp_schedule_event( time(), 'twicedaily', 'wp_update_plugins' ); |
720 if ( ! wp_next_scheduled( 'wp_update_themes' ) && ! wp_installing() ) |
779 } |
721 wp_schedule_event(time(), 'twicedaily', 'wp_update_themes'); |
780 |
|
781 if ( ! wp_next_scheduled( 'wp_update_themes' ) && ! wp_installing() ) { |
|
782 wp_schedule_event( time(), 'twicedaily', 'wp_update_themes' ); |
|
783 } |
722 } |
784 } |
723 |
785 |
724 /** |
786 /** |
725 * Clear existing update caches for plugins, themes, and core. |
787 * Clear existing update caches for plugins, themes, and core. |
726 * |
788 * |
753 add_action( 'load-update.php', 'wp_update_themes' ); |
815 add_action( 'load-update.php', 'wp_update_themes' ); |
754 add_action( 'load-update-core.php', 'wp_update_themes' ); |
816 add_action( 'load-update-core.php', 'wp_update_themes' ); |
755 add_action( 'admin_init', '_maybe_update_themes' ); |
817 add_action( 'admin_init', '_maybe_update_themes' ); |
756 add_action( 'wp_update_themes', 'wp_update_themes' ); |
818 add_action( 'wp_update_themes', 'wp_update_themes' ); |
757 |
819 |
758 add_action( 'update_option_WPLANG', 'wp_clean_update_cache' , 10, 0 ); |
820 add_action( 'update_option_WPLANG', 'wp_clean_update_cache', 10, 0 ); |
759 |
821 |
760 add_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' ); |
822 add_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' ); |
761 |
823 |
762 add_action( 'init', 'wp_schedule_update_checks' ); |
824 add_action( 'init', 'wp_schedule_update_checks' ); |