3 // A simple set of functions to check our version 1.0 update service
5 function wp_version_check() {
6 if ( !function_exists('fsockopen') || strpos($_SERVER['PHP_SELF'], 'install.php') !== false || defined('WP_INSTALLING') )
10 $php_version = phpversion();
12 $current = get_option( 'update_core' );
13 $locale = get_locale();
16 isset( $current->last_checked ) &&
17 43200 > ( time() - $current->last_checked ) &&
18 $current->version_checked == $wp_version
23 $new_option->last_checked = time(); // this gets set whether we get a response or not, so if something is down or misconfigured it won't delay the page load for more than 3 seconds, twice a day
24 $new_option->version_checked = $wp_version;
26 $http_request = "GET /core/version-check/1.0/?version=$wp_version&php=$php_version&locale=$locale HTTP/1.0\r\n";
27 $http_request .= "Host: api.wordpress.org\r\n";
28 $http_request .= 'Content-Type: application/x-www-form-urlencoded; charset=' . get_option('blog_charset') . "\r\n";
29 $http_request .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n";
30 $http_request .= "\r\n";
33 if ( false !== ( $fs = @fsockopen( 'api.wordpress.org', 80, $errno, $errstr, 3 ) ) && is_resource($fs) ) {
34 fwrite( $fs, $http_request );
35 while ( !feof( $fs ) )
36 $response .= fgets( $fs, 1160 ); // One TCP-IP packet
39 $response = explode("\r\n\r\n", $response, 2);
40 $body = trim( $response[1] );
41 $body = str_replace(array("\r\n", "\r"), "\n", $body);
43 $returns = explode("\n", $body);
45 $new_option->response = $returns[0];
46 if ( isset( $returns[1] ) )
47 $new_option->url = $returns[1];
49 update_option( 'update_core', $new_option );
52 add_action( 'init', 'wp_version_check' );