- $to_send->plugins = $plugins;
- $to_send->active = $active;
- $send = serialize( $to_send );
-
- $request = 'plugins=' . urlencode( $send );
- $http_request = "POST /plugins/update-check/1.0/ HTTP/1.0\r\n";
- $http_request .= "Host: api.wordpress.org\r\n";
- $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=" . get_option('blog_charset') . "\r\n";
- $http_request .= "Content-Length: " . strlen($request) . "\r\n";
- $http_request .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n";
- $http_request .= "\r\n";
- $http_request .= $request;
-
- $response = '';
- if( false != ( $fs = @fsockopen( 'api.wordpress.org', 80, $errno, $errstr, 3) ) && is_resource($fs) ) {
- fwrite($fs, $http_request);
-
- while ( !feof($fs) )
- $response .= fgets($fs, 1160); // One TCP-IP packet
- fclose($fs);
- $response = explode("\r\n\r\n", $response, 2);
+ // Update last_checked for current to prevent multiple blocking requests if request hangs
+ $current->last_checked = time();
+ set_transient( 'update_plugins', $current );
+
+ $to_send = (object)compact('plugins', 'active');
+
+ $options = array(
+ 'timeout' => 3,
+ 'body' => array( 'plugins' => serialize( $to_send ) ),
+ 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
+ );
+
+ $raw_response = wp_remote_post('http://api.wordpress.org/plugins/update-check/1.0/', $options);
+
+ if ( is_wp_error( $raw_response ) )
+ return false;
+
+ if( 200 != $raw_response['response']['code'] )
+ return false;
+
+ $response = unserialize( $raw_response['body'] );
+
+ if ( false !== $response )
+ $new_option->response = $response;
+ else
+ $new_option->response = array();
+
+ set_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.
+ *
+ * @package WordPress
+ * @since 2.7.0
+ * @uses $wp_version Used to notidy the WordPress version.
+ *
+ * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
+ */
+function wp_update_themes( ) {
+ global $wp_version;
+
+ if( defined( 'WP_INSTALLING' ) )
+ return false;
+
+ if( !function_exists( 'get_themes' ) )
+ require_once( ABSPATH . 'wp-includes/theme.php' );
+
+ $installed_themes = get_themes( );
+ $current_theme = get_transient( 'update_themes' );
+ if ( ! is_object($current_theme) )
+ $current_theme = new stdClass;
+
+ $new_option = new stdClass;
+ $new_option->last_checked = time( );
+ $timeout = 'load-themes.php' == current_filter() ? 3600 : 43200; //Check for updated every 60 minutes if hitting the themes page, Else, check every 12 hours
+ $time_not_changed = isset( $current_theme->last_checked ) && $timeout > ( time( ) - $current_theme->last_checked );
+
+ if( $time_not_changed )
+ return false;
+
+ // Update last_checked for current to prevent multiple blocking requests if request hangs
+ $current_theme->last_checked = time();
+ set_transient( 'update_themes', $current_theme );
+
+ $current_theme->template = get_option( 'template' );
+
+ $themes = array( );
+ $themes['current_theme'] = (array) $current_theme;
+ foreach( (array) $installed_themes as $theme_title => $theme ) {
+ $themes[$theme['Stylesheet']] = array( );
+
+ foreach( (array) $theme as $key => $value ) {
+ $themes[$theme['Stylesheet']][$key] = $value;
+ }