/wp-includes/update.php

  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. Checks against the 
  13. * WordPress server at api.wordpress.org server. Will only check if WordPress 
  14. * isn't installing. 
  15. * 
  16. * @since 2.3.0 
  17. * @global string $wp_version Used to check against the newest WordPress version. 
  18. * @global wpdb $wpdb 
  19. * @global string $wp_local_package 
  20. * 
  21. * @param array $extra_stats Extra statistics to report to the WordPress.org API. 
  22. * @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. 
  23. */ 
  24. function wp_version_check( $extra_stats = array(), $force_check = false ) { 
  25. if ( wp_installing() ) { 
  26. return; 
  27.  
  28. global $wpdb, $wp_local_package; 
  29. // include an unmodified $wp_version 
  30. include( ABSPATH . WPINC . '/version.php' ); 
  31. $php_version = phpversion(); 
  32.  
  33. $current = get_site_transient( 'update_core' ); 
  34. $translations = wp_get_installed_translations( 'core' ); 
  35.  
  36. // Invalidate the transient when $wp_version changes 
  37. if ( is_object( $current ) && $wp_version != $current->version_checked ) 
  38. $current = false; 
  39.  
  40. if ( ! is_object($current) ) { 
  41. $current = new stdClass; 
  42. $current->updates = array(); 
  43. $current->version_checked = $wp_version; 
  44.  
  45. if ( ! empty( $extra_stats ) ) 
  46. $force_check = true; 
  47.  
  48. // Wait 60 seconds between multiple version check requests 
  49. $timeout = 60; 
  50. $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked ); 
  51. if ( ! $force_check && $time_not_changed ) { 
  52. return; 
  53.  
  54. /** 
  55. * Filters the locale requested for WordPress core translations. 
  56. * 
  57. * @since 2.8.0 
  58. * 
  59. * @param string $locale Current locale. 
  60. */ 
  61. $locale = apply_filters( 'core_version_check_locale', get_locale() ); 
  62.  
  63. // Update last_checked for current to prevent multiple blocking requests if request hangs 
  64. $current->last_checked = time(); 
  65. set_site_transient( 'update_core', $current ); 
  66.  
  67. if ( method_exists( $wpdb, 'db_version' ) ) 
  68. $mysql_version = preg_replace('/[^0-9.].*/', '', $wpdb->db_version()); 
  69. else 
  70. $mysql_version = 'N/A'; 
  71.  
  72. if ( is_multisite() ) { 
  73. $user_count = get_user_count(); 
  74. $num_blogs = get_blog_count(); 
  75. $wp_install = network_site_url(); 
  76. $multisite_enabled = 1; 
  77. } else { 
  78. $user_count = count_users(); 
  79. $user_count = $user_count['total_users']; 
  80. $multisite_enabled = 0; 
  81. $num_blogs = 1; 
  82. $wp_install = home_url( '/' ); 
  83.  
  84. $query = array( 
  85. 'version' => $wp_version,  
  86. 'php' => $php_version,  
  87. 'locale' => $locale,  
  88. 'mysql' => $mysql_version,  
  89. 'local_package' => isset( $wp_local_package ) ? $wp_local_package : '',  
  90. 'blogs' => $num_blogs,  
  91. 'users' => $user_count,  
  92. 'multisite_enabled' => $multisite_enabled,  
  93. 'initial_db_version' => get_site_option( 'initial_db_version' ),  
  94. ); 
  95.  
  96. $post_body = array( 
  97. 'translations' => wp_json_encode( $translations ),  
  98. ); 
  99.  
  100. if ( is_array( $extra_stats ) ) 
  101. $post_body = array_merge( $post_body, $extra_stats ); 
  102.  
  103. $url = $http_url = 'http://api.wordpress.org/core/version-check/1.7/?' . http_build_query( $query, null, '&' ); 
  104. if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) 
  105. $url = set_url_scheme( $url, 'https' ); 
  106.  
  107. $options = array( 
  108. 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ),  
  109. 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),  
  110. 'headers' => array( 
  111. 'wp_install' => $wp_install,  
  112. 'wp_blog' => home_url( '/' ) 
  113. ),  
  114. 'body' => $post_body,  
  115. ); 
  116.  
  117. $response = wp_remote_post( $url, $options ); 
  118. if ( $ssl && is_wp_error( $response ) ) { 
  119. trigger_error( 
  120. sprintf( 
  121. /** translators: %s: support forums URL */ 
  122. __( '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>.' ),  
  123. __( 'https://wordpress.org/support/' ) 
  124. ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),  
  125. headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE 
  126. ); 
  127. $response = wp_remote_post( $http_url, $options ); 
  128.  
  129. if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) { 
  130. return; 
  131.  
  132. $body = trim( wp_remote_retrieve_body( $response ) ); 
  133. $body = json_decode( $body, true ); 
  134.  
  135. if ( ! is_array( $body ) || ! isset( $body['offers'] ) ) { 
  136. return; 
  137.  
  138. $offers = $body['offers']; 
  139.  
  140. foreach ( $offers as &$offer ) { 
  141. foreach ( $offer as $offer_key => $value ) { 
  142. if ( 'packages' == $offer_key ) 
  143. $offer['packages'] = (object) array_intersect_key( array_map( 'esc_url', $offer['packages'] ),  
  144. array_fill_keys( array( 'full', 'no_content', 'new_bundled', 'partial', 'rollback' ), '' ) ); 
  145. elseif ( 'download' == $offer_key ) 
  146. $offer['download'] = esc_url( $value ); 
  147. else 
  148. $offer[ $offer_key ] = esc_html( $value ); 
  149. $offer = (object) array_intersect_key( $offer, array_fill_keys( array( 'response', 'download', 'locale',  
  150. 'packages', 'current', 'version', 'php_version', 'mysql_version', 'new_bundled', 'partial_version', 'notify_email', 'support_email', 'new_files' ), '' ) ); 
  151.  
  152. $updates = new stdClass(); 
  153. $updates->updates = $offers; 
  154. $updates->last_checked = time(); 
  155. $updates->version_checked = $wp_version; 
  156.  
  157. if ( isset( $body['translations'] ) ) 
  158. $updates->translations = $body['translations']; 
  159.  
  160. set_site_transient( 'update_core', $updates ); 
  161.  
  162. if ( ! empty( $body['ttl'] ) ) { 
  163. $ttl = (int) $body['ttl']; 
  164. if ( $ttl && ( time() + $ttl < wp_next_scheduled( 'wp_version_check' ) ) ) { 
  165. // Queue an event to re-run the update check in $ttl seconds. 
  166. wp_schedule_single_event( time() + $ttl, 'wp_version_check' ); 
  167.  
  168. // Trigger background updates if running non-interactively, and we weren't called from the update handler. 
  169. if ( defined( 'DOING_CRON' ) && DOING_CRON && ! doing_action( 'wp_maybe_auto_update' ) ) { 
  170. do_action( 'wp_maybe_auto_update' ); 
  171.  
  172. /** 
  173. * Check plugin versions against the latest versions hosted on WordPress.org. 
  174. * 
  175. * The WordPress version, PHP version, and Locale is sent along with a list of 
  176. * all plugins installed. Checks against the WordPress server at 
  177. * api.wordpress.org. Will only check if WordPress isn't installing. 
  178. * 
  179. * @since 2.3.0 
  180. * @global string $wp_version Used to notify the WordPress version. 
  181. * 
  182. * @param array $extra_stats Extra statistics to report to the WordPress.org API. 
  183. */ 
  184. function wp_update_plugins( $extra_stats = array() ) { 
  185. if ( wp_installing() ) { 
  186. return; 
  187.  
  188. // include an unmodified $wp_version 
  189. include( ABSPATH . WPINC . '/version.php' ); 
  190.  
  191. // If running blog-side, bail unless we've not checked in the last 12 hours 
  192. if ( !function_exists( 'get_plugins' ) ) 
  193. require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 
  194.  
  195. $plugins = get_plugins(); 
  196. $translations = wp_get_installed_translations( 'plugins' ); 
  197.  
  198. $active = get_option( 'active_plugins', array() ); 
  199. $current = get_site_transient( 'update_plugins' ); 
  200. if ( ! is_object($current) ) 
  201. $current = new stdClass; 
  202.  
  203. $new_option = new stdClass; 
  204. $new_option->last_checked = time(); 
  205.  
  206. // Check for update on a different schedule, depending on the page. 
  207. switch ( current_filter() ) { 
  208. case 'upgrader_process_complete' : 
  209. $timeout = 0; 
  210. break; 
  211. case 'load-update-core.php' : 
  212. $timeout = MINUTE_IN_SECONDS; 
  213. break; 
  214. case 'load-plugins.php' : 
  215. case 'load-update.php' : 
  216. $timeout = HOUR_IN_SECONDS; 
  217. break; 
  218. default : 
  219. if ( defined( 'DOING_CRON' ) && DOING_CRON ) { 
  220. $timeout = 0; 
  221. } else { 
  222. $timeout = 12 * HOUR_IN_SECONDS; 
  223.  
  224. $time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked ); 
  225.  
  226. if ( $time_not_changed && ! $extra_stats ) { 
  227. $plugin_changed = false; 
  228. foreach ( $plugins as $file => $p ) { 
  229. $new_option->checked[ $file ] = $p['Version']; 
  230.  
  231. if ( !isset( $current->checked[ $file ] ) || strval($current->checked[ $file ]) !== strval($p['Version']) ) 
  232. $plugin_changed = true; 
  233.  
  234. if ( isset ( $current->response ) && is_array( $current->response ) ) { 
  235. foreach ( $current->response as $plugin_file => $update_details ) { 
  236. if ( ! isset($plugins[ $plugin_file ]) ) { 
  237. $plugin_changed = true; 
  238. break; 
  239.  
  240. // Bail if we've checked recently and if nothing has changed 
  241. if ( ! $plugin_changed ) { 
  242. return; 
  243.  
  244. // Update last_checked for current to prevent multiple blocking requests if request hangs 
  245. $current->last_checked = time(); 
  246. set_site_transient( 'update_plugins', $current ); 
  247.  
  248. $to_send = compact( 'plugins', 'active' ); 
  249.  
  250. $locales = array_values( get_available_languages() ); 
  251.  
  252. /** 
  253. * Filters the locales requested for plugin translations. 
  254. * 
  255. * @since 3.7.0 
  256. * @since 4.5.0 The default value of the `$locales` parameter changed to include all locales. 
  257. * 
  258. * @param array $locales Plugin locales. Default is all available locales of the site. 
  259. */ 
  260. $locales = apply_filters( 'plugins_update_check_locales', $locales ); 
  261. $locales = array_unique( $locales ); 
  262.  
  263. if ( defined( 'DOING_CRON' ) && DOING_CRON ) { 
  264. $timeout = 30; 
  265. } else { 
  266. // Three seconds, plus one extra second for every 10 plugins 
  267. $timeout = 3 + (int) ( count( $plugins ) / 10 ); 
  268.  
  269. $options = array( 
  270. 'timeout' => $timeout,  
  271. 'body' => array( 
  272. 'plugins' => wp_json_encode( $to_send ),  
  273. 'translations' => wp_json_encode( $translations ),  
  274. 'locale' => wp_json_encode( $locales ),  
  275. 'all' => wp_json_encode( true ),  
  276. ),  
  277. 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 
  278. ); 
  279.  
  280. if ( $extra_stats ) { 
  281. $options['body']['update_stats'] = wp_json_encode( $extra_stats ); 
  282.  
  283. $url = $http_url = 'http://api.wordpress.org/plugins/update-check/1.1/'; 
  284. if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) 
  285. $url = set_url_scheme( $url, 'https' ); 
  286.  
  287. $raw_response = wp_remote_post( $url, $options ); 
  288. if ( $ssl && is_wp_error( $raw_response ) ) { 
  289. trigger_error( 
  290. sprintf( 
  291. /** translators: %s: support forums URL */ 
  292. __( '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>.' ),  
  293. __( 'https://wordpress.org/support/' ) 
  294. ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),  
  295. headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE 
  296. ); 
  297. $raw_response = wp_remote_post( $http_url, $options ); 
  298.  
  299. if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) { 
  300. return; 
  301.  
  302. $response = json_decode( wp_remote_retrieve_body( $raw_response ), true ); 
  303. foreach ( $response['plugins'] as &$plugin ) { 
  304. $plugin = (object) $plugin; 
  305. if ( isset( $plugin->compatibility ) ) { 
  306. $plugin->compatibility = (object) $plugin->compatibility; 
  307. foreach ( $plugin->compatibility as &$data ) { 
  308. $data = (object) $data; 
  309. unset( $plugin, $data ); 
  310. foreach ( $response['no_update'] as &$plugin ) { 
  311. $plugin = (object) $plugin; 
  312. unset( $plugin ); 
  313.  
  314. if ( is_array( $response ) ) { 
  315. $new_option->response = $response['plugins']; 
  316. $new_option->translations = $response['translations']; 
  317. // TODO: Perhaps better to store no_update in a separate transient with an expiry? 
  318. $new_option->no_update = $response['no_update']; 
  319. } else { 
  320. $new_option->response = array(); 
  321. $new_option->translations = array(); 
  322. $new_option->no_update = array(); 
  323.  
  324. set_site_transient( 'update_plugins', $new_option ); 
  325.  
  326. /** 
  327. * Check theme versions against the latest versions hosted on WordPress.org. 
  328. * 
  329. * A list of all themes installed in sent to WP. Checks against the 
  330. * WordPress server at api.wordpress.org. Will only check if WordPress isn't 
  331. * installing. 
  332. * 
  333. * @since 2.7.0 
  334. * 
  335. * @param array $extra_stats Extra statistics to report to the WordPress.org API. 
  336. */ 
  337. function wp_update_themes( $extra_stats = array() ) { 
  338. if ( wp_installing() ) { 
  339. return; 
  340.  
  341. // include an unmodified $wp_version 
  342. include( ABSPATH . WPINC . '/version.php' ); 
  343.  
  344. $installed_themes = wp_get_themes(); 
  345. $translations = wp_get_installed_translations( 'themes' ); 
  346.  
  347. $last_update = get_site_transient( 'update_themes' ); 
  348. if ( ! is_object($last_update) ) 
  349. $last_update = new stdClass; 
  350.  
  351. $themes = $checked = $request = array(); 
  352.  
  353. // Put slug of current theme into request. 
  354. $request['active'] = get_option( 'stylesheet' ); 
  355.  
  356. foreach ( $installed_themes as $theme ) { 
  357. $checked[ $theme->get_stylesheet() ] = $theme->get('Version'); 
  358.  
  359. $themes[ $theme->get_stylesheet() ] = array( 
  360. 'Name' => $theme->get('Name'),  
  361. 'Title' => $theme->get('Name'),  
  362. 'Version' => $theme->get('Version'),  
  363. 'Author' => $theme->get('Author'),  
  364. 'Author URI' => $theme->get('AuthorURI'),  
  365. 'Template' => $theme->get_template(),  
  366. 'Stylesheet' => $theme->get_stylesheet(),  
  367. ); 
  368.  
  369. // Check for update on a different schedule, depending on the page. 
  370. switch ( current_filter() ) { 
  371. case 'upgrader_process_complete' : 
  372. $timeout = 0; 
  373. break; 
  374. case 'load-update-core.php' : 
  375. $timeout = MINUTE_IN_SECONDS; 
  376. break; 
  377. case 'load-themes.php' : 
  378. case 'load-update.php' : 
  379. $timeout = HOUR_IN_SECONDS; 
  380. break; 
  381. default : 
  382. if ( defined( 'DOING_CRON' ) && DOING_CRON ) { 
  383. $timeout = 0; 
  384. } else { 
  385. $timeout = 12 * HOUR_IN_SECONDS; 
  386.  
  387. $time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time() - $last_update->last_checked ); 
  388.  
  389. if ( $time_not_changed && ! $extra_stats ) { 
  390. $theme_changed = false; 
  391. foreach ( $checked as $slug => $v ) { 
  392. if ( !isset( $last_update->checked[ $slug ] ) || strval($last_update->checked[ $slug ]) !== strval($v) ) 
  393. $theme_changed = true; 
  394.  
  395. if ( isset ( $last_update->response ) && is_array( $last_update->response ) ) { 
  396. foreach ( $last_update->response as $slug => $update_details ) { 
  397. if ( ! isset($checked[ $slug ]) ) { 
  398. $theme_changed = true; 
  399. break; 
  400.  
  401. // Bail if we've checked recently and if nothing has changed 
  402. if ( ! $theme_changed ) { 
  403. return; 
  404.  
  405. // Update last_checked for current to prevent multiple blocking requests if request hangs 
  406. $last_update->last_checked = time(); 
  407. set_site_transient( 'update_themes', $last_update ); 
  408.  
  409. $request['themes'] = $themes; 
  410.  
  411. $locales = array_values( get_available_languages() ); 
  412.  
  413. /** 
  414. * Filters the locales requested for theme translations. 
  415. * 
  416. * @since 3.7.0 
  417. * @since 4.5.0 The default value of the `$locales` parameter changed to include all locales. 
  418. * 
  419. * @param array $locales Theme locales. Default is all available locales of the site. 
  420. */ 
  421. $locales = apply_filters( 'themes_update_check_locales', $locales ); 
  422. $locales = array_unique( $locales ); 
  423.  
  424. if ( defined( 'DOING_CRON' ) && DOING_CRON ) { 
  425. $timeout = 30; 
  426. } else { 
  427. // Three seconds, plus one extra second for every 10 themes 
  428. $timeout = 3 + (int) ( count( $themes ) / 10 ); 
  429.  
  430. $options = array( 
  431. 'timeout' => $timeout,  
  432. 'body' => array( 
  433. 'themes' => wp_json_encode( $request ),  
  434. 'translations' => wp_json_encode( $translations ),  
  435. 'locale' => wp_json_encode( $locales ),  
  436. ),  
  437. 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 
  438. ); 
  439.  
  440. if ( $extra_stats ) { 
  441. $options['body']['update_stats'] = wp_json_encode( $extra_stats ); 
  442.  
  443. $url = $http_url = 'http://api.wordpress.org/themes/update-check/1.1/'; 
  444. if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) 
  445. $url = set_url_scheme( $url, 'https' ); 
  446.  
  447. $raw_response = wp_remote_post( $url, $options ); 
  448. if ( $ssl && is_wp_error( $raw_response ) ) { 
  449. trigger_error( 
  450. sprintf( 
  451. /** translators: %s: support forums URL */ 
  452. __( '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>.' ),  
  453. __( 'https://wordpress.org/support/' ) 
  454. ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ),  
  455. headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE 
  456. ); 
  457. $raw_response = wp_remote_post( $http_url, $options ); 
  458.  
  459. if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) { 
  460. return; 
  461.  
  462. $new_update = new stdClass; 
  463. $new_update->last_checked = time(); 
  464. $new_update->checked = $checked; 
  465.  
  466. $response = json_decode( wp_remote_retrieve_body( $raw_response ), true ); 
  467.  
  468. if ( is_array( $response ) ) { 
  469. $new_update->response = $response['themes']; 
  470. $new_update->translations = $response['translations']; 
  471.  
  472. set_site_transient( 'update_themes', $new_update ); 
  473.  
  474. /** 
  475. * Performs WordPress automatic background updates. 
  476. * 
  477. * @since 3.7.0 
  478. */ 
  479. function wp_maybe_auto_update() { 
  480. include_once( ABSPATH . '/wp-admin/includes/admin.php' ); 
  481. include_once( ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' ); 
  482.  
  483. $upgrader = new WP_Automatic_Updater; 
  484. $upgrader->run(); 
  485.  
  486. /** 
  487. * Retrieves a list of all language updates available. 
  488. * 
  489. * @since 3.7.0 
  490. * 
  491. * @return array 
  492. */ 
  493. function wp_get_translation_updates() { 
  494. $updates = array(); 
  495. $transients = array( 'update_core' => 'core', 'update_plugins' => 'plugin', 'update_themes' => 'theme' ); 
  496. foreach ( $transients as $transient => $type ) { 
  497. $transient = get_site_transient( $transient ); 
  498. if ( empty( $transient->translations ) ) 
  499. continue; 
  500.  
  501. foreach ( $transient->translations as $translation ) { 
  502. $updates[] = (object) $translation; 
  503. return $updates; 
  504.  
  505. /** 
  506. * Collect counts and UI strings for available updates 
  507. * 
  508. * @since 3.3.0 
  509. * 
  510. * @return array 
  511. */ 
  512. function wp_get_update_data() { 
  513. $counts = array( 'plugins' => 0, 'themes' => 0, 'wordpress' => 0, 'translations' => 0 ); 
  514.  
  515. if ( $plugins = current_user_can( 'update_plugins' ) ) { 
  516. $update_plugins = get_site_transient( 'update_plugins' ); 
  517. if ( ! empty( $update_plugins->response ) ) 
  518. $counts['plugins'] = count( $update_plugins->response ); 
  519.  
  520. if ( $themes = current_user_can( 'update_themes' ) ) { 
  521. $update_themes = get_site_transient( 'update_themes' ); 
  522. if ( ! empty( $update_themes->response ) ) 
  523. $counts['themes'] = count( $update_themes->response ); 
  524.  
  525. if ( ( $core = current_user_can( 'update_core' ) ) && function_exists( 'get_core_updates' ) ) { 
  526. $update_wordpress = get_core_updates( array('dismissed' => false) ); 
  527. if ( ! empty( $update_wordpress ) && ! in_array( $update_wordpress[0]->response, array('development', 'latest') ) && current_user_can('update_core') ) 
  528. $counts['wordpress'] = 1; 
  529.  
  530. if ( ( $core || $plugins || $themes ) && wp_get_translation_updates() ) 
  531. $counts['translations'] = 1; 
  532.  
  533. $counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress'] + $counts['translations']; 
  534. $titles = array(); 
  535. if ( $counts['wordpress'] ) { 
  536. /** translators: 1: Number of updates available to WordPress */ 
  537. $titles['wordpress'] = sprintf( __( '%d WordPress Update'), $counts['wordpress'] ); 
  538. if ( $counts['plugins'] ) { 
  539. /** translators: 1: Number of updates available to plugins */ 
  540. $titles['plugins'] = sprintf( _n( '%d Plugin Update', '%d Plugin Updates', $counts['plugins'] ), $counts['plugins'] ); 
  541. if ( $counts['themes'] ) { 
  542. /** translators: 1: Number of updates available to themes */ 
  543. $titles['themes'] = sprintf( _n( '%d Theme Update', '%d Theme Updates', $counts['themes'] ), $counts['themes'] ); 
  544. if ( $counts['translations'] ) { 
  545. $titles['translations'] = __( 'Translation Updates' ); 
  546.  
  547. $update_title = $titles ? esc_attr( implode( ', ', $titles ) ) : ''; 
  548.  
  549. $update_data = array( 'counts' => $counts, 'title' => $update_title ); 
  550. /** 
  551. * Filters the returned array of update data for plugins, themes, and WordPress core. 
  552. * 
  553. * @since 3.5.0 
  554. * 
  555. * @param array $update_data { 
  556. * Fetched update data. 
  557. * 
  558. * @type array $counts An array of counts for available plugin, theme, and WordPress updates. 
  559. * @type string $update_title Titles of available updates. 
  560. * } 
  561. * @param array $titles An array of update counts and UI strings for available updates. 
  562. */ 
  563. return apply_filters( 'wp_get_update_data', $update_data, $titles ); 
  564.  
  565. /** 
  566. * Determines whether core should be updated. 
  567. * 
  568. * @since 2.8.0 
  569. * 
  570. * @global string $wp_version 
  571. */ 
  572. function _maybe_update_core() { 
  573. // include an unmodified $wp_version 
  574. include( ABSPATH . WPINC . '/version.php' ); 
  575.  
  576. $current = get_site_transient( 'update_core' ); 
  577.  
  578. if ( isset( $current->last_checked, $current->version_checked ) && 
  579. 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) && 
  580. $current->version_checked == $wp_version ) { 
  581. return; 
  582. wp_version_check(); 
  583. /** 
  584. * Check the last time plugins were run before checking plugin versions. 
  585. * 
  586. * This might have been backported to WordPress 2.6.1 for performance reasons. 
  587. * This is used for the wp-admin to check only so often instead of every page 
  588. * load. 
  589. * 
  590. * @since 2.7.0 
  591. * @access private 
  592. */ 
  593. function _maybe_update_plugins() { 
  594. $current = get_site_transient( 'update_plugins' ); 
  595. if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) ) 
  596. return; 
  597. wp_update_plugins(); 
  598.  
  599. /** 
  600. * Check themes versions only after a duration of time. 
  601. * 
  602. * This is for performance reasons to make sure that on the theme version 
  603. * checker is not run on every page load. 
  604. * 
  605. * @since 2.7.0 
  606. * @access private 
  607. */ 
  608. function _maybe_update_themes() { 
  609. $current = get_site_transient( 'update_themes' ); 
  610. if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) ) 
  611. return; 
  612. wp_update_themes(); 
  613.  
  614. /** 
  615. * Schedule core, theme, and plugin update checks. 
  616. * 
  617. * @since 3.1.0 
  618. */ 
  619. function wp_schedule_update_checks() { 
  620. if ( ! wp_next_scheduled( 'wp_version_check' ) && ! wp_installing() ) 
  621. wp_schedule_event(time(), 'twicedaily', 'wp_version_check'); 
  622.  
  623. if ( ! wp_next_scheduled( 'wp_update_plugins' ) && ! wp_installing() ) 
  624. wp_schedule_event(time(), 'twicedaily', 'wp_update_plugins'); 
  625.  
  626. if ( ! wp_next_scheduled( 'wp_update_themes' ) && ! wp_installing() ) 
  627. wp_schedule_event(time(), 'twicedaily', 'wp_update_themes'); 
  628.  
  629. /** 
  630. * Clear existing update caches for plugins, themes, and core. 
  631. * 
  632. * @since 4.1.0 
  633. */ 
  634. function wp_clean_update_cache() { 
  635. if ( function_exists( 'wp_clean_plugins_cache' ) ) { 
  636. wp_clean_plugins_cache(); 
  637. } else { 
  638. delete_site_transient( 'update_plugins' ); 
  639. wp_clean_themes_cache(); 
  640. delete_site_transient( 'update_core' ); 
  641.  
  642. if ( ( ! is_main_site() && ! is_network_admin() ) || wp_doing_ajax() ) { 
  643. return; 
  644.  
  645. add_action( 'admin_init', '_maybe_update_core' ); 
  646. add_action( 'wp_version_check', 'wp_version_check' ); 
  647.  
  648. add_action( 'load-plugins.php', 'wp_update_plugins' ); 
  649. add_action( 'load-update.php', 'wp_update_plugins' ); 
  650. add_action( 'load-update-core.php', 'wp_update_plugins' ); 
  651. add_action( 'admin_init', '_maybe_update_plugins' ); 
  652. add_action( 'wp_update_plugins', 'wp_update_plugins' ); 
  653.  
  654. add_action( 'load-themes.php', 'wp_update_themes' ); 
  655. add_action( 'load-update.php', 'wp_update_themes' ); 
  656. add_action( 'load-update-core.php', 'wp_update_themes' ); 
  657. add_action( 'admin_init', '_maybe_update_themes' ); 
  658. add_action( 'wp_update_themes', 'wp_update_themes' ); 
  659.  
  660. add_action( 'update_option_WPLANG', 'wp_clean_update_cache' , 10, 0 ); 
  661.  
  662. add_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' ); 
  663.  
  664. add_action( 'init', 'wp_schedule_update_checks' ); 
.