Changeset 42343 for trunk/src/wp-admin/includes/update.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/update.php
r41289 r42343 14 14 function get_preferred_from_update_core() { 15 15 $updates = get_core_updates(); 16 if ( ! is_array( $updates ) ) 17 return false; 18 if ( empty( $updates ) ) 16 if ( ! is_array( $updates ) ) { 17 return false; 18 } 19 if ( empty( $updates ) ) { 19 20 return (object) array( 'response' => 'latest' ); 21 } 20 22 return $updates[0]; 21 23 } … … 25 27 * 26 28 * @param array $options Set $options['dismissed'] to true to show dismissed upgrades too, 27 * 29 * set $options['available'] to false to skip not-dismissed updates. 28 30 * @return array|false Array of the update objects on success, false on failure. 29 31 */ 30 32 function get_core_updates( $options = array() ) { 31 $options = array_merge( array( 'available' => true, 'dismissed' => false ), $options ); 33 $options = array_merge( 34 array( 35 'available' => true, 36 'dismissed' => false, 37 ), $options 38 ); 32 39 $dismissed = get_site_option( 'dismissed_update_core' ); 33 40 34 if ( ! is_array( $dismissed ) ) 41 if ( ! is_array( $dismissed ) ) { 35 42 $dismissed = array(); 43 } 36 44 37 45 $from_api = get_site_transient( 'update_core' ); 38 46 39 if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) 40 return false; 47 if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) { 48 return false; 49 } 41 50 42 51 $updates = $from_api->updates; 43 $result = array();52 $result = array(); 44 53 foreach ( $updates as $update ) { 45 if ( $update->response == 'autoupdate' ) 54 if ( $update->response == 'autoupdate' ) { 46 55 continue; 56 } 47 57 48 58 if ( array_key_exists( $update->current . '|' . $update->locale, $dismissed ) ) { 49 59 if ( $options['dismissed'] ) { 50 60 $update->dismissed = true; 51 $result[] = $update;61 $result[] = $update; 52 62 } 53 63 } else { 54 64 if ( $options['available'] ) { 55 65 $update->dismissed = false; 56 $result[] = $update;66 $result[] = $update; 57 67 } 58 68 } … … 72 82 function find_core_auto_update() { 73 83 $updates = get_site_transient( 'update_core' ); 74 if ( ! $updates || empty( $updates->updates ) ) 75 return false; 84 if ( ! $updates || empty( $updates->updates ) ) { 85 return false; 86 } 76 87 77 88 include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); 78 89 79 90 $auto_update = false; 80 $upgrader = new WP_Automatic_Updater;91 $upgrader = new WP_Automatic_Updater; 81 92 foreach ( $updates->updates as $update ) { 82 if ( 'autoupdate' != $update->response ) 93 if ( 'autoupdate' != $update->response ) { 83 94 continue; 84 85 if ( ! $upgrader->should_update( 'core', $update, ABSPATH ) ) 95 } 96 97 if ( ! $upgrader->should_update( 'core', $update, ABSPATH ) ) { 86 98 continue; 87 88 if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) ) 99 } 100 101 if ( ! $auto_update || version_compare( $update->current, $auto_update->current, '>' ) ) { 89 102 $auto_update = $update; 103 } 90 104 } 91 105 return $auto_update; … … 104 118 $url = $http_url = 'http://api.wordpress.org/core/checksums/1.0/?' . http_build_query( compact( 'version', 'locale' ), null, '&' ); 105 119 106 if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) 120 if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) { 107 121 $url = set_url_scheme( $url, 'https' ); 122 } 108 123 109 124 $options = array( … … 124 139 } 125 140 126 if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) 127 return false; 141 if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) { 142 return false; 143 } 128 144 129 145 $body = trim( wp_remote_retrieve_body( $response ) ); 130 146 $body = json_decode( $body, true ); 131 147 132 if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) ) 133 return false; 148 if ( ! is_array( $body ) || ! isset( $body['checksums'] ) || ! is_array( $body['checksums'] ) ) { 149 return false; 150 } 134 151 135 152 return $body['checksums']; … … 137 154 138 155 /** 139 *140 156 * @param object $update 141 157 * @return bool … … 148 164 149 165 /** 150 *151 166 * @param string $version 152 167 * @param string $locale … … 155 170 function undismiss_core_update( $version, $locale ) { 156 171 $dismissed = get_site_option( 'dismissed_update_core' ); 157 $key = $version . '|' . $locale; 158 159 if ( ! isset( $dismissed[$key] ) ) 160 return false; 161 162 unset( $dismissed[$key] ); 172 $key = $version . '|' . $locale; 173 174 if ( ! isset( $dismissed[ $key ] ) ) { 175 return false; 176 } 177 178 unset( $dismissed[ $key ] ); 163 179 return update_site_option( 'dismissed_update_core', $dismissed ); 164 180 } 165 181 166 182 /** 167 *168 183 * @param string $version 169 184 * @param string $locale … … 173 188 $from_api = get_site_transient( 'update_core' ); 174 189 175 if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) 176 return false; 190 if ( ! isset( $from_api->updates ) || ! is_array( $from_api->updates ) ) { 191 return false; 192 } 177 193 178 194 $updates = $from_api->updates; 179 195 foreach ( $updates as $update ) { 180 if ( $update->current == $version && $update->locale == $locale ) 196 if ( $update->current == $version && $update->locale == $locale ) { 181 197 return $update; 198 } 182 199 } 183 200 return false; … … 185 202 186 203 /** 187 *188 204 * @param string $msg 189 205 * @return string 190 206 */ 191 207 function core_update_footer( $msg = '' ) { 192 if ( ! current_user_can('update_core') )208 if ( ! current_user_can( 'update_core' ) ) { 193 209 return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) ); 210 } 194 211 195 212 $cur = get_preferred_from_update_core(); 196 if ( ! is_object( $cur ) ) 213 if ( ! is_object( $cur ) ) { 197 214 $cur = new stdClass; 198 199 if ( ! isset( $cur->current ) ) 215 } 216 217 if ( ! isset( $cur->current ) ) { 200 218 $cur->current = ''; 201 202 if ( ! isset( $cur->url ) ) 219 } 220 221 if ( ! isset( $cur->url ) ) { 203 222 $cur->url = ''; 204 205 if ( ! isset( $cur->response ) ) 223 } 224 225 if ( ! isset( $cur->response ) ) { 206 226 $cur->response = ''; 227 } 207 228 208 229 switch ( $cur->response ) { 209 case 'development' : 210 /* translators: 1: WordPress version number, 2: WordPress updates admin screen URL */ 211 return sprintf( __( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ), get_bloginfo( 'version', 'display' ), network_admin_url( 'update-core.php' ) ); 212 213 case 'upgrade' : 214 return '<strong><a href="' . network_admin_url( 'update-core.php' ) . '">' . sprintf( __( 'Get Version %s' ), $cur->current ) . '</a></strong>'; 215 216 case 'latest' : 217 default : 218 return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) ); 219 } 220 } 221 222 /** 223 * 230 case 'development': 231 /* translators: 1: WordPress version number, 2: WordPress updates admin screen URL */ 232 return sprintf( __( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ), get_bloginfo( 'version', 'display' ), network_admin_url( 'update-core.php' ) ); 233 234 case 'upgrade': 235 return '<strong><a href="' . network_admin_url( 'update-core.php' ) . '">' . sprintf( __( 'Get Version %s' ), $cur->current ) . '</a></strong>'; 236 237 case 'latest': 238 default: 239 return sprintf( __( 'Version %s' ), get_bloginfo( 'version', 'display' ) ); 240 } 241 } 242 243 /** 224 244 * @global string $pagenow 225 245 * @return false|void 226 246 */ 227 247 function update_nag() { 228 if ( is_multisite() && !current_user_can('update_core') ) 229 return false; 248 if ( is_multisite() && ! current_user_can( 'update_core' ) ) { 249 return false; 250 } 230 251 231 252 global $pagenow; 232 253 233 if ( 'update-core.php' == $pagenow ) 254 if ( 'update-core.php' == $pagenow ) { 234 255 return; 256 } 235 257 236 258 $cur = get_preferred_from_update_core(); 237 259 238 if ( ! isset( $cur->response ) || $cur->response != 'upgrade' ) 239 return false; 260 if ( ! isset( $cur->response ) || $cur->response != 'upgrade' ) { 261 return false; 262 } 240 263 241 264 if ( current_user_can( 'update_core' ) ) { … … 276 299 $msg = ''; 277 300 278 if ( current_user_can( 'update_core') ) {301 if ( current_user_can( 'update_core' ) ) { 279 302 $cur = get_preferred_from_update_core(); 280 303 281 if ( isset( $cur->response ) && $cur->response == 'upgrade' ) 304 if ( isset( $cur->response ) && $cur->response == 'upgrade' ) { 282 305 $msg .= '<a href="' . network_admin_url( 'update-core.php' ) . '" class="button" aria-describedby="wp-version">' . sprintf( __( 'Update to %s' ), $cur->current ? $cur->current : __( 'Latest' ) ) . '</a> '; 306 } 283 307 } 284 308 … … 308 332 */ 309 333 function get_plugin_updates() { 310 $all_plugins = get_plugins();334 $all_plugins = get_plugins(); 311 335 $upgrade_plugins = array(); 312 $current = get_site_transient( 'update_plugins' );313 foreach ( (array) $all_plugins as $plugin_file => $plugin_data) {336 $current = get_site_transient( 'update_plugins' ); 337 foreach ( (array) $all_plugins as $plugin_file => $plugin_data ) { 314 338 if ( isset( $current->response[ $plugin_file ] ) ) { 315 $upgrade_plugins[ $plugin_file ] = (object) $plugin_data;339 $upgrade_plugins[ $plugin_file ] = (object) $plugin_data; 316 340 $upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ]; 317 341 } … … 325 349 */ 326 350 function wp_plugin_update_rows() { 327 if ( ! current_user_can('update_plugins' ) )351 if ( ! current_user_can( 'update_plugins' ) ) { 328 352 return; 353 } 329 354 330 355 $plugins = get_site_transient( 'update_plugins' ); 331 if ( isset( $plugins->response) && is_array($plugins->response) ) {356 if ( isset( $plugins->response ) && is_array( $plugins->response ) ) { 332 357 $plugins = array_keys( $plugins->response ); 333 358 foreach ( $plugins as $plugin_file ) { … … 353 378 354 379 $plugins_allowedtags = array( 355 'a' => array( 'href' => array(), 'title' => array() ), 380 'a' => array( 381 'href' => array(), 382 'title' => array(), 383 ), 356 384 'abbr' => array( 'title' => array() ), 357 385 'acronym' => array( 'title' => array() ), … … 361 389 ); 362 390 363 $plugin_name 364 $details_url 391 $plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags ); 392 $details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $response->slug . '§ion=changelog&TB_iframe=true&width=600&height=800' ); 365 393 366 394 /** @var WP_Plugins_List_Table $wp_list_table */ … … 378 406 if ( ! current_user_can( 'update_plugins' ) ) { 379 407 /* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number */ 380 printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ), 408 printf( 409 __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ), 381 410 $plugin_name, 382 411 esc_url( $details_url ), 383 sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"', 412 sprintf( 413 'class="thickbox open-plugin-details-modal" aria-label="%s"', 384 414 /* translators: 1: plugin name, 2: version number */ 385 415 esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) ) … … 389 419 } elseif ( empty( $response->package ) ) { 390 420 /* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number */ 391 printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this plugin.</em>' ), 421 printf( 422 __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this plugin.</em>' ), 392 423 $plugin_name, 393 424 esc_url( $details_url ), 394 sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"', 425 sprintf( 426 'class="thickbox open-plugin-details-modal" aria-label="%s"', 395 427 /* translators: 1: plugin name, 2: version number */ 396 428 esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) ) … … 400 432 } else { 401 433 /* translators: 1: plugin name, 2: details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */ 402 printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ), 434 printf( 435 __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ), 403 436 $plugin_name, 404 437 esc_url( $details_url ), 405 sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"', 438 sprintf( 439 'class="thickbox open-plugin-details-modal" aria-label="%s"', 406 440 /* translators: 1: plugin name, 2: version number */ 407 441 esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $plugin_name, $response->new_version ) ) … … 409 443 $response->new_version, 410 444 wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' ) . $file, 'upgrade-plugin_' . $file ), 411 sprintf( 'class="update-link" aria-label="%s"', 445 sprintf( 446 'class="update-link" aria-label="%s"', 412 447 /* translators: %s: plugin name */ 413 448 esc_attr( sprintf( __( 'Update %s now' ), $plugin_name ) ) … … 458 493 459 494 /** 460 *461 495 * @return array 462 496 */ 463 497 function get_theme_updates() { 464 $current = get_site_transient( 'update_themes');465 466 if ( ! isset( $current->response ) ) 498 $current = get_site_transient( 'update_themes' ); 499 500 if ( ! isset( $current->response ) ) { 467 501 return array(); 502 } 468 503 469 504 $update_themes = array(); 470 505 foreach ( $current->response as $stylesheet => $data ) { 471 $update_themes[ $stylesheet ] = wp_get_theme( $stylesheet );506 $update_themes[ $stylesheet ] = wp_get_theme( $stylesheet ); 472 507 $update_themes[ $stylesheet ]->update = $data; 473 508 } … … 480 515 */ 481 516 function wp_theme_update_rows() { 482 if ( ! current_user_can('update_themes' ) )517 if ( ! current_user_can( 'update_themes' ) ) { 483 518 return; 519 } 484 520 485 521 $themes = get_site_transient( 'update_themes' ); 486 if ( isset( $themes->response) && is_array($themes->response) ) {522 if ( isset( $themes->response ) && is_array( $themes->response ) ) { 487 523 $themes = array_keys( $themes->response ); 488 524 … … 509 545 $response = $current->response[ $theme_key ]; 510 546 511 $details_url = add_query_arg( array( 512 'TB_iframe' => 'true', 513 'width' => 1024, 514 'height' => 800, 515 ), $current->response[ $theme_key ]['url'] ); 547 $details_url = add_query_arg( 548 array( 549 'TB_iframe' => 'true', 550 'width' => 1024, 551 'height' => 800, 552 ), $current->response[ $theme_key ]['url'] 553 ); 516 554 517 555 /** @var WP_MS_Themes_List_Table $wp_list_table */ … … 523 561 if ( ! current_user_can( 'update_themes' ) ) { 524 562 /* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number */ 525 printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.'), 563 printf( 564 __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>.' ), 526 565 $theme['Name'], 527 566 esc_url( $details_url ), 528 sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"', 567 sprintf( 568 'class="thickbox open-plugin-details-modal" aria-label="%s"', 529 569 /* translators: 1: theme name, 2: version number */ 530 570 esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) ) … … 534 574 } elseif ( empty( $response['package'] ) ) { 535 575 /* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number */ 536 printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ), 576 printf( 577 __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a>. <em>Automatic update is unavailable for this theme.</em>' ), 537 578 $theme['Name'], 538 579 esc_url( $details_url ), 539 sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"', 580 sprintf( 581 'class="thickbox open-plugin-details-modal" aria-label="%s"', 540 582 /* translators: 1: theme name, 2: version number */ 541 583 esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) ) … … 545 587 } else { 546 588 /* translators: 1: theme name, 2: details URL, 3: additional link attributes, 4: version number, 5: update URL, 6: additional link attributes */ 547 printf( __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ), 589 printf( 590 __( 'There is a new version of %1$s available. <a href="%2$s" %3$s>View version %4$s details</a> or <a href="%5$s" %6$s>update now</a>.' ), 548 591 $theme['Name'], 549 592 esc_url( $details_url ), 550 sprintf( 'class="thickbox open-plugin-details-modal" aria-label="%s"', 593 sprintf( 594 'class="thickbox open-plugin-details-modal" aria-label="%s"', 551 595 /* translators: 1: theme name, 2: version number */ 552 596 esc_attr( sprintf( __( 'View %1$s version %2$s details' ), $theme['Name'], $response['new_version'] ) ) … … 554 598 $response['new_version'], 555 599 wp_nonce_url( self_admin_url( 'update.php?action=upgrade-theme&theme=' ) . $theme_key, 'upgrade-theme_' . $theme_key ), 556 sprintf( 'class="update-link" aria-label="%s"', 600 sprintf( 601 'class="update-link" aria-label="%s"', 557 602 /* translators: %s: theme name */ 558 603 esc_attr( sprintf( __( 'Update %s now' ), $theme['Name'] ) ) … … 585 630 586 631 /** 587 *588 632 * @global int $upgrading 589 633 * @return false|void … … 606 650 */ 607 651 $comparison = ! empty( $failed['critical'] ) ? '>=' : '>'; 608 if ( version_compare( $failed['attempted'], $wp_version, $comparison ) ) 652 if ( version_compare( $failed['attempted'], $wp_version, $comparison ) ) { 609 653 $nag = true; 610 } 611 612 if ( ! $nag ) 613 return false; 614 615 if ( current_user_can('update_core') ) 616 $msg = sprintf( __('An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.'), 'update-core.php' ); 617 else 618 $msg = __('An automated WordPress update has failed to complete! Please notify the site administrator.'); 654 } 655 } 656 657 if ( ! $nag ) { 658 return false; 659 } 660 661 if ( current_user_can( 'update_core' ) ) { 662 $msg = sprintf( __( 'An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.' ), 'update-core.php' ); 663 } else { 664 $msg = __( 'An automated WordPress update has failed to complete! Please notify the site administrator.' ); 665 } 619 666 620 667 echo "<div class='update-nag'>$msg</div>";
Note: See TracChangeset
for help on using the changeset viewer.