+ }
+
+ // Update last_checked for current to prevent multiple blocking requests if request hangs
+ $last_update->last_checked = time();
+ set_site_transient( 'update_themes', $last_update );
+
+ $request['themes'] = $themes;
+
+ $locales = array( get_locale() );
+ /**
+ * Filter the locales requested for theme translations.
+ *
+ * @since 3.7.0
+ *
+ * @param array $locales Theme locale. Default is current locale of the site.
+ */
+ $locales = apply_filters( 'themes_update_check_locales', $locales );
+
+ $options = array(
+ 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
+ 'body' => array(
+ 'themes' => json_encode( $request ),
+ 'translations' => json_encode( $translations ),
+ 'locale' => json_encode( $locales ),
+ ),
+ 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
+ );
+
+ $url = $http_url = 'http://api.wordpress.org/themes/update-check/1.1/';
+ if ( $ssl = wp_http_supports( array( 'ssl' ) ) )
+ $url = set_url_scheme( $url, 'https' );
+
+ $raw_response = wp_remote_post( $url, $options );
+ if ( $ssl && is_wp_error( $raw_response ) ) {
+ trigger_error( __( '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="http://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 );
+ $raw_response = wp_remote_post( $http_url, $options );
+ }
+
+ if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )
+ return false;
+
+ $new_update = new stdClass;
+ $new_update->last_checked = time();
+ $new_update->checked = $checked;
+
+ $response = json_decode( wp_remote_retrieve_body( $raw_response ), true );
+
+ if ( is_array( $response ) ) {
+ $new_update->response = $response['themes'];
+ $new_update->translations = $response['translations'];
+ }
+
+ set_site_transient( 'update_themes', $new_update );
+}
+
+/**
+ * Performs WordPress automatic background updates.
+ *
+ * @since 3.7.0
+ */
+function wp_maybe_auto_update() {
+ include_once ABSPATH . '/wp-admin/includes/admin.php';
+ include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
+
+ $upgrader = new WP_Automatic_Updater;
+ $upgrader->run();
+}
+
+/**
+ * Retrieves a list of all language updates available.
+ *
+ * @since 3.7.0
+ */
+function wp_get_translation_updates() {
+ $updates = array();
+ $transients = array( 'update_core' => 'core', 'update_plugins' => 'plugin', 'update_themes' => 'theme' );
+ foreach ( $transients as $transient => $type ) {
+
+ $transient = get_site_transient( $transient );
+ if ( empty( $transient->translations ) )
+ continue;
+
+ foreach ( $transient->translations as $translation ) {
+ $updates[] = (object) $translation;
+ }
+ }
+
+ return $updates;
+}
+
+/*
+ * Collect counts and UI strings for available updates
+ *
+ * @since 3.3.0
+ *
+ * @return array
+ */
+function wp_get_update_data() {
+ $counts = array( 'plugins' => 0, 'themes' => 0, 'wordpress' => 0, 'translations' => 0 );
+
+ if ( $plugins = current_user_can( 'update_plugins' ) ) {
+ $update_plugins = get_site_transient( 'update_plugins' );
+ if ( ! empty( $update_plugins->response ) )
+ $counts['plugins'] = count( $update_plugins->response );
+ }
+
+ if ( $themes = current_user_can( 'update_themes' ) ) {
+ $update_themes = get_site_transient( 'update_themes' );
+ if ( ! empty( $update_themes->response ) )
+ $counts['themes'] = count( $update_themes->response );
+ }
+
+ if ( ( $core = current_user_can( 'update_core' ) ) && function_exists( 'get_core_updates' ) ) {
+ $update_wordpress = get_core_updates( array('dismissed' => false) );
+ if ( ! empty( $update_wordpress ) && ! in_array( $update_wordpress[0]->response, array('development', 'latest') ) && current_user_can('update_core') )
+ $counts['wordpress'] = 1;
+ }
+
+ if ( ( $core || $plugins || $themes ) && wp_get_translation_updates() )
+ $counts['translations'] = 1;
+
+ $counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress'] + $counts['translations'];
+ $titles = array();
+ if ( $counts['wordpress'] )
+ $titles['wordpress'] = sprintf( __( '%d WordPress Update'), $counts['wordpress'] );
+ if ( $counts['plugins'] )
+ $titles['plugins'] = sprintf( _n( '%d Plugin Update', '%d Plugin Updates', $counts['plugins'] ), $counts['plugins'] );
+ if ( $counts['themes'] )
+ $titles['themes'] = sprintf( _n( '%d Theme Update', '%d Theme Updates', $counts['themes'] ), $counts['themes'] );
+ if ( $counts['translations'] )
+ $titles['translations'] = __( 'Translation Updates' );
+
+ $update_title = $titles ? esc_attr( implode( ', ', $titles ) ) : '';
+
+ $update_data = array( 'counts' => $counts, 'title' => $update_title );
+ /**
+ * Filter the returned array of update data for plugins, themes, and WordPress core.
+ *
+ * @since 3.5.0
+ *
+ * @param array $update_data {
+ * Fetched update data.
+ *
+ * @type array $counts An array of counts for available plugin, theme, and WordPress updates.
+ * @type string $update_title Titles of available updates.
+ * }
+ * @param array $titles An array of update counts and UI strings for available updates.
+ */
+ return apply_filters( 'wp_get_update_data', $update_data, $titles );
+}
+
+function _maybe_update_core() {
+ include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version
+
+ $current = get_site_transient( 'update_core' );
+
+ if ( isset( $current->last_checked ) &&
+ 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) &&
+ isset( $current->version_checked ) &&
+ $current->version_checked == $wp_version )
+ return;
+
+ wp_version_check();
+}
+/**
+ * Check the last time plugins were run before checking plugin versions.
+ *
+ * This might have been backported to WordPress 2.6.1 for performance reasons.
+ * This is used for the wp-admin to check only so often instead of every page
+ * load.
+ *
+ * @since 2.7.0
+ * @access private
+ */
+function _maybe_update_plugins() {
+ $current = get_site_transient( 'update_plugins' );
+ if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) )
+ return;
+ wp_update_plugins();
+}
+
+/**
+ * Check themes versions only after a duration of time.
+ *
+ * This is for performance reasons to make sure that on the theme version
+ * checker is not run on every page load.
+ *
+ * @since 2.7.0
+ * @access private
+ */
+function _maybe_update_themes() {
+ $current = get_site_transient( 'update_themes' );
+ if ( isset( $current->last_checked ) && 12 * HOUR_IN_SECONDS > ( time() - $current->last_checked ) )
+ return;