PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-includes/update.php

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