4 * |
4 * |
5 * @package WordPress |
5 * @package WordPress |
6 * @since 2.3.0 |
6 * @since 2.3.0 |
7 */ |
7 */ |
8 |
8 |
|
9 // Don't load directly. |
|
10 if ( ! defined( 'ABSPATH' ) ) { |
|
11 die( '-1' ); |
|
12 } |
|
13 |
9 /** |
14 /** |
10 * Checks WordPress version against the newest version. |
15 * Checks WordPress version against the newest version. |
11 * |
16 * |
12 * The WordPress version, PHP version, and locale is sent. |
17 * The WordPress version, PHP version, and locale is sent to api.wordpress.org. |
13 * |
18 * |
14 * Checks against the WordPress server at api.wordpress.org. Will only check |
19 * Checks against the WordPress server at api.wordpress.org. Will only check |
15 * if WordPress isn't installing. |
20 * if WordPress isn't installing. |
16 * |
21 * |
17 * @since 2.3.0 |
22 * @since 2.3.0 |
29 |
34 |
30 if ( wp_installing() ) { |
35 if ( wp_installing() ) { |
31 return; |
36 return; |
32 } |
37 } |
33 |
38 |
34 // Include an unmodified $wp_version. |
|
35 require ABSPATH . WPINC . '/version.php'; |
|
36 $php_version = PHP_VERSION; |
39 $php_version = PHP_VERSION; |
37 |
40 |
38 $current = get_site_transient( 'update_core' ); |
41 $current = get_site_transient( 'update_core' ); |
39 $translations = wp_get_installed_translations( 'core' ); |
42 $translations = wp_get_installed_translations( 'core' ); |
40 |
43 |
41 // Invalidate the transient when $wp_version changes. |
44 // Invalidate the transient when $wp_version changes. |
42 if ( is_object( $current ) && $wp_version !== $current->version_checked ) { |
45 if ( is_object( $current ) && wp_get_wp_version() !== $current->version_checked ) { |
43 $current = false; |
46 $current = false; |
44 } |
47 } |
45 |
48 |
46 if ( ! is_object( $current ) ) { |
49 if ( ! is_object( $current ) ) { |
47 $current = new stdClass(); |
50 $current = new stdClass(); |
48 $current->updates = array(); |
51 $current->updates = array(); |
49 $current->version_checked = $wp_version; |
52 $current->version_checked = wp_get_wp_version(); |
50 } |
53 } |
51 |
54 |
52 if ( ! empty( $extra_stats ) ) { |
55 if ( ! empty( $extra_stats ) ) { |
53 $force_check = true; |
56 $force_check = true; |
54 } |
57 } |
93 } |
96 } |
94 |
97 |
95 $extensions = get_loaded_extensions(); |
98 $extensions = get_loaded_extensions(); |
96 sort( $extensions, SORT_STRING | SORT_FLAG_CASE ); |
99 sort( $extensions, SORT_STRING | SORT_FLAG_CASE ); |
97 $query = array( |
100 $query = array( |
98 'version' => $wp_version, |
101 'version' => wp_get_wp_version(), |
99 'php' => $php_version, |
102 'php' => $php_version, |
100 'locale' => $locale, |
103 'locale' => $locale, |
101 'mysql' => $mysql_version, |
104 'mysql' => $mysql_version, |
102 'local_package' => isset( $wp_local_package ) ? $wp_local_package : '', |
105 'local_package' => isset( $wp_local_package ) ? $wp_local_package : '', |
103 'blogs' => $num_blogs, |
106 'blogs' => $num_blogs, |
115 if ( function_exists( 'gd_info' ) ) { |
118 if ( function_exists( 'gd_info' ) ) { |
116 $gd_info = gd_info(); |
119 $gd_info = gd_info(); |
117 // Filter to supported values. |
120 // Filter to supported values. |
118 $gd_info = array_filter( $gd_info ); |
121 $gd_info = array_filter( $gd_info ); |
119 |
122 |
120 // Add data for GD WebP and AVIF support. |
123 // Add data for GD WebP, AVIF, HEIC and JPEG XL support. |
121 $query['image_support']['gd'] = array_keys( |
124 $query['image_support']['gd'] = array_keys( |
122 array_filter( |
125 array_filter( |
123 array( |
126 array( |
124 'webp' => isset( $gd_info['WebP Support'] ), |
127 'webp' => isset( $gd_info['WebP Support'] ), |
125 'avif' => isset( $gd_info['AVIF Support'] ), |
128 'avif' => isset( $gd_info['AVIF Support'] ), |
|
129 'heic' => isset( $gd_info['HEIC Support'] ), |
|
130 'jxl' => isset( $gd_info['JXL Support'] ), |
126 ) |
131 ) |
127 ) |
132 ) |
128 ); |
133 ); |
129 } |
134 } |
130 |
135 |
131 if ( class_exists( 'Imagick' ) ) { |
136 if ( class_exists( 'Imagick' ) ) { |
132 // Add data for Imagick WebP and AVIF support. |
137 // Add data for Imagick WebP, AVIF, HEIC and JPEG XL support. |
133 $query['image_support']['imagick'] = array_keys( |
138 $query['image_support']['imagick'] = array_keys( |
134 array_filter( |
139 array_filter( |
135 array( |
140 array( |
136 'webp' => ! empty( Imagick::queryFormats( 'WEBP' ) ), |
141 'webp' => ! empty( Imagick::queryFormats( 'WEBP' ) ), |
137 'avif' => ! empty( Imagick::queryFormats( 'AVIF' ) ), |
142 'avif' => ! empty( Imagick::queryFormats( 'AVIF' ) ), |
|
143 'heic' => ! empty( Imagick::queryFormats( 'HEIC' ) ), |
|
144 'jxl' => ! empty( Imagick::queryFormats( 'JXL' ) ), |
138 ) |
145 ) |
139 ) |
146 ) |
140 ); |
147 ); |
141 } |
148 } |
142 |
149 |
145 * |
152 * |
146 * WARNING: Changing this data may result in your site not receiving security updates. |
153 * WARNING: Changing this data may result in your site not receiving security updates. |
147 * Please exercise extreme caution. |
154 * Please exercise extreme caution. |
148 * |
155 * |
149 * @since 4.9.0 |
156 * @since 4.9.0 |
|
157 * @since 6.1.0 Added `$extensions`, `$platform_flags`, and `$image_support` to the `$query` parameter. |
150 * |
158 * |
151 * @param array $query { |
159 * @param array $query { |
152 * Version check query arguments. |
160 * Version check query arguments. |
153 * |
161 * |
154 * @type string $version WordPress version number. |
162 * @type string $version WordPress version number. |
158 * @type string $local_package The value of the $wp_local_package global, when set. |
166 * @type string $local_package The value of the $wp_local_package global, when set. |
159 * @type int $blogs Number of sites on this WordPress installation. |
167 * @type int $blogs Number of sites on this WordPress installation. |
160 * @type int $users Number of users on this WordPress installation. |
168 * @type int $users Number of users on this WordPress installation. |
161 * @type int $multisite_enabled Whether this WordPress installation uses Multisite. |
169 * @type int $multisite_enabled Whether this WordPress installation uses Multisite. |
162 * @type int $initial_db_version Database version of WordPress at time of installation. |
170 * @type int $initial_db_version Database version of WordPress at time of installation. |
|
171 * @type array $extensions List of PHP extensions and their versions. |
|
172 * @type array $platform_flags List containing the operating system name and bit support. |
|
173 * @type array $image_support List of image formats supported by GD and Imagick. |
163 * } |
174 * } |
164 */ |
175 */ |
165 $query = apply_filters( 'core_version_check_query_args', $query ); |
176 $query = apply_filters( 'core_version_check_query_args', $query ); |
166 |
177 |
167 $post_body = array( |
178 $post_body = array( |
189 |
200 |
190 $doing_cron = wp_doing_cron(); |
201 $doing_cron = wp_doing_cron(); |
191 |
202 |
192 $options = array( |
203 $options = array( |
193 'timeout' => $doing_cron ? 30 : 3, |
204 'timeout' => $doing_cron ? 30 : 3, |
194 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), |
205 'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ), |
195 'headers' => array( |
206 'headers' => array( |
196 'wp_install' => $wp_install, |
207 'wp_install' => $wp_install, |
197 'wp_blog' => home_url( '/' ), |
208 'wp_blog' => home_url( '/' ), |
198 ), |
209 ), |
199 'body' => $post_body, |
210 'body' => $post_body, |
264 } |
275 } |
265 |
276 |
266 $updates = new stdClass(); |
277 $updates = new stdClass(); |
267 $updates->updates = $offers; |
278 $updates->updates = $offers; |
268 $updates->last_checked = time(); |
279 $updates->last_checked = time(); |
269 $updates->version_checked = $wp_version; |
280 $updates->version_checked = wp_get_wp_version(); |
270 |
281 |
271 if ( isset( $body['translations'] ) ) { |
282 if ( isset( $body['translations'] ) ) { |
272 $updates->translations = $body['translations']; |
283 $updates->translations = $body['translations']; |
273 } |
284 } |
274 |
285 |
297 /** |
308 /** |
298 * Checks for available updates to plugins based on the latest versions hosted on WordPress.org. |
309 * Checks for available updates to plugins based on the latest versions hosted on WordPress.org. |
299 * |
310 * |
300 * Despite its name this function does not actually perform any updates, it only checks for available updates. |
311 * Despite its name this function does not actually perform any updates, it only checks for available updates. |
301 * |
312 * |
302 * A list of all plugins installed is sent to WP, along with the site locale. |
313 * A list of all plugins installed is sent to api.wordpress.org, along with the site locale. |
303 * |
314 * |
304 * Checks against the WordPress server at api.wordpress.org. Will only check |
315 * Checks against the WordPress server at api.wordpress.org. Will only check |
305 * if WordPress isn't installing. |
316 * if WordPress isn't installing. |
306 * |
317 * |
307 * @since 2.3.0 |
318 * @since 2.3.0 |
312 */ |
323 */ |
313 function wp_update_plugins( $extra_stats = array() ) { |
324 function wp_update_plugins( $extra_stats = array() ) { |
314 if ( wp_installing() ) { |
325 if ( wp_installing() ) { |
315 return; |
326 return; |
316 } |
327 } |
317 |
|
318 // Include an unmodified $wp_version. |
|
319 require ABSPATH . WPINC . '/version.php'; |
|
320 |
328 |
321 // If running blog-side, bail unless we've not checked in the last 12 hours. |
329 // If running blog-side, bail unless we've not checked in the last 12 hours. |
322 if ( ! function_exists( 'get_plugins' ) ) { |
330 if ( ! function_exists( 'get_plugins' ) ) { |
323 require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
331 require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
324 } |
332 } |
330 $current = get_site_transient( 'update_plugins' ); |
338 $current = get_site_transient( 'update_plugins' ); |
331 |
339 |
332 if ( ! is_object( $current ) ) { |
340 if ( ! is_object( $current ) ) { |
333 $current = new stdClass(); |
341 $current = new stdClass(); |
334 } |
342 } |
335 |
|
336 $updates = new stdClass(); |
|
337 $updates->last_checked = time(); |
|
338 $updates->response = array(); |
|
339 $updates->translations = array(); |
|
340 $updates->no_update = array(); |
|
341 |
343 |
342 $doing_cron = wp_doing_cron(); |
344 $doing_cron = wp_doing_cron(); |
343 |
345 |
344 // Check for update on a different schedule, depending on the page. |
346 // Check for update on a different schedule, depending on the page. |
345 switch ( current_filter() ) { |
347 switch ( current_filter() ) { |
365 |
367 |
366 if ( $time_not_changed && ! $extra_stats ) { |
368 if ( $time_not_changed && ! $extra_stats ) { |
367 $plugin_changed = false; |
369 $plugin_changed = false; |
368 |
370 |
369 foreach ( $plugins as $file => $p ) { |
371 foreach ( $plugins as $file => $p ) { |
370 $updates->checked[ $file ] = $p['Version']; |
|
371 |
|
372 if ( ! isset( $current->checked[ $file ] ) || (string) $current->checked[ $file ] !== (string) $p['Version'] ) { |
372 if ( ! isset( $current->checked[ $file ] ) || (string) $current->checked[ $file ] !== (string) $p['Version'] ) { |
373 $plugin_changed = true; |
373 $plugin_changed = true; |
374 } |
374 } |
375 } |
375 } |
376 |
376 |
421 'plugins' => wp_json_encode( $to_send ), |
421 'plugins' => wp_json_encode( $to_send ), |
422 'translations' => wp_json_encode( $translations ), |
422 'translations' => wp_json_encode( $translations ), |
423 'locale' => wp_json_encode( $locales ), |
423 'locale' => wp_json_encode( $locales ), |
424 'all' => wp_json_encode( true ), |
424 'all' => wp_json_encode( true ), |
425 ), |
425 ), |
426 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), |
426 'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ), |
427 ); |
427 ); |
428 |
428 |
429 if ( $extra_stats ) { |
429 if ( $extra_stats ) { |
430 $options['body']['update_stats'] = wp_json_encode( $extra_stats ); |
430 $options['body']['update_stats'] = wp_json_encode( $extra_stats ); |
431 } |
431 } |
455 |
455 |
456 if ( is_wp_error( $raw_response ) || 200 !== wp_remote_retrieve_response_code( $raw_response ) ) { |
456 if ( is_wp_error( $raw_response ) || 200 !== wp_remote_retrieve_response_code( $raw_response ) ) { |
457 return; |
457 return; |
458 } |
458 } |
459 |
459 |
|
460 $updates = new stdClass(); |
|
461 $updates->last_checked = time(); |
|
462 $updates->response = array(); |
|
463 $updates->translations = array(); |
|
464 $updates->no_update = array(); |
|
465 foreach ( $plugins as $file => $p ) { |
|
466 $updates->checked[ $file ] = $p['Version']; |
|
467 } |
|
468 |
460 $response = json_decode( wp_remote_retrieve_body( $raw_response ), true ); |
469 $response = json_decode( wp_remote_retrieve_body( $raw_response ), true ); |
461 |
470 |
462 if ( $response && is_array( $response ) ) { |
471 if ( $response && is_array( $response ) ) { |
463 $updates->response = $response['plugins']; |
472 $updates->response = $response['plugins']; |
464 $updates->translations = $response['translations']; |
473 $updates->translations = $response['translations']; |
482 * @since 5.8.0 |
491 * @since 5.8.0 |
483 * |
492 * |
484 * @param array|false $update { |
493 * @param array|false $update { |
485 * The plugin update data with the latest details. Default false. |
494 * The plugin update data with the latest details. Default false. |
486 * |
495 * |
487 * @type string $id Optional. ID of the plugin for update purposes, should be a URI |
496 * @type string $id Optional. ID of the plugin for update purposes, should be a URI |
488 * specified in the `Update URI` header field. |
497 * specified in the `Update URI` header field. |
489 * @type string $slug Slug of the plugin. |
498 * @type string $slug Slug of the plugin. |
490 * @type string $version The version of the plugin. |
499 * @type string $version The version of the plugin. |
491 * @type string $url The URL for details of the plugin. |
500 * @type string $url The URL for details of the plugin. |
492 * @type string $package Optional. The update ZIP for the plugin. |
501 * @type string $package Optional. The update ZIP for the plugin. |
493 * @type string $tested Optional. The version of WordPress the plugin is tested against. |
502 * @type string $tested Optional. The version of WordPress the plugin is tested against. |
494 * @type string $requires_php Optional. The version of PHP which the plugin requires. |
503 * @type string $requires_php Optional. The version of PHP which the plugin requires. |
495 * @type bool $autoupdate Optional. Whether the plugin should automatically update. |
504 * @type bool $autoupdate Optional. Whether the plugin should automatically update. |
496 * @type array $icons Optional. Array of plugin icons. |
505 * @type string[] $icons Optional. Array of plugin icons. |
497 * @type array $banners Optional. Array of plugin banners. |
506 * @type string[] $banners Optional. Array of plugin banners. |
498 * @type array $banners_rtl Optional. Array of plugin RTL banners. |
507 * @type string[] $banners_rtl Optional. Array of plugin RTL banners. |
499 * @type array $translations { |
508 * @type array $translations { |
500 * Optional. List of translation updates for the plugin. |
509 * Optional. List of translation updates for the plugin. |
501 * |
510 * |
502 * @type string $language The language the translation update is for. |
511 * @type string $language The language the translation update is for. |
503 * @type string $version The version of the plugin this translation is for. |
512 * @type string $version The version of the plugin this translation is for. |
504 * This is not the version of the language file. |
513 * This is not the version of the language file. |
572 /** |
581 /** |
573 * Checks for available updates to themes based on the latest versions hosted on WordPress.org. |
582 * Checks for available updates to themes based on the latest versions hosted on WordPress.org. |
574 * |
583 * |
575 * Despite its name this function does not actually perform any updates, it only checks for available updates. |
584 * Despite its name this function does not actually perform any updates, it only checks for available updates. |
576 * |
585 * |
577 * A list of all themes installed is sent to WP, along with the site locale. |
586 * A list of all themes installed is sent to api.wordpress.org, along with the site locale. |
578 * |
587 * |
579 * Checks against the WordPress server at api.wordpress.org. Will only check |
588 * Checks against the WordPress server at api.wordpress.org. Will only check |
580 * if WordPress isn't installing. |
589 * if WordPress isn't installing. |
581 * |
590 * |
582 * @since 2.7.0 |
591 * @since 2.7.0 |
587 */ |
596 */ |
588 function wp_update_themes( $extra_stats = array() ) { |
597 function wp_update_themes( $extra_stats = array() ) { |
589 if ( wp_installing() ) { |
598 if ( wp_installing() ) { |
590 return; |
599 return; |
591 } |
600 } |
592 |
|
593 // Include an unmodified $wp_version. |
|
594 require ABSPATH . WPINC . '/version.php'; |
|
595 |
601 |
596 $installed_themes = wp_get_themes(); |
602 $installed_themes = wp_get_themes(); |
597 $translations = wp_get_installed_translations( 'themes' ); |
603 $translations = wp_get_installed_translations( 'themes' ); |
598 |
604 |
599 $last_update = get_site_transient( 'update_themes' ); |
605 $last_update = get_site_transient( 'update_themes' ); |
703 'body' => array( |
709 'body' => array( |
704 'themes' => wp_json_encode( $request ), |
710 'themes' => wp_json_encode( $request ), |
705 'translations' => wp_json_encode( $translations ), |
711 'translations' => wp_json_encode( $translations ), |
706 'locale' => wp_json_encode( $locales ), |
712 'locale' => wp_json_encode( $locales ), |
707 ), |
713 ), |
708 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), |
714 'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ), |
709 ); |
715 ); |
710 |
716 |
711 if ( $extra_stats ) { |
717 if ( $extra_stats ) { |
712 $options['body']['update_stats'] = wp_json_encode( $extra_stats ); |
718 $options['body']['update_stats'] = wp_json_encode( $extra_stats ); |
713 } |
719 } |
971 * @since 3.5.0 |
982 * @since 3.5.0 |
972 * |
983 * |
973 * @param array $update_data { |
984 * @param array $update_data { |
974 * Fetched update data. |
985 * Fetched update data. |
975 * |
986 * |
976 * @type array $counts An array of counts for available plugin, theme, and WordPress updates. |
987 * @type int[] $counts An array of counts for available plugin, theme, and WordPress updates. |
977 * @type string $update_title Titles of available updates. |
988 * @type string $update_title Titles of available updates. |
978 * } |
989 * } |
979 * @param array $titles An array of update counts and UI strings for available updates. |
990 * @param array $titles An array of update counts and UI strings for available updates. |
980 */ |
991 */ |
981 return apply_filters( 'wp_get_update_data', $update_data, $titles ); |
992 return apply_filters( 'wp_get_update_data', $update_data, $titles ); |
983 |
994 |
984 /** |
995 /** |
985 * Determines whether core should be updated. |
996 * Determines whether core should be updated. |
986 * |
997 * |
987 * @since 2.8.0 |
998 * @since 2.8.0 |
988 * |
|
989 * @global string $wp_version The WordPress version string. |
|
990 */ |
999 */ |
991 function _maybe_update_core() { |
1000 function _maybe_update_core() { |
992 // Include an unmodified $wp_version. |
|
993 require ABSPATH . WPINC . '/version.php'; |
|
994 |
|
995 $current = get_site_transient( 'update_core' ); |
1001 $current = get_site_transient( 'update_core' ); |
996 |
1002 |
997 if ( isset( $current->last_checked, $current->version_checked ) |
1003 if ( isset( $current->last_checked, $current->version_checked ) |
998 && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) |
1004 && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) |
999 && $current->version_checked === $wp_version |
1005 && wp_get_wp_version() === $current->version_checked |
1000 ) { |
1006 ) { |
1001 return; |
1007 return; |
1002 } |
1008 } |
1003 |
1009 |
1004 wp_version_check(); |
1010 wp_version_check(); |
1108 * @since 6.3.0 |
1114 * @since 6.3.0 |
1109 * |
1115 * |
1110 * @access private |
1116 * @access private |
1111 * |
1117 * |
1112 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
1118 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. |
1113 * |
|
1114 * @return void|WP_Error Void on success, or a WP_Error object on failure. |
|
1115 */ |
1119 */ |
1116 function _wp_delete_all_temp_backups() { |
1120 function _wp_delete_all_temp_backups() { |
1117 global $wp_filesystem; |
1121 global $wp_filesystem; |
1118 |
1122 |
1119 if ( ! function_exists( 'WP_Filesystem' ) ) { |
1123 if ( ! function_exists( 'WP_Filesystem' ) ) { |
1120 require_once ABSPATH . '/wp-admin/includes/file.php'; |
1124 require_once ABSPATH . 'wp-admin/includes/file.php'; |
1121 } |
1125 } |
1122 |
1126 |
1123 ob_start(); |
1127 ob_start(); |
1124 $credentials = request_filesystem_credentials( '' ); |
1128 $credentials = request_filesystem_credentials( '' ); |
1125 ob_end_clean(); |
1129 ob_end_clean(); |
1126 |
1130 |
1127 if ( false === $credentials || ! WP_Filesystem( $credentials ) ) { |
1131 if ( false === $credentials || ! WP_Filesystem( $credentials ) ) { |
1128 return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) ); |
1132 wp_trigger_error( __FUNCTION__, __( 'Could not access filesystem.' ) ); |
|
1133 return; |
1129 } |
1134 } |
1130 |
1135 |
1131 if ( ! $wp_filesystem->wp_content_dir() ) { |
1136 if ( ! $wp_filesystem->wp_content_dir() ) { |
1132 return new WP_Error( |
1137 wp_trigger_error( |
1133 'fs_no_content_dir', |
1138 __FUNCTION__, |
1134 /* translators: %s: Directory name. */ |
1139 /* translators: %s: Directory name. */ |
1135 sprintf( __( 'Unable to locate WordPress content directory (%s).' ), 'wp-content' ) |
1140 sprintf( __( 'Unable to locate WordPress content directory (%s).' ), 'wp-content' ) |
1136 ); |
1141 ); |
|
1142 return; |
1137 } |
1143 } |
1138 |
1144 |
1139 $temp_backup_dir = $wp_filesystem->wp_content_dir() . 'upgrade-temp-backup/'; |
1145 $temp_backup_dir = $wp_filesystem->wp_content_dir() . 'upgrade-temp-backup/'; |
1140 $dirlist = $wp_filesystem->dirlist( $temp_backup_dir ); |
1146 $dirlist = $wp_filesystem->dirlist( $temp_backup_dir ); |
1141 $dirlist = $dirlist ? $dirlist : array(); |
1147 $dirlist = $dirlist ? $dirlist : array(); |