[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * A simple set of functions to check our version 1.0 update service. 4 * 5 * @package WordPress 6 * @since 2.3.0 7 */ 8 9 /** 10 * Check WordPress version against the newest version. 11 * 12 * The WordPress version, PHP version, and locale is sent. 13 * 14 * Checks against the WordPress server at api.wordpress.org. Will only check 15 * if WordPress isn't installing. 16 * 17 * @since 2.3.0 18 * 19 * @global string $wp_version Used to check against the newest WordPress version. 20 * @global wpdb $wpdb WordPress database abstraction object. 21 * @global string $wp_local_package Locale code of the package. 22 * 23 * @param array $extra_stats Extra statistics to report to the WordPress.org API. 24 * @param bool $force_check Whether to bypass the transient cache and force a fresh update check. Defaults to false, true if $extra_stats is set. 25 */ 26 function wp_version_check( $extra_stats = array(), $force_check = false ) { 27 global $wpdb, $wp_local_package; 28 29 if ( wp_installing() ) { 30 return; 31 } 32 33 // Include an unmodified $wp_version. 34 require ABSPATH . WPINC . '/version.php'; 35 $php_version = phpversion(); 36 37 $current = get_site_transient( 'update_core' ); 38 $translations = wp_get_installed_translations( 'core' ); 39 40 // Invalidate the transient when $wp_version changes. 41 if ( is_object( $current ) && $wp_version !== $current->version_checked ) { 42 $current = false; 43 } 44 45 if ( ! is_object( $current ) ) { 46 $current = new stdClass; 47 $current->updates = array(); 48 $current->version_checked = $wp_version; 49 } 50 51 if ( ! empty( $extra_stats ) ) { 52 $force_check = true; 53 } 54 55 // Wait 1 minute between multiple version check requests. 56 $timeout = MINUTE_IN_SECONDS; 57 $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked ); 58 59 if ( ! $force_check && $time_not_changed ) { 60 return; 61 } 62 63 /** 64 * Filters the locale requested for WordPress core translations. 65 * 66 * @since 2.8.0 67 * 68 * @param string $locale Current locale. 69 */ 70 $locale = apply_filters( 'core_version_check_locale', get_locale() ); 71 72 // Update last_checked for current to prevent multiple blocking requests if request hangs. 73 $current->last_checked = time(); 74 set_site_transient( 'update_core', $current ); 75 76 if ( method_exists( $wpdb, 'db_version' ) ) { 77 $mysql_version = preg_replace( '/[^0-9.].*/', '', $wpdb->db_version() ); 78 } else { 79 $mysql_version = 'N/A'; 80 } 81 82 if ( is_multisite() ) { 83 $user_count = get_user_count(); 84 $num_blogs = get_blog_count(); 85 $wp_install = network_site_url(); 86 $multisite_enabled = 1; 87 } else { 88 $user_count = count_users(); 89 $user_count = $user_count['total_users']; 90 $multisite_enabled = 0; 91 $num_blogs = 1; 92 $wp_install = home_url( '/' ); 93 } 94 95 $query = array( 96 'version' => $wp_version, 97 'php' => $php_version, 98 'locale' => $locale, 99 'mysql' => $mysql_version, 100 'local_package' => isset( $wp_local_package ) ? $wp_local_package : '', 101 'blogs' => $num_blogs, 102 'users' => $user_count, 103 'multisite_enabled' => $multisite_enabled, 104 'initial_db_version' => get_site_option( 'initial_db_version' ), 105 ); 106 107 /** 108 * Filters the query arguments sent as part of the core version check. 109 * 110 * WARNING: Changing this data may result in your site not receiving security updates. 111 * Please exercise extreme caution. 112 * 113 * @since 4.9.0 114 * 115 * @param array $query { 116 * Version check query arguments. 117 * 118 * @type string $version WordPress version number. 119 * @type string $php PHP version number. 120 * @type string $locale The locale to retrieve updates for. 121 * @type string $mysql MySQL version number. 122 * @type string $local_package The value of the $wp_local_package global, when set. 123 * @type int $blogs Number of sites on this WordPress installation. 124 * @type int $users Number of users on this WordPress installation. 125 * @type int $multisite_enabled Whether this WordPress installation uses Multisite. 126 * @type int $initial_db_version Database version of WordPress at time of installation. 127 * } 128 */ 129 $query = apply_filters( 'core_version_check_query_args', $query ); 130 131 $post_body = array( 132 'translations' => wp_json_encode( $translations ), 133 ); 134 135 if ( is_array( $extra_stats ) ) { 136 $post_body = array_merge( $post_body, $extra_stats ); 137 } 138 139 // Allow for WP_AUTO_UPDATE_CORE to specify beta/RC/development releases. 140 if ( defined( 'WP_AUTO_UPDATE_CORE' ) 141 && in_array( WP_AUTO_UPDATE_CORE, array( 'beta', 'rc', 'development', 'branch-development' ), true ) 142 ) { 143 $query['channel'] = WP_AUTO_UPDATE_CORE; 144 } 145 146 $url = 'http://api.wordpress.org/core/version-check/1.7/?' . http_build_query( $query, null, '&' ); 147 $http_url = $url; 148 $ssl = wp_http_supports( array( 'ssl' ) ); 149 150 if ( $ssl ) { 151 $url = set_url_scheme( $url, 'https' ); 152 } 153 154 $doing_cron = wp_doing_cron(); 155 156 $options = array( 157 'timeout' => $doing_cron ? 30 : 3, 158 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), 159 'headers' => array( 160 'wp_install' => $wp_install, 161 'wp_blog' => home_url( '/' ), 162 ), 163 'body' => $post_body, 164 ); 165 166 $response = wp_remote_post( $url, $options ); 167 168 if ( $ssl && is_wp_error( $response ) ) { 169 trigger_error( 170 sprintf( 171 /* translators: %s: Support forums URL. */ 172 __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), 173 __( 'https://wordpress.org/support/forums/' ) 174 ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), 175 headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE 176 ); 177 $response = wp_remote_post( $http_url, $options ); 178 } 179 180 if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { 181 return; 182 } 183 184 $body = trim( wp_remote_retrieve_body( $response ) ); 185 $body = json_decode( $body, true ); 186 187 if ( ! is_array( $body ) || ! isset( $body['offers'] ) ) { 188 return; 189 } 190 191 $offers = $body['offers']; 192 193 foreach ( $offers as &$offer ) { 194 foreach ( $offer as $offer_key => $value ) { 195 if ( 'packages' === $offer_key ) { 196 $offer['packages'] = (object) array_intersect_key( 197 array_map( 'esc_url', $offer['packages'] ), 198 array_fill_keys( array( 'full', 'no_content', 'new_bundled', 'partial', 'rollback' ), '' ) 199 ); 200 } elseif ( 'download' === $offer_key ) { 201 $offer['download'] = esc_url( $value ); 202 } else { 203 $offer[ $offer_key ] = esc_html( $value ); 204 } 205 } 206 $offer = (object) array_intersect_key( 207 $offer, 208 array_fill_keys( 209 array( 210 'response', 211 'download', 212 'locale', 213 'packages', 214 'current', 215 'version', 216 'php_version', 217 'mysql_version', 218 'new_bundled', 219 'partial_version', 220 'notify_email', 221 'support_email', 222 'new_files', 223 ), 224 '' 225 ) 226 ); 227 } 228 229 $updates = new stdClass(); 230 $updates->updates = $offers; 231 $updates->last_checked = time(); 232 $updates->version_checked = $wp_version; 233 234 if ( isset( $body['translations'] ) ) { 235 $updates->translations = $body['translations']; 236 } 237 238 set_site_transient( 'update_core', $updates ); 239 240 if ( ! empty( $body['ttl'] ) ) { 241 $ttl = (int) $body['ttl']; 242 243 if ( $ttl && ( time() + $ttl < wp_next_scheduled( 'wp_version_check' ) ) ) { 244 // Queue an event to re-run the update check in $ttl seconds. 245 wp_schedule_single_event( time() + $ttl, 'wp_version_check' ); 246 } 247 } 248 249 // Trigger background updates if running non-interactively, and we weren't called from the update handler. 250 if ( $doing_cron && ! doing_action( 'wp_maybe_auto_update' ) ) { 251 /** 252 * Fires during wp_cron, starting the auto-update process. 253 * 254 * @since 3.9.0 255 */ 256 do_action( 'wp_maybe_auto_update' ); 257 } 258 } 259 260 /** 261 * Checks for available updates to plugins based on the latest versions hosted on WordPress.org. 262 * 263 * Despite its name this function does not actually perform any updates, it only checks for available updates. 264 * 265 * A list of all plugins installed is sent to WP, along with the site locale. 266 * 267 * Checks against the WordPress server at api.wordpress.org. Will only check 268 * if WordPress isn't installing. 269 * 270 * @since 2.3.0 271 * 272 * @global string $wp_version The WordPress version string. 273 * 274 * @param array $extra_stats Extra statistics to report to the WordPress.org API. 275 */ 276 function wp_update_plugins( $extra_stats = array() ) { 277 if ( wp_installing() ) { 278 return; 279 } 280 281 // Include an unmodified $wp_version. 282 require ABSPATH . WPINC . '/version.php'; 283 284 // If running blog-side, bail unless we've not checked in the last 12 hours. 285 if ( ! function_exists( 'get_plugins' ) ) { 286 require_once ABSPATH . 'wp-admin/includes/plugin.php'; 287 } 288 289 $plugins = get_plugins(); 290 $translations = wp_get_installed_translations( 'plugins' ); 291 292 $active = get_option( 'active_plugins', array() ); 293 $current = get_site_transient( 'update_plugins' ); 294 295 if ( ! is_object( $current ) ) { 296 $current = new stdClass; 297 } 298 299 $new_option = new stdClass; 300 $new_option->last_checked = time(); 301 302 $doing_cron = wp_doing_cron(); 303 304 // Check for update on a different schedule, depending on the page. 305 switch ( current_filter() ) { 306 case 'upgrader_process_complete': 307 $timeout = 0; 308 break; 309 case 'load-update-core.php': 310 $timeout = MINUTE_IN_SECONDS; 311 break; 312 case 'load-plugins.php': 313 case 'load-update.php': 314 $timeout = HOUR_IN_SECONDS; 315 break; 316 default: 317 if ( $doing_cron ) { 318 $timeout = 2 * HOUR_IN_SECONDS; 319 } else { 320 $timeout = 12 * HOUR_IN_SECONDS; 321 } 322 } 323 324 $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked ); 325 326 if ( $time_not_changed && ! $extra_stats ) { 327 $plugin_changed = false; 328 329 foreach ( $plugins as $file => $p ) { 330 $new_option->checked[ $file ] = $p['Version']; 331 332 if ( ! isset( $current->checked[ $file ] ) || (string) $current->checked[ $file ] !== (string) $p['Version'] ) { 333 $plugin_changed = true; 334 } 335 } 336 337 if ( isset( $current->response ) && is_array( $current->response ) ) { 338 foreach ( $current->response as $plugin_file => $update_details ) { 339 if ( ! isset( $plugins[ $plugin_file ] ) ) { 340 $plugin_changed = true; 341 break; 342 } 343 } 344 } 345 346 // Bail if we've checked recently and if nothing has changed. 347 if ( ! $plugin_changed ) { 348 return; 349 } 350 } 351 352 // Update last_checked for current to prevent multiple blocking requests if request hangs. 353 $current->last_checked = time(); 354 set_site_transient( 'update_plugins', $current ); 355 356 $to_send = compact( 'plugins', 'active' ); 357 358 $locales = array_values( get_available_languages() ); 359 360 /** 361 * Filters the locales requested for plugin translations. 362 * 363 * @since 3.7.0 364 * @since 4.5.0 The default value of the `$locales` parameter changed to include all locales. 365 * 366 * @param array $locales Plugin locales. Default is all available locales of the site. 367 */ 368 $locales = apply_filters( 'plugins_update_check_locales', $locales ); 369 $locales = array_unique( $locales ); 370 371 if ( $doing_cron ) { 372 $timeout = 30; 373 } else { 374 // Three seconds, plus one extra second for every 10 plugins. 375 $timeout = 3 + (int) ( count( $plugins ) / 10 ); 376 } 377 378 $options = array( 379 'timeout' => $timeout, 380 'body' => array( 381 'plugins' => wp_json_encode( $to_send ), 382 'translations' => wp_json_encode( $translations ), 383 'locale' => wp_json_encode( $locales ), 384 'all' => wp_json_encode( true ), 385 ), 386 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), 387 ); 388 389 if ( $extra_stats ) { 390 $options['body']['update_stats'] = wp_json_encode( $extra_stats ); 391 } 392 393 $url = 'http://api.wordpress.org/plugins/update-check/1.1/'; 394 $http_url = $url; 395 $ssl = wp_http_supports( array( 'ssl' ) ); 396 397 if ( $ssl ) { 398 $url = set_url_scheme( $url, 'https' ); 399 } 400 401 $raw_response = wp_remote_post( $url, $options ); 402 403 if ( $ssl && is_wp_error( $raw_response ) ) { 404 trigger_error( 405 sprintf( 406 /* translators: %s: Support forums URL. */ 407 __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), 408 __( 'https://wordpress.org/support/forums/' ) 409 ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), 410 headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE 411 ); 412 $raw_response = wp_remote_post( $http_url, $options ); 413 } 414 415 if ( is_wp_error( $raw_response ) || 200 !== wp_remote_retrieve_response_code( $raw_response ) ) { 416 return; 417 } 418 419 $response = json_decode( wp_remote_retrieve_body( $raw_response ), true ); 420 421 foreach ( $response['plugins'] as &$plugin ) { 422 $plugin = (object) $plugin; 423 424 if ( isset( $plugin->compatibility ) ) { 425 $plugin->compatibility = (object) $plugin->compatibility; 426 427 foreach ( $plugin->compatibility as &$data ) { 428 $data = (object) $data; 429 } 430 } 431 } 432 433 unset( $plugin, $data ); 434 435 foreach ( $response['no_update'] as &$plugin ) { 436 $plugin = (object) $plugin; 437 } 438 439 unset( $plugin ); 440 441 if ( is_array( $response ) ) { 442 $new_option->response = $response['plugins']; 443 $new_option->translations = $response['translations']; 444 // TODO: Perhaps better to store no_update in a separate transient with an expiry? 445 $new_option->no_update = $response['no_update']; 446 } else { 447 $new_option->response = array(); 448 $new_option->translations = array(); 449 $new_option->no_update = array(); 450 } 451 452 set_site_transient( 'update_plugins', $new_option ); 453 } 454 455 /** 456 * Checks for available updates to themes based on the latest versions hosted on WordPress.org. 457 * 458 * Despite its name this function does not actually perform any updates, it only checks for available updates. 459 * 460 * A list of all themes installed is sent to WP, along with the site locale. 461 * 462 * Checks against the WordPress server at api.wordpress.org. Will only check 463 * if WordPress isn't installing. 464 * 465 * @since 2.7.0 466 * 467 * @global string $wp_version The WordPress version string. 468 * 469 * @param array $extra_stats Extra statistics to report to the WordPress.org API. 470 */ 471 function wp_update_themes( $extra_stats = array() ) { 472 if ( wp_installing() ) { 473 return; 474 } 475 476 // Include an unmodified $wp_version. 477 require ABSPATH . WPINC . '/version.php'; 478 479 $installed_themes = wp_get_themes(); 480 $translations = wp_get_installed_translations( 'themes' ); 481 482 $last_update = get_site_transient( 'update_themes' ); 483 484 if ( ! is_object( $last_update ) ) { 485 $last_update = new stdClass; 486 } 487 488 $themes = array(); 489 $checked = array(); 490 $request = array(); 491 492 // Put slug of current theme into request. 493 $request['active'] = get_option( 'stylesheet' ); 494 495 foreach ( $installed_themes as $theme ) { 496 $checked[ $theme->get_stylesheet() ] = $theme->get( 'Version' ); 497 498 $themes[ $theme->get_stylesheet() ] = array( 499 'Name' => $theme->get( 'Name' ), 500 'Title' => $theme->get( 'Name' ), 501 'Version' => $theme->get( 'Version' ), 502 'Author' => $theme->get( 'Author' ), 503 'Author URI' => $theme->get( 'AuthorURI' ), 504 'Template' => $theme->get_template(), 505 'Stylesheet' => $theme->get_stylesheet(), 506 ); 507 } 508 509 $doing_cron = wp_doing_cron(); 510 511 // Check for update on a different schedule, depending on the page. 512 switch ( current_filter() ) { 513 case 'upgrader_process_complete': 514 $timeout = 0; 515 break; 516 case 'load-update-core.php': 517 $timeout = MINUTE_IN_SECONDS; 518 break; 519 case 'load-themes.php': 520 case 'load-update.php': 521 $timeout = HOUR_IN_SECONDS; 522 break; 523 default: 524 if ( $doing_cron ) { 525 $timeout = 2 * HOUR_IN_SECONDS; 526 } else { 527 $timeout = 12 * HOUR_IN_SECONDS; 528 } 529 } 530 531 $time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time() - $last_update->last_checked ); 532 533 if ( $time_not_changed && ! $extra_stats ) { 534 $theme_changed = false; 535 536 foreach ( $checked as $slug => $v ) { 537 if ( ! isset( $last_update->checked[ $slug ] ) || (string) $last_update->checked[ $slug ] !== (string) $v ) { 538 $theme_changed = true; 539 } 540 } 541 542 if ( isset( $last_update->response ) && is_array( $last_update->response ) ) { 543 foreach ( $last_update->response as $slug => $update_details ) { 544 if ( ! isset( $checked[ $slug ] ) ) { 545 $theme_changed = true; 546 break; 547 } 548 } 549 } 550 551 // Bail if we've checked recently and if nothing has changed. 552 if ( ! $theme_changed ) { 553 return; 554 } 555 } 556 557 // Update last_checked for current to prevent multiple blocking requests if request hangs. 558 $last_update->last_checked = time(); 559 set_site_transient( 'update_themes', $last_update ); 560 561 $request['themes'] = $themes; 562 563 $locales = array_values( get_available_languages() ); 564 565 /** 566 * Filters the locales requested for theme translations. 567 * 568 * @since 3.7.0 569 * @since 4.5.0 The default value of the `$locales` parameter changed to include all locales. 570 * 571 * @param array $locales Theme locales. Default is all available locales of the site. 572 */ 573 $locales = apply_filters( 'themes_update_check_locales', $locales ); 574 $locales = array_unique( $locales ); 575 576 if ( $doing_cron ) { 577 $timeout = 30; 578 } else { 579 // Three seconds, plus one extra second for every 10 themes. 580 $timeout = 3 + (int) ( count( $themes ) / 10 ); 581 } 582 583 $options = array( 584 'timeout' => $timeout, 585 'body' => array( 586 'themes' => wp_json_encode( $request ), 587 'translations' => wp_json_encode( $translations ), 588 'locale' => wp_json_encode( $locales ), 589 ), 590 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ), 591 ); 592 593 if ( $extra_stats ) { 594 $options['body']['update_stats'] = wp_json_encode( $extra_stats ); 595 } 596 597 $url = 'http://api.wordpress.org/themes/update-check/1.1/'; 598 $http_url = $url; 599 $ssl = wp_http_supports( array( 'ssl' ) ); 600 601 if ( $ssl ) { 602 $url = set_url_scheme( $url, 'https' ); 603 } 604 605 $raw_response = wp_remote_post( $url, $options ); 606 607 if ( $ssl && is_wp_error( $raw_response ) ) { 608 trigger_error( 609 sprintf( 610 /* translators: %s: Support forums URL. */ 611 __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="%s">support forums</a>.' ), 612 __( 'https://wordpress.org/support/forums/' ) 613 ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), 614 headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE 615 ); 616 $raw_response = wp_remote_post( $http_url, $options ); 617 } 618 619 if ( is_wp_error( $raw_response ) || 200 !== wp_remote_retrieve_response_code( $raw_response ) ) { 620 return; 621 } 622 623 $new_update = new stdClass; 624 $new_update->last_checked = time(); 625 $new_update->checked = $checked; 626 627 $response = json_decode( wp_remote_retrieve_body( $raw_response ), true ); 628 629 if ( is_array( $response ) ) { 630 $new_update->response = $response['themes']; 631 $new_update->no_update = $response['no_update']; 632 $new_update->translations = $response['translations']; 633 } 634 635 set_site_transient( 'update_themes', $new_update ); 636 } 637 638 /** 639 * Performs WordPress automatic background updates. 640 * 641 * Updates WordPress core plus any plugins and themes that have automatic updates enabled. 642 * 643 * @since 3.7.0 644 */ 645 function wp_maybe_auto_update() { 646 include_once ABSPATH . 'wp-admin/includes/admin.php'; 647 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 648 649 $upgrader = new WP_Automatic_Updater; 650 $upgrader->run(); 651 } 652 653 /** 654 * Retrieves a list of all language updates available. 655 * 656 * @since 3.7.0 657 * 658 * @return object[] Array of translation objects that have available updates. 659 */ 660 function wp_get_translation_updates() { 661 $updates = array(); 662 $transients = array( 663 'update_core' => 'core', 664 'update_plugins' => 'plugin', 665 'update_themes' => 'theme', 666 ); 667 668 foreach ( $transients as $transient => $type ) { 669 $transient = get_site_transient( $transient ); 670 671 if ( empty( $transient->translations ) ) { 672 continue; 673 } 674 675 foreach ( $transient->translations as $translation ) { 676 $updates[] = (object) $translation; 677 } 678 } 679 680 return $updates; 681 } 682 683 /** 684 * Collect counts and UI strings for available updates 685 * 686 * @since 3.3.0 687 * 688 * @return array 689 */ 690 function wp_get_update_data() { 691 $counts = array( 692 'plugins' => 0, 693 'themes' => 0, 694 'wordpress' => 0, 695 'translations' => 0, 696 ); 697 698 $plugins = current_user_can( 'update_plugins' ); 699 700 if ( $plugins ) { 701 $update_plugins = get_site_transient( 'update_plugins' ); 702 703 if ( ! empty( $update_plugins->response ) ) { 704 $counts['plugins'] = count( $update_plugins->response ); 705 } 706 } 707 708 $themes = current_user_can( 'update_themes' ); 709 710 if ( $themes ) { 711 $update_themes = get_site_transient( 'update_themes' ); 712 713 if ( ! empty( $update_themes->response ) ) { 714 $counts['themes'] = count( $update_themes->response ); 715 } 716 } 717 718 $core = current_user_can( 'update_core' ); 719 720 if ( $core && function_exists( 'get_core_updates' ) ) { 721 $update_wordpress = get_core_updates( array( 'dismissed' => false ) ); 722 723 if ( ! empty( $update_wordpress ) 724 && ! in_array( $update_wordpress[0]->response, array( 'development', 'latest' ), true ) 725 && current_user_can( 'update_core' ) 726 ) { 727 $counts['wordpress'] = 1; 728 } 729 } 730 731 if ( ( $core || $plugins || $themes ) && wp_get_translation_updates() ) { 732 $counts['translations'] = 1; 733 } 734 735 $counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress'] + $counts['translations']; 736 $titles = array(); 737 738 if ( $counts['wordpress'] ) { 739 /* translators: %d: Number of available WordPress updates. */ 740 $titles['wordpress'] = sprintf( __( '%d WordPress Update' ), $counts['wordpress'] ); 741 } 742 743 if ( $counts['plugins'] ) { 744 /* translators: %d: Number of available plugin updates. */ 745 $titles['plugins'] = sprintf( _n( '%d Plugin Update', '%d Plugin Updates', $counts['plugins'] ), $counts['plugins'] ); 746 } 747 748 if ( $counts['themes'] ) { 749 /* translators: %d: Number of available theme updates. */ 750 $titles['themes'] = sprintf( _n( '%d Theme Update', '%d Theme Updates', $counts['themes'] ), $counts['themes'] ); 751 } 752 753 if ( $counts['translations'] ) { 754 $titles['translations'] = __( 'Translation Updates' ); 755 } 756 757 $update_title = $titles ? esc_attr( implode( ', ', $titles ) ) : ''; 758 759 $update_data = array( 760 'counts' => $counts, 761 'title' => $update_title, 762 ); 763 /** 764 * Filters the returned array of update data for plugins, themes, and WordPress core. 765 * 766 * @since 3.5.0 767 * 768 * @param array $update_data { 769 * Fetched update data. 770 * 771 * @type array $counts An array of counts for available plugin, theme, and WordPress updates. 772 * @type string $update_title Titles of available updates. 773 * } 774 * @param array $titles An array of update counts and UI strings for available updates. 775 */ 776 return apply_filters( 'wp_get_update_data', $update_data, $titles ); 777 } 778 779 /** 780 * Determines whether core should be updated. 781 * 782 * @since 2.8.0 783 * 784 * @global string $wp_version The WordPress version string. 785 */ 786 function _maybe_update_core() { 787 // Include an unmodified $wp_version. 788 require ABSPATH . WPINC . '/version.php'; 789 790 $current = get_site_transient( 'update_core' ); 791 792 if ( isset( $current->last_checked, $current->version_checked ) 793 && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) 794 && $current->version_checked === $wp_version 795 ) { 796 return; 797 } 798 799 wp_version_check(); 800 } 801 /** 802 * Check the last time plugins were run before checking plugin versions. 803 * 804 * This might have been backported to WordPress 2.6.1 for performance reasons. 805 * This is used for the wp-admin to check only so often instead of every page 806 * load. 807 * 808 * @since 2.7.0 809 * @access private 810 */ 811 function _maybe_update_plugins() { 812 $current = get_site_transient( 'update_plugins' ); 813 814 if ( isset( $current->last_checked ) 815 && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) 816 ) { 817 return; 818 } 819 820 wp_update_plugins(); 821 } 822 823 /** 824 * Check themes versions only after a duration of time. 825 * 826 * This is for performance reasons to make sure that on the theme version 827 * checker is not run on every page load. 828 * 829 * @since 2.7.0 830 * @access private 831 */ 832 function _maybe_update_themes() { 833 $current = get_site_transient( 'update_themes' ); 834 835 if ( isset( $current->last_checked ) 836 && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) 837 ) { 838 return; 839 } 840 841 wp_update_themes(); 842 } 843 844 /** 845 * Schedule core, theme, and plugin update checks. 846 * 847 * @since 3.1.0 848 */ 849 function wp_schedule_update_checks() { 850 if ( ! wp_next_scheduled( 'wp_version_check' ) && ! wp_installing() ) { 851 wp_schedule_event( time(), 'twicedaily', 'wp_version_check' ); 852 } 853 854 if ( ! wp_next_scheduled( 'wp_update_plugins' ) && ! wp_installing() ) { 855 wp_schedule_event( time(), 'twicedaily', 'wp_update_plugins' ); 856 } 857 858 if ( ! wp_next_scheduled( 'wp_update_themes' ) && ! wp_installing() ) { 859 wp_schedule_event( time(), 'twicedaily', 'wp_update_themes' ); 860 } 861 } 862 863 /** 864 * Clear existing update caches for plugins, themes, and core. 865 * 866 * @since 4.1.0 867 */ 868 function wp_clean_update_cache() { 869 if ( function_exists( 'wp_clean_plugins_cache' ) ) { 870 wp_clean_plugins_cache(); 871 } else { 872 delete_site_transient( 'update_plugins' ); 873 } 874 875 wp_clean_themes_cache(); 876 877 delete_site_transient( 'update_core' ); 878 } 879 880 if ( ( ! is_main_site() && ! is_network_admin() ) || wp_doing_ajax() ) { 881 return; 882 } 883 884 add_action( 'admin_init', '_maybe_update_core' ); 885 add_action( 'wp_version_check', 'wp_version_check' ); 886 887 add_action( 'load-plugins.php', 'wp_update_plugins' ); 888 add_action( 'load-update.php', 'wp_update_plugins' ); 889 add_action( 'load-update-core.php', 'wp_update_plugins' ); 890 add_action( 'admin_init', '_maybe_update_plugins' ); 891 add_action( 'wp_update_plugins', 'wp_update_plugins' ); 892 893 add_action( 'load-themes.php', 'wp_update_themes' ); 894 add_action( 'load-update.php', 'wp_update_themes' ); 895 add_action( 'load-update-core.php', 'wp_update_themes' ); 896 add_action( 'admin_init', '_maybe_update_themes' ); 897 add_action( 'wp_update_themes', 'wp_update_themes' ); 898 899 add_action( 'update_option_WPLANG', 'wp_clean_update_cache', 10, 0 ); 900 901 add_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' ); 902 903 add_action( 'init', 'wp_schedule_update_checks' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Apr 19 01:00:04 2021 | Cross-referenced by PHPXref 0.7.1 |