+ $url = $http_url = 'http://api.wordpress.org/plugins/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="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 );
+ $raw_response = wp_remote_post( $http_url, $options );
+ }
+
+ if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )
+ return false;
+
+ $response = json_decode( wp_remote_retrieve_body( $raw_response ), true );
+ foreach ( $response['plugins'] as &$plugin ) {
+ $plugin = (object) $plugin;
+ }
+ unset( $plugin );
+ foreach ( $response['no_update'] as &$plugin ) {
+ $plugin = (object) $plugin;
+ }
+ unset( $plugin );
+
+ if ( is_array( $response ) ) {
+ $new_option->response = $response['plugins'];
+ $new_option->translations = $response['translations'];
+ // TODO: Perhaps better to store no_update in a separate transient with an expiry?
+ $new_option->no_update = $response['no_update'];
+ } else {
+ $new_option->response = array();
+ $new_option->translations = array();
+ $new_option->no_update = array();
+ }
+
+ set_site_transient( 'update_plugins', $new_option );
+}
+
+/**
+ * Check theme versions against the latest versions hosted on WordPress.org.
+ *
+ * A list of all themes installed in sent to WP. Checks against the
+ * WordPress server at api.wordpress.org. Will only check if WordPress isn't
+ * installing.
+ *
+ * @since 2.7.0
+ * @uses $wp_version Used to notify the WordPress version.
+ *
+ * @param array $extra_stats Extra statistics to report to the WordPress.org API.
+ * @return false|null Returns null if update is unsupported. Returns false if check is too soon.
+ */
+function wp_update_themes( $extra_stats = array() ) {
+ include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
+
+ if ( defined( 'WP_INSTALLING' ) )
+ return false;
+
+ $installed_themes = wp_get_themes();
+ $translations = wp_get_installed_translations( 'themes' );
+
+ $last_update = get_site_transient( 'update_themes' );
+ if ( ! is_object($last_update) )
+ $last_update = new stdClass;
+
+ $themes = $checked = $request = array();
+
+ // Put slug of current theme into request.
+ $request['active'] = get_option( 'stylesheet' );
+
+ foreach ( $installed_themes as $theme ) {
+ $checked[ $theme->get_stylesheet() ] = $theme->get('Version');
+
+ $themes[ $theme->get_stylesheet() ] = array(
+ 'Name' => $theme->get('Name'),
+ 'Title' => $theme->get('Name'),
+ 'Version' => $theme->get('Version'),
+ 'Author' => $theme->get('Author'),
+ 'Author URI' => $theme->get('AuthorURI'),
+ 'Template' => $theme->get_template(),
+ 'Stylesheet' => $theme->get_stylesheet(),
+ );
+ }
+
+ // Check for update on a different schedule, depending on the page.
+ switch ( current_filter() ) {
+ case 'upgrader_process_complete' :
+ $timeout = 0;
+ break;
+ case 'load-update-core.php' :
+ $timeout = MINUTE_IN_SECONDS;
+ break;
+ case 'load-themes.php' :
+ case 'load-update.php' :
+ $timeout = HOUR_IN_SECONDS;
+ break;
+ default :
+ if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
+ $timeout = 0;
+ } else {
+ $timeout = 12 * HOUR_IN_SECONDS;
+ }
+ }
+
+ $time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time() - $last_update->last_checked );
+
+ if ( $time_not_changed && ! $extra_stats ) {
+ $theme_changed = false;
+ foreach ( $checked as $slug => $v ) {
+ if ( !isset( $last_update->checked[ $slug ] ) || strval($last_update->checked[ $slug ]) !== strval($v) )
+ $theme_changed = true;
+ }
+
+ if ( isset ( $last_update->response ) && is_array( $last_update->response ) ) {
+ foreach ( $last_update->response as $slug => $update_details ) {
+ if ( ! isset($checked[ $slug ]) ) {
+ $theme_changed = true;
+ break;
+ }
+ }