author | Anthony Ly <anthonyly.com@gmail.com> |
Tue, 11 Dec 2012 12:47:47 -0800 | |
changeset 198 | dcf82fd50cc6 |
parent 194 | 32102edaa81b |
child 204 | 09a1c134465b |
permissions | -rw-r--r-- |
136 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Administration Update API |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
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 |
*/ |
|
16 |
function 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, |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
29 |
* set $options['available'] to false to skip not-dismissed updates. |
136 | 30 |
* @return array Array of the update objects |
31 |
*/ |
|
32 |
function get_core_updates( $options = array() ) { |
|
33 |
$options = array_merge( array('available' => true, 'dismissed' => false ), $options ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
34 |
$dismissed = get_site_option( 'dismissed_update_core' ); |
136 | 35 |
if ( !is_array( $dismissed ) ) $dismissed = array(); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
36 |
$from_api = get_site_transient( 'update_core' ); |
136 | 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 |
||
59 |
function dismiss_core_update( $update ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
60 |
$dismissed = get_site_option( 'dismissed_update_core' ); |
136 | 61 |
$dismissed[ $update->current.'|'.$update->locale ] = true; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
62 |
return update_site_option( 'dismissed_update_core', $dismissed ); |
136 | 63 |
} |
64 |
||
65 |
function undismiss_core_update( $version, $locale ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
66 |
$dismissed = get_site_option( 'dismissed_update_core' ); |
136 | 67 |
$key = $version.'|'.$locale; |
68 |
if ( !isset( $dismissed[$key] ) ) return false; |
|
69 |
unset( $dismissed[$key] ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
70 |
return update_site_option( 'dismissed_update_core', $dismissed ); |
136 | 71 |
} |
72 |
||
73 |
function find_core_update( $version, $locale ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
74 |
$from_api = get_site_transient( 'update_core' ); |
136 | 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 |
||
84 |
function core_update_footer( $msg = '' ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
85 |
if ( !current_user_can('update_core') ) |
136 | 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' : |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
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' ) ); |
136 | 101 |
break; |
102 |
||
103 |
case 'upgrade' : |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
104 |
return sprintf( '<strong>'.__( '<a href="%1$s">Get Version %2$s</a>' ).'</strong>', network_admin_url( 'update-core.php' ), $cur->current); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
105 |
break; |
136 | 106 |
|
107 |
case 'latest' : |
|
108 |
default : |
|
109 |
return sprintf( __( 'Version %s' ), $GLOBALS['wp_version'] ); |
|
110 |
break; |
|
111 |
} |
|
112 |
} |
|
113 |
add_filter( 'update_footer', 'core_update_footer' ); |
|
114 |
||
115 |
function update_nag() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
116 |
if ( is_multisite() && !current_user_can('update_core') ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
117 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
118 |
|
136 | 119 |
global $pagenow; |
120 |
||
121 |
if ( 'update-core.php' == $pagenow ) |
|
122 |
return; |
|
123 |
||
124 |
$cur = get_preferred_from_update_core(); |
|
125 |
||
126 |
if ( ! isset( $cur->response ) || $cur->response != 'upgrade' ) |
|
127 |
return false; |
|
128 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
129 |
if ( current_user_can('update_core') ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
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' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
131 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
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 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
133 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
134 |
echo "<div class='update-nag'>$msg</div>"; |
136 | 135 |
} |
136 |
add_action( 'admin_notices', 'update_nag', 3 ); |
|
137 |
||
138 |
// Called directly from dashboard |
|
139 |
function update_right_now_message() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
140 |
$msg = sprintf( __('You are using <span class="b">WordPress %s</span>.'), $GLOBALS['wp_version'] ); |
136 | 141 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
142 |
if ( current_user_can('update_core') ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
143 |
$cur = get_preferred_from_update_core(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
144 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
145 |
if ( isset( $cur->response ) && $cur->response == 'upgrade' ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
146 |
$msg .= " <a href='" . network_admin_url( 'update-core.php' ) . "' class='button'>" . sprintf( __('Update to %s'), $cur->current ? $cur->current : __( 'Latest' ) ) . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
147 |
} |
136 | 148 |
|
149 |
echo "<span id='wp-version-message'>$msg</span>"; |
|
150 |
} |
|
151 |
||
152 |
function get_plugin_updates() { |
|
153 |
$all_plugins = get_plugins(); |
|
154 |
$upgrade_plugins = array(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
155 |
$current = get_site_transient( 'update_plugins' ); |
136 | 156 |
foreach ( (array)$all_plugins as $plugin_file => $plugin_data) { |
157 |
if ( isset( $current->response[ $plugin_file ] ) ) { |
|
158 |
$upgrade_plugins[ $plugin_file ] = (object) $plugin_data; |
|
159 |
$upgrade_plugins[ $plugin_file ]->update = $current->response[ $plugin_file ]; |
|
160 |
} |
|
161 |
} |
|
162 |
||
163 |
return $upgrade_plugins; |
|
164 |
} |
|
165 |
||
166 |
function wp_plugin_update_rows() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
167 |
if ( !current_user_can('update_plugins' ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
168 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
169 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
170 |
$plugins = get_site_transient( 'update_plugins' ); |
136 | 171 |
if ( isset($plugins->response) && is_array($plugins->response) ) { |
172 |
$plugins = array_keys( $plugins->response ); |
|
173 |
foreach( $plugins as $plugin_file ) { |
|
174 |
add_action( "after_plugin_row_$plugin_file", 'wp_plugin_update_row', 10, 2 ); |
|
175 |
} |
|
176 |
} |
|
177 |
} |
|
178 |
add_action( 'admin_init', 'wp_plugin_update_rows' ); |
|
179 |
||
180 |
function wp_plugin_update_row( $file, $plugin_data ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
181 |
$current = get_site_transient( 'update_plugins' ); |
136 | 182 |
if ( !isset( $current->response[ $file ] ) ) |
183 |
return false; |
|
184 |
||
185 |
$r = $current->response[ $file ]; |
|
186 |
||
187 |
$plugins_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array()); |
|
188 |
$plugin_name = wp_kses( $plugin_data['Name'], $plugins_allowedtags ); |
|
189 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
190 |
$details_url = self_admin_url('plugin-install.php?tab=plugin-information&plugin=' . $r->slug . '§ion=changelog&TB_iframe=true&width=600&height=800'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
191 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
192 |
$wp_list_table = _get_list_table('WP_Plugins_List_Table'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
193 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
194 |
if ( is_network_admin() || !is_multisite() ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
195 |
echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; |
136 | 196 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
197 |
if ( ! current_user_can('update_plugins') ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
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 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
199 |
else if ( empty($r->package) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
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 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
201 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
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) ); |
136 | 203 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
204 |
do_action( "in_plugin_update_message-$file", $plugin_data, $r ); |
136 | 205 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
206 |
echo '</div></td></tr>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
207 |
} |
136 | 208 |
} |
209 |
||
210 |
function wp_update_plugin($plugin, $feedback = '') { |
|
211 |
if ( !empty($feedback) ) |
|
212 |
add_filter('update_feedback', $feedback); |
|
213 |
||
214 |
include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
215 |
$upgrader = new Plugin_Upgrader(); |
|
216 |
return $upgrader->upgrade($plugin); |
|
217 |
} |
|
218 |
||
219 |
function get_theme_updates() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
220 |
$themes = wp_get_themes(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
221 |
$current = get_site_transient('update_themes'); |
136 | 222 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
223 |
if ( ! isset( $current->response ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
224 |
return array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
225 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
226 |
$update_themes = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
227 |
foreach ( $current->response as $stylesheet => $data ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
228 |
$update_themes[ $stylesheet ] = wp_get_theme( $stylesheet ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
229 |
$update_themes[ $stylesheet ]->update = $data; |
136 | 230 |
} |
231 |
||
232 |
return $update_themes; |
|
233 |
} |
|
234 |
||
235 |
function wp_update_theme($theme, $feedback = '') { |
|
236 |
if ( !empty($feedback) ) |
|
237 |
add_filter('update_feedback', $feedback); |
|
238 |
||
239 |
include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
240 |
$upgrader = new Theme_Upgrader(); |
|
241 |
return $upgrader->upgrade($theme); |
|
242 |
} |
|
243 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
244 |
function wp_theme_update_rows() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
245 |
if ( !current_user_can('update_themes' ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
246 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
247 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
248 |
$themes = get_site_transient( 'update_themes' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
249 |
if ( isset($themes->response) && is_array($themes->response) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
250 |
$themes = array_keys( $themes->response ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
251 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
252 |
foreach( $themes as $theme ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
253 |
add_action( "after_theme_row_$theme", 'wp_theme_update_row', 10, 2 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
254 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
255 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
256 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
257 |
add_action( 'admin_init', 'wp_theme_update_rows' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
258 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
259 |
function wp_theme_update_row( $theme_key, $theme ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
260 |
$current = get_site_transient( 'update_themes' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
261 |
if ( !isset( $current->response[ $theme_key ] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
262 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
263 |
$r = $current->response[ $theme_key ]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
264 |
$themes_allowedtags = array('a' => array('href' => array(),'title' => array()),'abbr' => array('title' => array()),'acronym' => array('title' => array()),'code' => array(),'em' => array(),'strong' => array()); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
265 |
$theme_name = wp_kses( $theme['Name'], $themes_allowedtags ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
266 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
267 |
$details_url = add_query_arg( array( 'TB_iframe' => 'true', 'width' => 1024, 'height' => 800 ), $current->response[ $theme_key ]['url'] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
268 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
269 |
$wp_list_table = _get_list_table('WP_MS_Themes_List_Table'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
270 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
271 |
echo '<tr class="plugin-update-tr"><td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"><div class="update-message">'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
272 |
if ( ! current_user_can('update_themes') ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
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 ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
274 |
else if ( empty( $r['package'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
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'] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
276 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
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) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
278 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
279 |
do_action( "in_theme_update_message-$theme_key", $theme, $r ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
280 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
281 |
echo '</div></td></tr>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
282 |
} |
136 | 283 |
|
284 |
function wp_update_core($current, $feedback = '') { |
|
285 |
if ( !empty($feedback) ) |
|
286 |
add_filter('update_feedback', $feedback); |
|
287 |
||
288 |
include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
|
289 |
$upgrader = new Core_Upgrader(); |
|
290 |
return $upgrader->upgrade($current); |
|
291 |
||
292 |
} |
|
293 |
||
294 |
function maintenance_nag() { |
|
295 |
global $upgrading; |
|
296 |
if ( ! isset( $upgrading ) ) |
|
297 |
return false; |
|
298 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
299 |
if ( current_user_can('update_core') ) |
136 | 300 |
$msg = sprintf( __('An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.'), 'update-core.php' ); |
301 |
else |
|
302 |
$msg = __('An automated WordPress update has failed to complete! Please notify the site administrator.'); |
|
303 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
304 |
echo "<div class='update-nag'>$msg</div>"; |
136 | 305 |
} |
306 |
add_action( 'admin_notices', 'maintenance_nag' ); |