55 } |
55 } |
56 return $result; |
56 return $result; |
57 } |
57 } |
58 |
58 |
59 function dismiss_core_update( $update ) { |
59 function dismiss_core_update( $update ) { |
60 $dismissed = get_option( 'dismissed_update_core' ); |
60 $dismissed = get_site_option( 'dismissed_update_core' ); |
61 $dismissed[ $update->current.'|'.$update->locale ] = true; |
61 $dismissed[ $update->current.'|'.$update->locale ] = true; |
62 return update_option( 'dismissed_update_core', $dismissed ); |
62 return update_site_option( 'dismissed_update_core', $dismissed ); |
63 } |
63 } |
64 |
64 |
65 function undismiss_core_update( $version, $locale ) { |
65 function undismiss_core_update( $version, $locale ) { |
66 $dismissed = get_option( 'dismissed_update_core' ); |
66 $dismissed = get_site_option( 'dismissed_update_core' ); |
67 $key = $version.'|'.$locale; |
67 $key = $version.'|'.$locale; |
68 if ( !isset( $dismissed[$key] ) ) return false; |
68 if ( !isset( $dismissed[$key] ) ) return false; |
69 unset( $dismissed[$key] ); |
69 unset( $dismissed[$key] ); |
70 return update_option( 'dismissed_update_core', $dismissed ); |
70 return update_site_option( 'dismissed_update_core', $dismissed ); |
71 } |
71 } |
72 |
72 |
73 function find_core_update( $version, $locale ) { |
73 function find_core_update( $version, $locale ) { |
74 $from_api = get_transient( 'update_core' ); |
74 $from_api = get_site_transient( 'update_core' ); |
75 if ( !is_array( $from_api->updates ) ) return false; |
75 if ( !is_array( $from_api->updates ) ) return false; |
76 $updates = $from_api->updates; |
76 $updates = $from_api->updates; |
77 foreach($updates as $update) { |
77 foreach($updates as $update) { |
78 if ( $update->current == $version && $update->locale == $locale ) |
78 if ( $update->current == $version && $update->locale == $locale ) |
79 return $update; |
79 return $update; |
80 } |
80 } |
81 return false; |
81 return false; |
82 } |
82 } |
83 |
83 |
84 function core_update_footer( $msg = '' ) { |
84 function core_update_footer( $msg = '' ) { |
85 if ( !current_user_can('manage_options') ) |
85 if ( !current_user_can('update_core') ) |
86 return sprintf( __( 'Version %s' ), $GLOBALS['wp_version'] ); |
86 return sprintf( __( 'Version %s' ), $GLOBALS['wp_version'] ); |
87 |
87 |
88 $cur = get_preferred_from_update_core(); |
88 $cur = get_preferred_from_update_core(); |
89 if ( ! isset( $cur->current ) ) |
89 if ( ! isset( $cur->current ) ) |
90 $cur->current = ''; |
90 $cur->current = ''; |
95 if ( ! isset( $cur->response ) ) |
95 if ( ! isset( $cur->response ) ) |
96 $cur->response = ''; |
96 $cur->response = ''; |
97 |
97 |
98 switch ( $cur->response ) { |
98 switch ( $cur->response ) { |
99 case 'development' : |
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'); |
100 return sprintf( __( 'You are using a development version (%1$s). Cool! Please <a href="%2$s">stay updated</a>.' ), $GLOBALS['wp_version'], network_admin_url( 'update-core.php' ) ); |
101 break; |
101 break; |
102 |
102 |
103 case 'upgrade' : |
103 case 'upgrade' : |
104 if ( current_user_can('manage_options') ) { |
104 return sprintf( '<strong>'.__( '<a href="%1$s">Get Version %2$s</a>' ).'</strong>', network_admin_url( 'update-core.php' ), $cur->current); |
105 return sprintf( '<strong>'.__( '<a href="%1$s">Get Version %2$s</a>' ).'</strong>', 'update-core.php', $cur->current); |
105 break; |
106 break; |
|
107 } |
|
108 |
106 |
109 case 'latest' : |
107 case 'latest' : |
110 default : |
108 default : |
111 return sprintf( __( 'Version %s' ), $GLOBALS['wp_version'] ); |
109 return sprintf( __( 'Version %s' ), $GLOBALS['wp_version'] ); |
112 break; |
110 break; |
113 } |
111 } |
114 } |
112 } |
115 add_filter( 'update_footer', 'core_update_footer' ); |
113 add_filter( 'update_footer', 'core_update_footer' ); |
116 |
114 |
117 function update_nag() { |
115 function update_nag() { |
|
116 if ( is_multisite() && !current_user_can('update_core') ) |
|
117 return false; |
|
118 |
118 global $pagenow; |
119 global $pagenow; |
119 |
120 |
120 if ( 'update-core.php' == $pagenow ) |
121 if ( 'update-core.php' == $pagenow ) |
121 return; |
122 return; |
122 |
123 |
123 $cur = get_preferred_from_update_core(); |
124 $cur = get_preferred_from_update_core(); |
124 |
125 |
125 if ( ! isset( $cur->response ) || $cur->response != 'upgrade' ) |
126 if ( ! isset( $cur->response ) || $cur->response != 'upgrade' ) |
126 return false; |
127 return false; |
127 |
128 |
128 if ( current_user_can('manage_options') ) |
129 if ( current_user_can('update_core') ) { |
129 $msg = sprintf( __('WordPress %1$s is available! <a href="%2$s">Please update now</a>.'), $cur->current, 'update-core.php' ); |
130 $msg = sprintf( __('<a href="http://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> is available! <a href="%2$s">Please update now</a>.'), $cur->current, network_admin_url( 'update-core.php' ) ); |
130 else |
131 } else { |
131 $msg = sprintf( __('WordPress %1$s is available! Please notify the site administrator.'), $cur->current ); |
132 $msg = sprintf( __('<a href="http://codex.wordpress.org/Version_%1$s">WordPress %1$s</a> is available! Please notify the site administrator.'), $cur->current ); |
132 |
133 } |
133 echo "<div id='update-nag'>$msg</div>"; |
134 echo "<div class='update-nag'>$msg</div>"; |
134 } |
135 } |
135 add_action( 'admin_notices', 'update_nag', 3 ); |
136 add_action( 'admin_notices', 'update_nag', 3 ); |
136 |
137 |
137 // Called directly from dashboard |
138 // Called directly from dashboard |
138 function update_right_now_message() { |
139 function 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'] ); |
140 $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') ) |
141 |
143 $msg .= " <a href='update-core.php' class='button'>" . sprintf( __('Update to %s'), $cur->current ? $cur->current : __( 'Latest' ) ) . '</a>'; |
142 if ( current_user_can('update_core') ) { |
|
143 $cur = get_preferred_from_update_core(); |
|
144 |
|
145 if ( isset( $cur->response ) && $cur->response == 'upgrade' ) |
|
146 $msg .= " <a href='" . network_admin_url( 'update-core.php' ) . "' class='button'>" . sprintf( __('Update to %s'), $cur->current ? $cur->current : __( 'Latest' ) ) . '</a>'; |
|
147 } |
144 |
148 |
145 echo "<span id='wp-version-message'>$msg</span>"; |
149 echo "<span id='wp-version-message'>$msg</span>"; |
146 } |
150 } |
147 |
151 |
148 function get_plugin_updates() { |
152 function get_plugin_updates() { |
149 $all_plugins = get_plugins(); |
153 $all_plugins = get_plugins(); |
150 $upgrade_plugins = array(); |
154 $upgrade_plugins = array(); |
151 $current = get_transient( 'update_plugins' ); |
155 $current = get_site_transient( 'update_plugins' ); |
152 foreach ( (array)$all_plugins as $plugin_file => $plugin_data) { |
156 foreach ( (array)$all_plugins as $plugin_file => $plugin_data) { |
153 if ( isset( $current->response[ $plugin_file ] ) ) { |
157 if ( isset( $current->response[ $plugin_file ] ) ) { |
154 $upgrade_plugins[ $plugin_file ] = (object) $plugin_data; |
158 $upgrade_plugins[ $plugin_file ] = (object) $plugin_data; |
155 $upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ]; |
159 $upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ]; |
156 } |
160 } |
158 |
162 |
159 return $upgrade_plugins; |
163 return $upgrade_plugins; |
160 } |
164 } |
161 |
165 |
162 function wp_plugin_update_rows() { |
166 function wp_plugin_update_rows() { |
163 $plugins = get_transient( 'update_plugins' ); |
167 if ( !current_user_can('update_plugins' ) ) |
|
168 return; |
|
169 |
|
170 $plugins = get_site_transient( 'update_plugins' ); |
164 if ( isset($plugins->response) && is_array($plugins->response) ) { |
171 if ( isset($plugins->response) && is_array($plugins->response) ) { |
165 $plugins = array_keys( $plugins->response ); |
172 $plugins = array_keys( $plugins->response ); |
166 foreach( $plugins as $plugin_file ) { |
173 foreach( $plugins as $plugin_file ) { |
167 add_action( "after_plugin_row_$plugin_file", 'wp_plugin_update_row', 10, 2 ); |
174 add_action( "after_plugin_row_$plugin_file", 'wp_plugin_update_row', 10, 2 ); |
168 } |
175 } |
169 } |
176 } |
170 } |
177 } |
171 add_action( 'admin_init', 'wp_plugin_update_rows' ); |
178 add_action( 'admin_init', 'wp_plugin_update_rows' ); |
172 |
179 |
173 function wp_plugin_update_row( $file, $plugin_data ) { |
180 function wp_plugin_update_row( $file, $plugin_data ) { |
174 $current = get_transient( 'update_plugins' ); |
181 $current = get_site_transient( 'update_plugins' ); |
175 if ( !isset( $current->response[ $file ] ) ) |
182 if ( !isset( $current->response[ $file ] ) ) |
176 return false; |
183 return false; |
177 |
184 |
178 $r = $current->response[ $file ]; |
185 $r = $current->response[ $file ]; |
179 |
186 |
180 $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array()); |
187 $plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array()); |
181 $plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags ); |
188 $plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags ); |
182 |
189 |
183 $details_url = admin_url('plugin-install.php?tab=plugin-information&plugin=' . $r->slug . '&TB_iframe=true&width=600&height=800'); |
190 $details_url = self_admin_url('plugin-install.php?tab=plugin-information&plugin=' . $r->slug . '§ion=changelog&TB_iframe=true&width=600&height=800'); |
184 |
191 |
185 echo '<tr class="plugin-update-tr"><td colspan="3" class="plugin-update"><div class="update-message">'; |
192 $wp_list_table = _get_list_table('WP_Plugins_List_Table'); |
186 if ( ! current_user_can('update_plugins') ) |
193 |
187 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 ); |
194 if ( is_network_admin() || !is_multisite() ) { |
188 else if ( empty($r->package) ) |
195 echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; |
189 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 ); |
196 |
190 else |
197 if ( ! current_user_can('update_plugins') ) |
191 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) ); |
198 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 ); |
192 |
199 else if ( empty($r->package) ) |
193 do_action( "in_plugin_update_message-$file", $plugin_data, $r ); |
200 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 update is unavailable for this plugin.</em>'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version ); |
194 |
201 else |
195 echo '</div></td></tr>'; |
202 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">update now</a>.'), $plugin_name, esc_url($details_url), esc_attr($plugin_name), $r->new_version, wp_nonce_url( self_admin_url('update.php?action=upgrade-plugin&plugin=') . $file, 'upgrade-plugin_' . $file) ); |
|
203 |
|
204 do_action( "in_plugin_update_message-$file", $plugin_data, $r ); |
|
205 |
|
206 echo '</div></td></tr>'; |
|
207 } |
196 } |
208 } |
197 |
209 |
198 function wp_update_plugin($plugin, $feedback = '') { |
210 function wp_update_plugin($plugin, $feedback = '') { |
199 |
|
200 if ( !empty($feedback) ) |
211 if ( !empty($feedback) ) |
201 add_filter('update_feedback', $feedback); |
212 add_filter('update_feedback', $feedback); |
202 |
213 |
203 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
214 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
204 $upgrader = new Plugin_Upgrader(); |
215 $upgrader = new Plugin_Upgrader(); |
205 return $upgrader->upgrade($plugin); |
216 return $upgrader->upgrade($plugin); |
206 } |
217 } |
207 |
218 |
208 function get_theme_updates() { |
219 function get_theme_updates() { |
209 $themes = get_themes(); |
220 $themes = wp_get_themes(); |
210 $current = get_transient('update_themes'); |
221 $current = get_site_transient('update_themes'); |
|
222 |
|
223 if ( ! isset( $current->response ) ) |
|
224 return array(); |
|
225 |
211 $update_themes = array(); |
226 $update_themes = array(); |
212 |
227 foreach ( $current->response as $stylesheet => $data ) { |
213 foreach ( $themes as $theme ) { |
228 $update_themes[ $stylesheet ] = wp_get_theme( $stylesheet ); |
214 $theme = (object) $theme; |
229 $update_themes[ $stylesheet ]->update = $data; |
215 if ( isset($current->response[ $theme->Stylesheet ]) ) { |
|
216 $update_themes[$theme->Stylesheet] = $theme; |
|
217 $update_themes[$theme->Stylesheet]->update = $current->response[ $theme->Stylesheet ]; |
|
218 } |
|
219 } |
230 } |
220 |
231 |
221 return $update_themes; |
232 return $update_themes; |
222 } |
233 } |
223 |
234 |
224 function wp_update_theme($theme, $feedback = '') { |
235 function wp_update_theme($theme, $feedback = '') { |
225 |
|
226 if ( !empty($feedback) ) |
236 if ( !empty($feedback) ) |
227 add_filter('update_feedback', $feedback); |
237 add_filter('update_feedback', $feedback); |
228 |
238 |
229 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
239 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
230 $upgrader = new Theme_Upgrader(); |
240 $upgrader = new Theme_Upgrader(); |
231 return $upgrader->upgrade($theme); |
241 return $upgrader->upgrade($theme); |
232 } |
242 } |
233 |
243 |
|
244 function wp_theme_update_rows() { |
|
245 if ( !current_user_can('update_themes' ) ) |
|
246 return; |
|
247 |
|
248 $themes = get_site_transient( 'update_themes' ); |
|
249 if ( isset($themes->response) && is_array($themes->response) ) { |
|
250 $themes = array_keys( $themes->response ); |
|
251 |
|
252 foreach( $themes as $theme ) { |
|
253 add_action( "after_theme_row_$theme", 'wp_theme_update_row', 10, 2 ); |
|
254 } |
|
255 } |
|
256 } |
|
257 add_action( 'admin_init', 'wp_theme_update_rows' ); |
|
258 |
|
259 function wp_theme_update_row( $theme_key, $theme ) { |
|
260 $current = get_site_transient( 'update_themes' ); |
|
261 if ( !isset( $current->response[ $theme_key ] ) ) |
|
262 return false; |
|
263 $r = $current->response[ $theme_key ]; |
|
264 $themes_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array()); |
|
265 $theme_name = wp_kses( $theme['Name'], $themes_allowedtags ); |
|
266 |
|
267 $details_url = add_query_arg( array( 'TB_iframe' => 'true', 'width' => 1024, 'height' => 800 ), $current->response[ $theme_key ]['url'] ); |
|
268 |
|
269 $wp_list_table = _get_list_table('WP_MS_Themes_List_Table'); |
|
270 |
|
271 echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; |
|
272 if ( ! current_user_can('update_themes') ) |
|
273 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>.'), $theme['Name'], esc_url($details_url), esc_attr($theme['Name']), $r->new_version ); |
|
274 else if ( empty( $r['package'] ) ) |
|
275 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 update is unavailable for this theme.</em>'), $theme['Name'], esc_url($details_url), esc_attr($theme['Name']), $r['new_version'] ); |
|
276 else |
|
277 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">update now</a>.'), $theme['Name'], esc_url($details_url), esc_attr($theme['Name']), $r['new_version'], wp_nonce_url( self_admin_url('update.php?action=upgrade-theme&theme=') . $theme_key, 'upgrade-theme_' . $theme_key) ); |
|
278 |
|
279 do_action( "in_theme_update_message-$theme_key", $theme, $r ); |
|
280 |
|
281 echo '</div></td></tr>'; |
|
282 } |
234 |
283 |
235 function wp_update_core($current, $feedback = '') { |
284 function wp_update_core($current, $feedback = '') { |
236 |
|
237 if ( !empty($feedback) ) |
285 if ( !empty($feedback) ) |
238 add_filter('update_feedback', $feedback); |
286 add_filter('update_feedback', $feedback); |
239 |
287 |
240 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
288 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
241 $upgrader = new Core_Upgrader(); |
289 $upgrader = new Core_Upgrader(); |