Ticket #43103: 43103.diff
| File 43103.diff, 5.4 KB (added by , 8 years ago) |
|---|
-
src/wp-includes/update.php
function wp_version_check( $extra_stats 161 161 ); 162 162 $response = wp_remote_post( $http_url, $options ); 163 163 } 164 164 165 165 if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) { 166 166 return; 167 167 } 168 168 169 169 $body = trim( wp_remote_retrieve_body( $response ) ); 170 170 $body = json_decode( $body, true ); 171 171 172 172 if ( ! is_array( $body ) || ! isset( $body['offers'] ) ) { 173 173 return; 174 174 } 175 175 176 $offers = $body['offers']; 176 $offers = $body['offers']; 177 $has_auto_update = false; 177 178 178 179 foreach ( $offers as &$offer ) { 179 180 foreach ( $offer as $offer_key => $value ) { 180 181 if ( 'packages' == $offer_key ) { 181 182 $offer['packages'] = (object) array_intersect_key( 182 183 array_map( 'esc_url', $offer['packages'] ), 183 184 array_fill_keys( array( 'full', 'no_content', 'new_bundled', 'partial', 'rollback' ), '' ) 184 185 ); 185 186 } elseif ( 'download' == $offer_key ) { 186 187 $offer['download'] = esc_url( $value ); 187 188 } else { 188 189 $offer[ $offer_key ] = esc_html( $value ); 189 190 } 190 191 } 191 192 $offer = (object) array_intersect_key( … … function wp_version_check( $extra_stats 195 196 'download', 196 197 'locale', 197 198 'packages', 198 199 'current', 199 200 'version', 200 201 'php_version', 201 202 'mysql_version', 202 203 'new_bundled', 203 204 'partial_version', 204 205 'notify_email', 205 206 'support_email', 206 207 'new_files', 207 208 ), '' 208 209 ) 209 210 ); 211 212 if ( 'autoupdate' == $offer->response ) { 213 $has_auto_update = true; 214 } 210 215 } 211 216 212 217 $updates = new stdClass(); 213 218 $updates->updates = $offers; 214 219 $updates->last_checked = time(); 215 220 $updates->version_checked = $wp_version; 216 221 217 222 if ( isset( $body['translations'] ) ) { 218 223 $updates->translations = $body['translations']; 219 224 } 220 225 221 226 set_site_transient( 'update_core', $updates ); 222 227 223 228 if ( ! empty( $body['ttl'] ) ) { 224 229 $ttl = (int) $body['ttl']; 225 230 if ( $ttl && ( time() + $ttl < wp_next_scheduled( 'wp_version_check' ) ) ) { 226 231 // Queue an event to re-run the update check in $ttl seconds. 227 232 wp_schedule_single_event( time() + $ttl, 'wp_version_check' ); 228 233 } 229 234 } 230 235 231 236 // Trigger background updates if running non-interactively, and we weren't called from the update handler. 232 if ( $doing_cron && ! doing_action( 'wp_maybe_auto_update' ) ) { 233 do_action( 'wp_maybe_auto_update' ); 237 if ( $doing_cron && $has_auto_update && ! doing_action( 'wp_maybe_auto_update' ) ) { 238 include_once( ABSPATH . '/wp-admin/includes/update.php' ); 239 240 // Only trigger background updates if an acceptable autoupdate is on offer, avoids needless extra API calls. 241 if ( find_core_auto_update() ) { 242 do_action( 'wp_maybe_auto_update' ); 243 } 234 244 } 235 245 } 236 246 237 247 /** 238 248 * Check plugin versions against the latest versions hosted on WordPress.org. 239 249 * 240 250 * The WordPress version, PHP version, and Locale is sent along with a list of 241 251 * all plugins installed. Checks against the WordPress server at 242 252 * api.wordpress.org. Will only check if WordPress isn't installing. 243 253 * 244 254 * @since 2.3.0 245 255 * @global string $wp_version Used to notify the WordPress version. 246 256 * 247 257 * @param array $extra_stats Extra statistics to report to the WordPress.org API. 248 258 */ … … function wp_update_plugins( $extra_stats 275 285 276 286 // Check for update on a different schedule, depending on the page. 277 287 switch ( current_filter() ) { 278 288 case 'upgrader_process_complete': 279 289 $timeout = 0; 280 290 break; 281 291 case 'load-update-core.php': 282 292 $timeout = MINUTE_IN_SECONDS; 283 293 break; 284 294 case 'load-plugins.php': 285 295 case 'load-update.php': 286 296 $timeout = HOUR_IN_SECONDS; 287 297 break; 288 298 default: 289 299 if ( $doing_cron ) { 290 $timeout = 0;300 $timeout = 2 * HOUR_IN_SECONDS; 291 301 } else { 292 302 $timeout = 12 * HOUR_IN_SECONDS; 293 303 } 294 304 } 295 305 296 306 $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked ); 297 307 298 308 if ( $time_not_changed && ! $extra_stats ) { 299 309 $plugin_changed = false; 300 310 foreach ( $plugins as $file => $p ) { 301 311 $new_option->checked[ $file ] = $p['Version']; 302 312 303 313 if ( ! isset( $current->checked[ $file ] ) || strval( $current->checked[ $file ] ) !== strval( $p['Version'] ) ) { 304 314 $plugin_changed = true; 305 315 } … … function wp_update_themes( $extra_stats 462 472 $doing_cron = wp_doing_cron(); 463 473 464 474 // Check for update on a different schedule, depending on the page. 465 475 switch ( current_filter() ) { 466 476 case 'upgrader_process_complete': 467 477 $timeout = 0; 468 478 break; 469 479 case 'load-update-core.php': 470 480 $timeout = MINUTE_IN_SECONDS; 471 481 break; 472 482 case 'load-themes.php': 473 483 case 'load-update.php': 474 484 $timeout = HOUR_IN_SECONDS; 475 485 break; 476 486 default: 477 $timeout = $doing_cron ? 0 : 12 * HOUR_IN_SECONDS; 487 if ( $doing_cron ) { 488 $timeout = 2 * HOUR_IN_SECONDS; 489 } else { 490 $timeout = 12 * HOUR_IN_SECONDS; 491 } 478 492 } 479 493 480 494 $time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time() - $last_update->last_checked ); 481 495 482 496 if ( $time_not_changed && ! $extra_stats ) { 483 497 $theme_changed = false; 484 498 foreach ( $checked as $slug => $v ) { 485 499 if ( ! isset( $last_update->checked[ $slug ] ) || strval( $last_update->checked[ $slug ] ) !== strval( $v ) ) { 486 500 $theme_changed = true; 487 501 } 488 502 } 489 503 490 504 if ( isset( $last_update->response ) && is_array( $last_update->response ) ) { 491 505 foreach ( $last_update->response as $slug => $update_details ) { 492 506 if ( ! isset( $checked[ $slug ] ) ) {