Changeset 42343 for trunk/src/wp-includes/update.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/update.php (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/update.php
r41967 r42343 32 32 $php_version = phpversion(); 33 33 34 $current = get_site_transient( 'update_core' );34 $current = get_site_transient( 'update_core' ); 35 35 $translations = wp_get_installed_translations( 'core' ); 36 36 37 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 39 $current = false; 40 41 if ( ! is_object($current) ) { 42 $current = new stdClass; 43 $current->updates = array(); 40 } 41 42 if ( ! is_object( $current ) ) { 43 $current = new stdClass; 44 $current->updates = array(); 44 45 $current->version_checked = $wp_version; 45 46 } 46 47 47 if ( ! empty( $extra_stats ) ) 48 if ( ! empty( $extra_stats ) ) { 48 49 $force_check = true; 50 } 49 51 50 52 // Wait 60 seconds between multiple version check requests 51 $timeout = 60;53 $timeout = 60; 52 54 $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked ); 53 55 if ( ! $force_check && $time_not_changed ) { … … 68 70 set_site_transient( 'update_core', $current ); 69 71 70 if ( method_exists( $wpdb, 'db_version' ) ) 71 $mysql_version = preg_replace( '/[^0-9.].*/', '', $wpdb->db_version());72 else72 if ( method_exists( $wpdb, 'db_version' ) ) { 73 $mysql_version = preg_replace( '/[^0-9.].*/', '', $wpdb->db_version() ); 74 } else { 73 75 $mysql_version = 'N/A'; 76 } 74 77 75 78 if ( is_multisite() ) { 76 $user_count = get_user_count();77 $num_blogs = get_blog_count();78 $wp_install = network_site_url();79 $user_count = get_user_count(); 80 $num_blogs = get_blog_count(); 81 $wp_install = network_site_url(); 79 82 $multisite_enabled = 1; 80 83 } else { 81 $user_count = count_users();82 $user_count = $user_count['total_users'];84 $user_count = count_users(); 85 $user_count = $user_count['total_users']; 83 86 $multisite_enabled = 0; 84 $num_blogs = 1;85 $wp_install = home_url( '/' );87 $num_blogs = 1; 88 $wp_install = home_url( '/' ); 86 89 } 87 90 … … 107 110 * 108 111 * @param array $query { 109 * Version check query arguments. 112 * Version check query arguments. 110 113 * 111 114 * @type string $version WordPress version number. … … 126 129 ); 127 130 128 if ( is_array( $extra_stats ) ) 131 if ( is_array( $extra_stats ) ) { 129 132 $post_body = array_merge( $post_body, $extra_stats ); 133 } 130 134 131 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 137 $url = set_url_scheme( $url, 'https' ); 138 } 134 139 135 140 $doing_cron = wp_doing_cron(); 136 141 137 142 $options = array( 138 'timeout' => $doing_cron ? 30 : 3,143 'timeout' => $doing_cron ? 30 : 3, 139 144 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), 140 'headers' => array(145 'headers' => array( 141 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 … … 173 178 foreach ( $offers as &$offer ) { 174 179 foreach ( $offer as $offer_key => $value ) { 175 if ( 'packages' == $offer_key ) 176 $offer['packages'] = (object) array_intersect_key( array_map( 'esc_url', $offer['packages'] ), 177 array_fill_keys( array( 'full', 'no_content', 'new_bundled', 'partial', 'rollback' ), '' ) ); 178 elseif ( 'download' == $offer_key ) 180 if ( 'packages' == $offer_key ) { 181 $offer['packages'] = (object) array_intersect_key( 182 array_map( 'esc_url', $offer['packages'] ), 183 array_fill_keys( array( 'full', 'no_content', 'new_bundled', 'partial', 'rollback' ), '' ) 184 ); 185 } elseif ( 'download' == $offer_key ) { 179 186 $offer['download'] = esc_url( $value ); 180 else187 } else { 181 188 $offer[ $offer_key ] = esc_html( $value ); 182 } 183 $offer = (object) array_intersect_key( $offer, array_fill_keys( array( 'response', 'download', 'locale', 184 'packages', 'current', 'version', 'php_version', 'mysql_version', 'new_bundled', 'partial_version', 'notify_email', 'support_email', 'new_files' ), '' ) ); 185 } 186 187 $updates = new stdClass(); 188 $updates->updates = $offers; 189 $updates->last_checked = time(); 189 } 190 } 191 $offer = (object) array_intersect_key( 192 $offer, array_fill_keys( 193 array( 194 'response', 195 'download', 196 'locale', 197 'packages', 198 'current', 199 'version', 200 'php_version', 201 'mysql_version', 202 'new_bundled', 203 'partial_version', 204 'notify_email', 205 'support_email', 206 'new_files', 207 ), '' 208 ) 209 ); 210 } 211 212 $updates = new stdClass(); 213 $updates->updates = $offers; 214 $updates->last_checked = time(); 190 215 $updates->version_checked = $wp_version; 191 216 192 if ( isset( $body['translations'] ) ) 217 if ( isset( $body['translations'] ) ) { 193 218 $updates->translations = $body['translations']; 219 } 194 220 195 221 set_site_transient( 'update_core', $updates ); … … 230 256 231 257 // If running blog-side, bail unless we've not checked in the last 12 hours 232 if ( ! function_exists( 'get_plugins' ) )258 if ( ! function_exists( 'get_plugins' ) ) { 233 259 require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 234 235 $plugins = get_plugins(); 260 } 261 262 $plugins = get_plugins(); 236 263 $translations = wp_get_installed_translations( 'plugins' ); 237 264 238 265 $active = get_option( 'active_plugins', array() ); 239 266 $current = get_site_transient( 'update_plugins' ); 240 if ( ! is_object( $current) )267 if ( ! is_object( $current ) ) { 241 268 $current = new stdClass; 242 243 $new_option = new stdClass; 269 } 270 271 $new_option = new stdClass; 244 272 $new_option->last_checked = time(); 245 273 … … 248 276 // Check for update on a different schedule, depending on the page. 249 277 switch ( current_filter() ) { 250 case 'upgrader_process_complete' :278 case 'upgrader_process_complete': 251 279 $timeout = 0; 252 280 break; 253 case 'load-update-core.php' :281 case 'load-update-core.php': 254 282 $timeout = MINUTE_IN_SECONDS; 255 283 break; 256 case 'load-plugins.php' :257 case 'load-update.php' :284 case 'load-plugins.php': 285 case 'load-update.php': 258 286 $timeout = HOUR_IN_SECONDS; 259 287 break; 260 default :288 default: 261 289 if ( $doing_cron ) { 262 290 $timeout = 0; … … 273 301 $new_option->checked[ $file ] = $p['Version']; 274 302 275 if ( ! isset( $current->checked[ $file ] ) || strval($current->checked[ $file ]) !== strval($p['Version']) )303 if ( ! isset( $current->checked[ $file ] ) || strval( $current->checked[ $file ] ) !== strval( $p['Version'] ) ) { 276 304 $plugin_changed = true; 277 } 278 279 if ( isset ( $current->response ) && is_array( $current->response ) ) { 305 } 306 } 307 308 if ( isset( $current->response ) && is_array( $current->response ) ) { 280 309 foreach ( $current->response as $plugin_file => $update_details ) { 281 if ( ! isset( $plugins[ $plugin_file ]) ) {310 if ( ! isset( $plugins[ $plugin_file ] ) ) { 282 311 $plugin_changed = true; 283 312 break; … … 319 348 320 349 $options = array( 321 'timeout' => $timeout,322 'body' => array(350 'timeout' => $timeout, 351 'body' => array( 323 352 'plugins' => wp_json_encode( $to_send ), 324 353 'translations' => wp_json_encode( $translations ), … … 326 355 'all' => wp_json_encode( true ), 327 356 ), 328 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ) 357 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), 329 358 ); 330 359 … … 334 363 335 364 $url = $http_url = 'http://api.wordpress.org/plugins/update-check/1.1/'; 336 if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) 365 if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) { 337 366 $url = set_url_scheme( $url, 'https' ); 367 } 338 368 339 369 $raw_response = wp_remote_post( $url, $options ); … … 371 401 372 402 if ( is_array( $response ) ) { 373 $new_option->response = $response['plugins'];403 $new_option->response = $response['plugins']; 374 404 $new_option->translations = $response['translations']; 375 405 // TODO: Perhaps better to store no_update in a separate transient with an expiry? 376 406 $new_option->no_update = $response['no_update']; 377 407 } else { 378 $new_option->response = array();408 $new_option->response = array(); 379 409 $new_option->translations = array(); 380 $new_option->no_update = array();410 $new_option->no_update = array(); 381 411 } 382 412 … … 404 434 405 435 $installed_themes = wp_get_themes(); 406 $translations = wp_get_installed_translations( 'themes' );436 $translations = wp_get_installed_translations( 'themes' ); 407 437 408 438 $last_update = get_site_transient( 'update_themes' ); 409 if ( ! is_object( $last_update) )439 if ( ! is_object( $last_update ) ) { 410 440 $last_update = new stdClass; 441 } 411 442 412 443 $themes = $checked = $request = array(); … … 416 447 417 448 foreach ( $installed_themes as $theme ) { 418 $checked[ $theme->get_stylesheet() ] = $theme->get( 'Version');449 $checked[ $theme->get_stylesheet() ] = $theme->get( 'Version' ); 419 450 420 451 $themes[ $theme->get_stylesheet() ] = array( 421 'Name' => $theme->get( 'Name'),422 'Title' => $theme->get( 'Name'),423 'Version' => $theme->get( 'Version'),424 'Author' => $theme->get( 'Author'),425 'Author URI' => $theme->get( 'AuthorURI'),452 'Name' => $theme->get( 'Name' ), 453 'Title' => $theme->get( 'Name' ), 454 'Version' => $theme->get( 'Version' ), 455 'Author' => $theme->get( 'Author' ), 456 'Author URI' => $theme->get( 'AuthorURI' ), 426 457 'Template' => $theme->get_template(), 427 458 'Stylesheet' => $theme->get_stylesheet(), … … 433 464 // Check for update on a different schedule, depending on the page. 434 465 switch ( current_filter() ) { 435 case 'upgrader_process_complete' :466 case 'upgrader_process_complete': 436 467 $timeout = 0; 437 468 break; 438 case 'load-update-core.php' :469 case 'load-update-core.php': 439 470 $timeout = MINUTE_IN_SECONDS; 440 471 break; 441 case 'load-themes.php' :442 case 'load-update.php' :472 case 'load-themes.php': 473 case 'load-update.php': 443 474 $timeout = HOUR_IN_SECONDS; 444 475 break; 445 default :476 default: 446 477 $timeout = $doing_cron ? 0 : 12 * HOUR_IN_SECONDS; 447 478 } … … 452 483 $theme_changed = false; 453 484 foreach ( $checked as $slug => $v ) { 454 if ( ! isset( $last_update->checked[ $slug ] ) || strval($last_update->checked[ $slug ]) !== strval($v) )485 if ( ! isset( $last_update->checked[ $slug ] ) || strval( $last_update->checked[ $slug ] ) !== strval( $v ) ) { 455 486 $theme_changed = true; 456 } 457 458 if ( isset ( $last_update->response ) && is_array( $last_update->response ) ) { 487 } 488 } 489 490 if ( isset( $last_update->response ) && is_array( $last_update->response ) ) { 459 491 foreach ( $last_update->response as $slug => $update_details ) { 460 if ( ! isset( $checked[ $slug ]) ) {492 if ( ! isset( $checked[ $slug ] ) ) { 461 493 $theme_changed = true; 462 494 break; … … 498 530 499 531 $options = array( 500 'timeout' => $timeout,501 'body' => array(532 'timeout' => $timeout, 533 'body' => array( 502 534 'themes' => wp_json_encode( $request ), 503 535 'translations' => wp_json_encode( $translations ), 504 536 'locale' => wp_json_encode( $locales ), 505 537 ), 506 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' )538 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), 507 539 ); 508 540 … … 512 544 513 545 $url = $http_url = 'http://api.wordpress.org/themes/update-check/1.1/'; 514 if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) 546 if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) { 515 547 $url = set_url_scheme( $url, 'https' ); 548 } 516 549 517 550 $raw_response = wp_remote_post( $url, $options ); … … 532 565 } 533 566 534 $new_update = new stdClass;567 $new_update = new stdClass; 535 568 $new_update->last_checked = time(); 536 $new_update->checked = $checked;569 $new_update->checked = $checked; 537 570 538 571 $response = json_decode( wp_remote_retrieve_body( $raw_response ), true ); … … 567 600 */ 568 601 function wp_get_translation_updates() { 569 $updates = array(); 570 $transients = array( 'update_core' => 'core', 'update_plugins' => 'plugin', 'update_themes' => 'theme' ); 602 $updates = array(); 603 $transients = array( 604 'update_core' => 'core', 605 'update_plugins' => 'plugin', 606 'update_themes' => 'theme', 607 ); 571 608 foreach ( $transients as $transient => $type ) { 572 609 $transient = get_site_transient( $transient ); 573 if ( empty( $transient->translations ) ) 610 if ( empty( $transient->translations ) ) { 574 611 continue; 612 } 575 613 576 614 foreach ( $transient->translations as $translation ) { … … 589 627 */ 590 628 function wp_get_update_data() { 591 $counts = array( 'plugins' => 0, 'themes' => 0, 'wordpress' => 0, 'translations' => 0 ); 629 $counts = array( 630 'plugins' => 0, 631 'themes' => 0, 632 'wordpress' => 0, 633 'translations' => 0, 634 ); 592 635 593 636 if ( $plugins = current_user_can( 'update_plugins' ) ) { 594 637 $update_plugins = get_site_transient( 'update_plugins' ); 595 if ( ! empty( $update_plugins->response ) ) 638 if ( ! empty( $update_plugins->response ) ) { 596 639 $counts['plugins'] = count( $update_plugins->response ); 640 } 597 641 } 598 642 599 643 if ( $themes = current_user_can( 'update_themes' ) ) { 600 644 $update_themes = get_site_transient( 'update_themes' ); 601 if ( ! empty( $update_themes->response ) ) 645 if ( ! empty( $update_themes->response ) ) { 602 646 $counts['themes'] = count( $update_themes->response ); 647 } 603 648 } 604 649 605 650 if ( ( $core = current_user_can( 'update_core' ) ) && function_exists( 'get_core_updates' ) ) { 606 $update_wordpress = get_core_updates( array( 'dismissed' => false) );607 if ( ! empty( $update_wordpress ) && ! in_array( $update_wordpress[0]->response, array( 'development', 'latest') ) && current_user_can('update_core') )651 $update_wordpress = get_core_updates( array( 'dismissed' => false ) ); 652 if ( ! empty( $update_wordpress ) && ! in_array( $update_wordpress[0]->response, array( 'development', 'latest' ) ) && current_user_can( 'update_core' ) ) { 608 653 $counts['wordpress'] = 1; 609 } 610 611 if ( ( $core || $plugins || $themes ) && wp_get_translation_updates() ) 654 } 655 } 656 657 if ( ( $core || $plugins || $themes ) && wp_get_translation_updates() ) { 612 658 $counts['translations'] = 1; 659 } 613 660 614 661 $counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress'] + $counts['translations']; 615 $titles = array();662 $titles = array(); 616 663 if ( $counts['wordpress'] ) { 617 664 /* translators: 1: Number of updates available to WordPress */ 618 $titles['wordpress'] = sprintf( __( '%d WordPress Update' ), $counts['wordpress'] );665 $titles['wordpress'] = sprintf( __( '%d WordPress Update' ), $counts['wordpress'] ); 619 666 } 620 667 if ( $counts['plugins'] ) { … … 632 679 $update_title = $titles ? esc_attr( implode( ', ', $titles ) ) : ''; 633 680 634 $update_data = array( 'counts' => $counts, 'title' => $update_title ); 681 $update_data = array( 682 'counts' => $counts, 683 'title' => $update_title, 684 ); 635 685 /** 636 686 * Filters the returned array of update data for plugins, themes, and WordPress core. … … 681 731 function _maybe_update_plugins() { 682 732 $current = get_site_transient( 'update_plugins' ); 683 if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) ) 684 return; 733 if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) ) { 734 return; 735 } 685 736 wp_update_plugins(); 686 737 } … … 697 748 function _maybe_update_themes() { 698 749 $current = get_site_transient( 'update_themes' ); 699 if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) ) 700 return; 750 if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) ) { 751 return; 752 } 701 753 wp_update_themes(); 702 754 } … … 708 760 */ 709 761 function wp_schedule_update_checks() { 710 if ( ! wp_next_scheduled( 'wp_version_check' ) && ! wp_installing() ) 711 wp_schedule_event(time(), 'twicedaily', 'wp_version_check'); 712 713 if ( ! wp_next_scheduled( 'wp_update_plugins' ) && ! wp_installing() ) 714 wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins'); 715 716 if ( ! wp_next_scheduled( 'wp_update_themes' ) && ! wp_installing() ) 717 wp_schedule_event(time(), 'twicedaily', 'wp_update_themes'); 762 if ( ! wp_next_scheduled( 'wp_version_check' ) && ! wp_installing() ) { 763 wp_schedule_event( time(), 'twicedaily', 'wp_version_check' ); 764 } 765 766 if ( ! wp_next_scheduled( 'wp_update_plugins' ) && ! wp_installing() ) { 767 wp_schedule_event( time(), 'twicedaily', 'wp_update_plugins' ); 768 } 769 770 if ( ! wp_next_scheduled( 'wp_update_themes' ) && ! wp_installing() ) { 771 wp_schedule_event( time(), 'twicedaily', 'wp_update_themes' ); 772 } 718 773 } 719 774 … … 752 807 add_action( 'wp_update_themes', 'wp_update_themes' ); 753 808 754 add_action( 'update_option_WPLANG', 'wp_clean_update_cache' , 10, 0 );809 add_action( 'update_option_WPLANG', 'wp_clean_update_cache', 10, 0 ); 755 810 756 811 add_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' );
Note: See TracChangeset
for help on using the changeset viewer.