source: trunk/www.guidonia.net/wp/wp-admin/includes/update.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 7.4 KB
Line 
1<?php
2/**
3 * WordPress Administration Update API
4 *
5 * @package WordPress
6 * @subpackage Admin
7 */
8
9// The admin side of our 1.1 update system
10
11/**
12 * Selects the first update version from the update_core option
13 *
14 * @return object the response from the API
15 */
16function get_preferred_from_update_core() {
17 $updates = get_core_updates();
18 if ( !is_array( $updates ) )
19 return false;
20 if ( empty( $updates ) )
21 return (object)array('response' => 'latest');
22 return $updates[0];
23}
24
25/**
26 * Get available core updates
27 *
28 * @param array $options Set $options['dismissed'] to true to show dismissed upgrades too,
29 * set $options['available'] to false to skip not-dimissed updates.
30 * @return array Array of the update objects
31 */
32function get_core_updates( $options = array() ) {
33 $options = array_merge( array('available' => true, 'dismissed' => false ), $options );
34 $dismissed = get_option( 'dismissed_update_core' );
35 if ( !is_array( $dismissed ) ) $dismissed = array();
36 $from_api = get_transient( 'update_core' );
37 if ( empty($from_api) )
38 return false;
39 if ( !isset( $from_api->updates ) || !is_array( $from_api->updates ) ) return false;
40 $updates = $from_api->updates;
41 if ( !is_array( $updates ) ) return false;
42 $result = array();
43 foreach($updates as $update) {
44 if ( array_key_exists( $update->current.'|'.$update->locale, $dismissed ) ) {
45 if ( $options['dismissed'] ) {
46 $update->dismissed = true;
47 $result[]= $update;
48 }
49 } else {
50 if ( $options['available'] ) {
51 $update->dismissed = false;
52 $result[]= $update;
53 }
54 }
55 }
56 return $result;
57}
58
59function dismiss_core_update( $update ) {
60 $dismissed = get_option( 'dismissed_update_core' );
61 $dismissed[ $update->current.'|'.$update->locale ] = true;
62 return update_option( 'dismissed_update_core', $dismissed );
63}
64
65function undismiss_core_update( $version, $locale ) {
66 $dismissed = get_option( 'dismissed_update_core' );
67 $key = $version.'|'.$locale;
68 if ( !isset( $dismissed[$key] ) ) return false;
69 unset( $dismissed[$key] );
70 return update_option( 'dismissed_update_core', $dismissed );
71}
72
73function find_core_update( $version, $locale ) {
74 $from_api = get_transient( 'update_core' );
75 if ( !is_array( $from_api->updates ) ) return false;
76 $updates = $from_api->updates;
77 foreach($updates as $update) {
78 if ( $update->current == $version && $update->locale == $locale )
79 return $update;
80 }
81 return false;
82}
83
84function core_update_footer( $msg = '' ) {
85 if ( !current_user_can('manage_options') )
86 return sprintf( __( 'Version %s' ), $GLOBALS['wp_version'] );
87
88 $cur = get_preferred_from_update_core();
89 if ( ! isset( $cur->current ) )
90 $cur->current = '';
91
92 if ( ! isset( $cur->url ) )
93 $cur->url = '';
94
95 if ( ! isset( $cur->response ) )
96 $cur->response = '';
97
98 switch ( $cur->response ) {
99 case 'development' :
100 return sprintf( __( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ), $GLOBALS['wp_version'], 'update-core.php');
101 break;
102
103 case 'upgrade' :
104 if ( current_user_can('manage_options') ) {
105 return sprintf( '<strong>'.__( '<a href="%1$s">Get Version %2$s</a>' ).'</strong>', 'update-core.php', $cur->current);
106 break;
107 }
108
109 case 'latest' :
110 default :
111 return sprintf( __( 'Version %s' ), $GLOBALS['wp_version'] );
112 break;
113 }
114}
115add_filter( 'update_footer', 'core_update_footer' );
116
117function update_nag() {
118 global $pagenow;
119
120 if ( 'update-core.php' == $pagenow )
121 return;
122
123 $cur = get_preferred_from_update_core();
124
125 if ( ! isset( $cur->response ) || $cur->response != 'upgrade' )
126 return false;
127
128 if ( current_user_can('manage_options') )
129 $msg = sprintf( __('WordPress %1$s is available! <a href="%2$s">Please update now</a>.'), $cur->current, 'update-core.php' );
130 else
131 $msg = sprintf( __('WordPress %1$s is available! Please notify the site administrator.'), $cur->current );
132
133 echo "<div id='update-nag'>$msg</div>";
134}
135add_action( 'admin_notices', 'update_nag', 3 );
136
137// Called directly from dashboard
138function update_right_now_message() {
139 $cur = get_preferred_from_update_core();
140
141 $msg = sprintf( __('You are using <span class="b">WordPress %s</span>.'), $GLOBALS['wp_version'] );
142 if ( isset( $cur->response ) && $cur->response == 'upgrade' && current_user_can('manage_options') )
143 $msg .= " <a href='update-core.php' class='button'>" . sprintf( __('Update to %s'), $cur->current ? $cur->current : __( 'Latest' ) ) . '</a>';
144
145 echo "<span id='wp-version-message'>$msg</span>";
146}
147
148function wp_plugin_update_row( $file, $plugin_data ) {
149 $current = get_transient( 'update_plugins' );
150 if ( !isset( $current->response[ $file ] ) )
151 return false;
152
153 $r = $current->response[ $file ];
154
155 $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array());
156 $plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags );
157
158 $details_url = admin_url('plugin-install.php?tab=plugin-information&plugin=' . $r->slug . '&TB_iframe=true&width=600&height=800');
159
160 echo '<tr class="plugin-update-tr"><td colspan="3" class="plugin-update"><div class="update-message">';
161 if ( ! current_user_can('update_plugins') )
162 printf( __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s Details</a>.'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version );
163 else if ( empty($r->package) )
164 printf( __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s Details</a> <em>automatic upgrade unavailable for this plugin</em>.'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version );
165 else
166 printf( __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%3$s">View version %4$s Details</a> or <a href="%5$s">upgrade automatically</a>.'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version, wp_nonce_url('update.php?action=upgrade-plugin&plugin=' . $file, 'upgrade-plugin_' . $file) );
167
168 do_action( "in_plugin_update_message-$file", $plugin_data, $r );
169
170 echo '</div></td></tr>';
171}
172add_action( 'after_plugin_row', 'wp_plugin_update_row', 10, 2 );
173
174function wp_update_plugin($plugin, $feedback = '') {
175
176 if ( !empty($feedback) )
177 add_filter('update_feedback', $feedback);
178
179 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
180 $upgrader = new Plugin_Upgrader();
181 return $upgrader->upgrade($plugin);
182}
183
184function wp_update_theme($theme, $feedback = '') {
185
186 if ( !empty($feedback) )
187 add_filter('update_feedback', $feedback);
188
189 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
190 $upgrader = new Theme_Upgrader();
191 return $upgrader->upgrade($theme);
192}
193
194
195function wp_update_core($current, $feedback = '') {
196
197 if ( !empty($feedback) )
198 add_filter('update_feedback', $feedback);
199
200 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
201 $upgrader = new Core_Upgrader();
202 return $upgrader->upgrade($current);
203
204}
205
206function maintenance_nag() {
207 global $upgrading;
208 if ( ! isset( $upgrading ) )
209 return false;
210
211 if ( current_user_can('manage_options') )
212 $msg = sprintf( __('An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.'), 'update-core.php' );
213 else
214 $msg = __('An automated WordPress update has failed to complete! Please notify the site administrator.');
215
216 echo "<div id='update-nag'>$msg</div>";
217}
218add_action( 'admin_notices', 'maintenance_nag' );
219
220?>
Note: See TracBrowser for help on using the repository browser.