3 // The admin side of our 1.0 update system
5 function core_update_footer( $msg ) {
6 if ( !current_user_can('manage_options') )
7 return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'] );
9 $cur = get_option( 'update_core' );
11 switch ( $cur->response ) {
13 return sprintf( '| '.__( 'You are using a development version (%s). Cool! Please <a href="%s">stay updated</a>.' ), $GLOBALS['wp_version'], 'http://wordpress.org/download/svn/' );
17 return sprintf( '| <strong>'.__( 'Your WordPress %s is out of date. <a href="%s">Please update</a>.' ).'</strong>', $GLOBALS['wp_version'], $cur->url );
22 return sprintf( '| '.__( 'Version %s' ), $GLOBALS['wp_version'] );
26 add_filter( 'update_footer', 'core_update_footer' );
28 function update_nag() {
29 $cur = get_option( 'update_core' );
31 if ( ! isset( $cur->response ) || $cur->response != 'upgrade' )
34 if ( current_user_can('manage_options') )
35 $msg = sprintf( __('A new version of WordPress is available! <a href="%s">Please update now</a>.'), $cur->url );
37 $msg = __('A new version of WordPress is available! Please notify the site administrator.');
39 echo "<div id='update-nag'>$msg</div>";
41 add_action( 'admin_notices', 'update_nag', 3 );
43 function wp_update_plugins() {
46 if ( !function_exists('fsockopen') )
49 $plugins = get_plugins();
50 $active = get_option( 'active_plugins' );
51 $current = get_option( 'update_plugins' );
54 $new_option->last_checked = time();
56 $plugin_changed = false;
57 foreach ( $plugins as $file => $p ) {
58 $new_option->checked[ $file ] = $p['Version'];
60 if ( !isset( $current->checked[ $file ] ) ) {
61 $plugin_changed = true;
65 if ( $current->checked[ $file ] != $p['Version'] )
66 $plugin_changed = true;
70 isset( $current->last_checked ) &&
71 43200 > ( time() - $current->last_checked ) &&
76 $to_send->plugins = $plugins;
77 $to_send->active = $active;
78 $send = serialize( $to_send );
80 $request = 'plugins=' . urlencode( $send );
81 $http_request = "POST /plugins/update-check/1.0/ HTTP/1.0\r\n";
82 $http_request .= "Host: api.wordpress.org\r\n";
83 $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=" . get_option('blog_charset') . "\r\n";
84 $http_request .= "Content-Length: " . strlen($request) . "\r\n";
85 $http_request .= 'User-Agent: WordPress/' . $wp_version . '; ' . get_bloginfo('url') . "\r\n";
86 $http_request .= "\r\n";
87 $http_request .= $request;
90 if( false != ( $fs = @fsockopen( 'api.wordpress.org', 80, $errno, $errstr, 3) ) && is_resource($fs) ) {
91 fwrite($fs, $http_request);
94 $response .= fgets($fs, 1160); // One TCP-IP packet
96 $response = explode("\r\n\r\n", $response, 2);
99 $response = unserialize( $response[1] );
102 $new_option->response = $response;
104 update_option( 'update_plugins', $new_option );
106 add_action( 'load-plugins.php', 'wp_update_plugins' );
108 function wp_plugin_update_row( $file ) {
110 $current = get_option( 'update_plugins' );
111 if ( !isset( $current->response[ $file ] ) )
114 $r = $current->response[ $file ];
116 echo "<tr><td colspan='5' class='plugin-update'>";
117 printf( __('There is a new version of %s available. <a href="%s">Download version %s here</a>.'), $plugin_data['Name'], $r->url, $r->new_version );
120 add_action( 'after_plugin_row', 'wp_plugin_update_row' );