author | Anthony Ly <anthonyly.com@gmail.com> |
Tue, 12 Mar 2013 18:21:39 +0100 | |
changeset 206 | 919b4ddb13fa |
parent 204 | 09a1c134465b |
permissions | -rw-r--r-- |
136 | 1 |
<?php |
2 |
/** |
|
3 |
* A File upgrader class for WordPress. |
|
4 |
* |
|
5 |
* This set of classes are designed to be used to upgrade/install a local set of files on the filesystem via the Filesystem Abstraction classes. |
|
6 |
* |
|
7 |
* @link http://trac.wordpress.org/ticket/7875 consolidate plugin/theme/core upgrade/install functions |
|
8 |
* |
|
9 |
* @package WordPress |
|
10 |
* @subpackage Upgrader |
|
11 |
* @since 2.8.0 |
|
12 |
*/ |
|
13 |
||
14 |
/** |
|
15 |
* WordPress Upgrader class for Upgrading/Installing a local set of files via the Filesystem Abstraction classes from a Zip file. |
|
16 |
* |
|
17 |
* @TODO More Detailed docs, for methods as well. |
|
18 |
* |
|
19 |
* @package WordPress |
|
20 |
* @subpackage Upgrader |
|
21 |
* @since 2.8.0 |
|
22 |
*/ |
|
23 |
class WP_Upgrader { |
|
24 |
var $strings = array(); |
|
25 |
var $skin = null; |
|
26 |
var $result = array(); |
|
27 |
||
28 |
function __construct($skin = null) { |
|
29 |
if ( null == $skin ) |
|
30 |
$this->skin = new WP_Upgrader_Skin(); |
|
31 |
else |
|
32 |
$this->skin = $skin; |
|
33 |
} |
|
34 |
||
35 |
function init() { |
|
36 |
$this->skin->set_upgrader($this); |
|
37 |
$this->generic_strings(); |
|
38 |
} |
|
39 |
||
40 |
function generic_strings() { |
|
41 |
$this->strings['bad_request'] = __('Invalid Data provided.'); |
|
42 |
$this->strings['fs_unavailable'] = __('Could not access filesystem.'); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
43 |
$this->strings['fs_error'] = __('Filesystem error.'); |
136 | 44 |
$this->strings['fs_no_root_dir'] = __('Unable to locate WordPress Root directory.'); |
45 |
$this->strings['fs_no_content_dir'] = __('Unable to locate WordPress Content directory (wp-content).'); |
|
46 |
$this->strings['fs_no_plugins_dir'] = __('Unable to locate WordPress Plugin directory.'); |
|
47 |
$this->strings['fs_no_themes_dir'] = __('Unable to locate WordPress Theme directory.'); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
48 |
/* translators: %s: directory name */ |
136 | 49 |
$this->strings['fs_no_folder'] = __('Unable to locate needed folder (%s).'); |
50 |
||
51 |
$this->strings['download_failed'] = __('Download failed.'); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
52 |
$this->strings['installing_package'] = __('Installing the latest version…'); |
136 | 53 |
$this->strings['folder_exists'] = __('Destination folder already exists.'); |
54 |
$this->strings['mkdir_failed'] = __('Could not create directory.'); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
55 |
$this->strings['incompatible_archive'] = __('The package could not be installed.'); |
136 | 56 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
57 |
$this->strings['maintenance_start'] = __('Enabling Maintenance mode…'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
58 |
$this->strings['maintenance_end'] = __('Disabling Maintenance mode…'); |
136 | 59 |
} |
60 |
||
61 |
function fs_connect( $directories = array() ) { |
|
62 |
global $wp_filesystem; |
|
63 |
||
64 |
if ( false === ($credentials = $this->skin->request_filesystem_credentials()) ) |
|
65 |
return false; |
|
66 |
||
67 |
if ( ! WP_Filesystem($credentials) ) { |
|
68 |
$error = true; |
|
69 |
if ( is_object($wp_filesystem) && $wp_filesystem->errors->get_error_code() ) |
|
70 |
$error = $wp_filesystem->errors; |
|
71 |
$this->skin->request_filesystem_credentials($error); //Failed to connect, Error and request again |
|
72 |
return false; |
|
73 |
} |
|
74 |
||
75 |
if ( ! is_object($wp_filesystem) ) |
|
76 |
return new WP_Error('fs_unavailable', $this->strings['fs_unavailable'] ); |
|
77 |
||
78 |
if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) |
|
79 |
return new WP_Error('fs_error', $this->strings['fs_error'], $wp_filesystem->errors); |
|
80 |
||
81 |
foreach ( (array)$directories as $dir ) { |
|
82 |
switch ( $dir ) { |
|
83 |
case ABSPATH: |
|
84 |
if ( ! $wp_filesystem->abspath() ) |
|
85 |
return new WP_Error('fs_no_root_dir', $this->strings['fs_no_root_dir']); |
|
86 |
break; |
|
87 |
case WP_CONTENT_DIR: |
|
88 |
if ( ! $wp_filesystem->wp_content_dir() ) |
|
89 |
return new WP_Error('fs_no_content_dir', $this->strings['fs_no_content_dir']); |
|
90 |
break; |
|
91 |
case WP_PLUGIN_DIR: |
|
92 |
if ( ! $wp_filesystem->wp_plugins_dir() ) |
|
93 |
return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']); |
|
94 |
break; |
|
95 |
case WP_CONTENT_DIR . '/themes': |
|
96 |
if ( ! $wp_filesystem->find_folder(WP_CONTENT_DIR . '/themes') ) |
|
97 |
return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']); |
|
98 |
break; |
|
99 |
default: |
|
100 |
if ( ! $wp_filesystem->find_folder($dir) ) |
|
101 |
return new WP_Error('fs_no_folder', sprintf($this->strings['fs_no_folder'], $dir)); |
|
102 |
break; |
|
103 |
} |
|
104 |
} |
|
105 |
return true; |
|
106 |
} //end fs_connect(); |
|
107 |
||
108 |
function download_package($package) { |
|
109 |
||
110 |
if ( ! preg_match('!^(http|https|ftp)://!i', $package) && file_exists($package) ) //Local file or remote? |
|
111 |
return $package; //must be a local file.. |
|
112 |
||
113 |
if ( empty($package) ) |
|
114 |
return new WP_Error('no_package', $this->strings['no_package']); |
|
115 |
||
116 |
$this->skin->feedback('downloading_package', $package); |
|
117 |
||
118 |
$download_file = download_url($package); |
|
119 |
||
120 |
if ( is_wp_error($download_file) ) |
|
121 |
return new WP_Error('download_failed', $this->strings['download_failed'], $download_file->get_error_message()); |
|
122 |
||
123 |
return $download_file; |
|
124 |
} |
|
125 |
||
126 |
function unpack_package($package, $delete_package = true) { |
|
127 |
global $wp_filesystem; |
|
128 |
||
129 |
$this->skin->feedback('unpack_package'); |
|
130 |
||
131 |
$upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/'; |
|
132 |
||
133 |
//Clean up contents of upgrade directory beforehand. |
|
134 |
$upgrade_files = $wp_filesystem->dirlist($upgrade_folder); |
|
135 |
if ( !empty($upgrade_files) ) { |
|
136 |
foreach ( $upgrade_files as $file ) |
|
137 |
$wp_filesystem->delete($upgrade_folder . $file['name'], true); |
|
138 |
} |
|
139 |
||
140 |
//We need a working directory |
|
141 |
$working_dir = $upgrade_folder . basename($package, '.zip'); |
|
142 |
||
143 |
// Clean up working directory |
|
144 |
if ( $wp_filesystem->is_dir($working_dir) ) |
|
145 |
$wp_filesystem->delete($working_dir, true); |
|
146 |
||
147 |
// Unzip package to working directory |
|
148 |
$result = unzip_file($package, $working_dir); //TODO optimizations, Copy when Move/Rename would suffice? |
|
149 |
||
150 |
// Once extracted, delete the package if required. |
|
151 |
if ( $delete_package ) |
|
152 |
unlink($package); |
|
153 |
||
154 |
if ( is_wp_error($result) ) { |
|
155 |
$wp_filesystem->delete($working_dir, true); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
156 |
if ( 'incompatible_archive' == $result->get_error_code() ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
157 |
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data() ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
158 |
} |
136 | 159 |
return $result; |
160 |
} |
|
161 |
||
162 |
return $working_dir; |
|
163 |
} |
|
164 |
||
165 |
function install_package($args = array()) { |
|
166 |
global $wp_filesystem; |
|
167 |
$defaults = array( 'source' => '', 'destination' => '', //Please always pass these |
|
168 |
'clear_destination' => false, 'clear_working' => false, |
|
169 |
'hook_extra' => array()); |
|
170 |
||
171 |
$args = wp_parse_args($args, $defaults); |
|
172 |
extract($args); |
|
173 |
||
174 |
@set_time_limit( 300 ); |
|
175 |
||
176 |
if ( empty($source) || empty($destination) ) |
|
177 |
return new WP_Error('bad_request', $this->strings['bad_request']); |
|
178 |
||
179 |
$this->skin->feedback('installing_package'); |
|
180 |
||
181 |
$res = apply_filters('upgrader_pre_install', true, $hook_extra); |
|
182 |
if ( is_wp_error($res) ) |
|
183 |
return $res; |
|
184 |
||
185 |
//Retain the Original source and destinations |
|
186 |
$remote_source = $source; |
|
187 |
$local_destination = $destination; |
|
188 |
||
189 |
$source_files = array_keys( $wp_filesystem->dirlist($remote_source) ); |
|
190 |
$remote_destination = $wp_filesystem->find_folder($local_destination); |
|
191 |
||
192 |
//Locate which directory to copy to the new folder, This is based on the actual folder holding the files. |
|
193 |
if ( 1 == count($source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents. |
|
194 |
$source = trailingslashit($source) . trailingslashit($source_files[0]); |
|
195 |
elseif ( count($source_files) == 0 ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
196 |
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __( 'The plugin contains no files.' ) ); //There are no files? |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
197 |
else //Its only a single file, The upgrader will use the foldername of this file as the destination folder. foldername is based on zip filename. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
198 |
$source = trailingslashit($source); |
136 | 199 |
|
200 |
//Hook ability to change the source file location.. |
|
201 |
$source = apply_filters('upgrader_source_selection', $source, $remote_source, $this); |
|
202 |
if ( is_wp_error($source) ) |
|
203 |
return $source; |
|
204 |
||
205 |
//Has the source location changed? If so, we need a new source_files list. |
|
206 |
if ( $source !== $remote_source ) |
|
207 |
$source_files = array_keys( $wp_filesystem->dirlist($source) ); |
|
208 |
||
209 |
//Protection against deleting files in any important base directories. |
|
210 |
if ( in_array( $destination, array(ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes') ) ) { |
|
211 |
$remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source)); |
|
212 |
$destination = trailingslashit($destination) . trailingslashit(basename($source)); |
|
213 |
} |
|
214 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
215 |
if ( $clear_destination ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
216 |
//We're going to clear the destination if there's something there |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
217 |
$this->skin->feedback('remove_old'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
218 |
$removed = true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
219 |
if ( $wp_filesystem->exists($remote_destination) ) |
136 | 220 |
$removed = $wp_filesystem->delete($remote_destination, true); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
221 |
$removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra); |
136 | 222 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
223 |
if ( is_wp_error($removed) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
224 |
return $removed; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
225 |
else if ( ! $removed ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
226 |
return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
227 |
} elseif ( $wp_filesystem->exists($remote_destination) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
228 |
//If we're not clearing the destination folder and something exists there already, Bail. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
229 |
//But first check to see if there are actually any files in the folder. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
230 |
$_files = $wp_filesystem->dirlist($remote_destination); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
231 |
if ( ! empty($_files) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
232 |
$wp_filesystem->delete($remote_source, true); //Clear out the source files. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
233 |
return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination ); |
136 | 234 |
} |
235 |
} |
|
236 |
||
237 |
//Create destination if needed |
|
238 |
if ( !$wp_filesystem->exists($remote_destination) ) |
|
239 |
if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) ) |
|
240 |
return new WP_Error('mkdir_failed', $this->strings['mkdir_failed'], $remote_destination); |
|
241 |
||
242 |
// Copy new version of item into place. |
|
243 |
$result = copy_dir($source, $remote_destination); |
|
244 |
if ( is_wp_error($result) ) { |
|
245 |
if ( $clear_working ) |
|
246 |
$wp_filesystem->delete($remote_source, true); |
|
247 |
return $result; |
|
248 |
} |
|
249 |
||
250 |
//Clear the Working folder? |
|
251 |
if ( $clear_working ) |
|
252 |
$wp_filesystem->delete($remote_source, true); |
|
253 |
||
254 |
$destination_name = basename( str_replace($local_destination, '', $destination) ); |
|
255 |
if ( '.' == $destination_name ) |
|
256 |
$destination_name = ''; |
|
257 |
||
258 |
$this->result = compact('local_source', 'source', 'source_name', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination', 'delete_source_dir'); |
|
259 |
||
260 |
$res = apply_filters('upgrader_post_install', true, $hook_extra, $this->result); |
|
261 |
if ( is_wp_error($res) ) { |
|
262 |
$this->result = $res; |
|
263 |
return $res; |
|
264 |
} |
|
265 |
||
266 |
//Bombard the calling function will all the info which we've just used. |
|
267 |
return $this->result; |
|
268 |
} |
|
269 |
||
270 |
function run($options) { |
|
271 |
||
272 |
$defaults = array( 'package' => '', //Please always pass this. |
|
273 |
'destination' => '', //And this |
|
274 |
'clear_destination' => false, |
|
275 |
'clear_working' => true, |
|
276 |
'is_multi' => false, |
|
277 |
'hook_extra' => array() //Pass any extra $hook_extra args here, this will be passed to any hooked filters. |
|
278 |
); |
|
279 |
||
280 |
$options = wp_parse_args($options, $defaults); |
|
281 |
extract($options); |
|
282 |
||
283 |
//Connect to the Filesystem first. |
|
284 |
$res = $this->fs_connect( array(WP_CONTENT_DIR, $destination) ); |
|
285 |
if ( ! $res ) //Mainly for non-connected filesystem. |
|
286 |
return false; |
|
287 |
||
288 |
if ( is_wp_error($res) ) { |
|
289 |
$this->skin->error($res); |
|
290 |
return $res; |
|
291 |
} |
|
292 |
||
293 |
if ( !$is_multi ) // call $this->header separately if running multiple times |
|
294 |
$this->skin->header(); |
|
295 |
||
296 |
$this->skin->before(); |
|
297 |
||
298 |
//Download the package (Note, This just returns the filename of the file if the package is a local file) |
|
299 |
$download = $this->download_package( $package ); |
|
300 |
if ( is_wp_error($download) ) { |
|
301 |
$this->skin->error($download); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
302 |
$this->skin->after(); |
136 | 303 |
return $download; |
304 |
} |
|
305 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
306 |
$delete_package = ($download != $package); // Do not delete a "local" file |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
307 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
308 |
//Unzips the file into a temporary directory |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
309 |
$working_dir = $this->unpack_package( $download, $delete_package ); |
136 | 310 |
if ( is_wp_error($working_dir) ) { |
311 |
$this->skin->error($working_dir); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
312 |
$this->skin->after(); |
136 | 313 |
return $working_dir; |
314 |
} |
|
315 |
||
316 |
//With the given options, this installs it to the destination directory. |
|
317 |
$result = $this->install_package( array( |
|
318 |
'source' => $working_dir, |
|
319 |
'destination' => $destination, |
|
320 |
'clear_destination' => $clear_destination, |
|
321 |
'clear_working' => $clear_working, |
|
322 |
'hook_extra' => $hook_extra |
|
323 |
) ); |
|
324 |
$this->skin->set_result($result); |
|
325 |
if ( is_wp_error($result) ) { |
|
326 |
$this->skin->error($result); |
|
327 |
$this->skin->feedback('process_failed'); |
|
328 |
} else { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
329 |
//Install Succeeded |
136 | 330 |
$this->skin->feedback('process_success'); |
331 |
} |
|
332 |
$this->skin->after(); |
|
333 |
||
334 |
if ( !$is_multi ) |
|
335 |
$this->skin->footer(); |
|
336 |
||
337 |
return $result; |
|
338 |
} |
|
339 |
||
340 |
function maintenance_mode($enable = false) { |
|
341 |
global $wp_filesystem; |
|
342 |
$file = $wp_filesystem->abspath() . '.maintenance'; |
|
343 |
if ( $enable ) { |
|
344 |
$this->skin->feedback('maintenance_start'); |
|
345 |
// Create maintenance file to signal that we are upgrading |
|
346 |
$maintenance_string = '<?php $upgrading = ' . time() . '; ?>'; |
|
347 |
$wp_filesystem->delete($file); |
|
348 |
$wp_filesystem->put_contents($file, $maintenance_string, FS_CHMOD_FILE); |
|
349 |
} else if ( !$enable && $wp_filesystem->exists($file) ) { |
|
350 |
$this->skin->feedback('maintenance_end'); |
|
351 |
$wp_filesystem->delete($file); |
|
352 |
} |
|
353 |
} |
|
354 |
||
355 |
} |
|
356 |
||
357 |
/** |
|
358 |
* Plugin Upgrader class for WordPress Plugins, It is designed to upgrade/install plugins from a local zip, remote zip URL, or uploaded zip file. |
|
359 |
* |
|
360 |
* @TODO More Detailed docs, for methods as well. |
|
361 |
* |
|
362 |
* @package WordPress |
|
363 |
* @subpackage Upgrader |
|
364 |
* @since 2.8.0 |
|
365 |
*/ |
|
366 |
class Plugin_Upgrader extends WP_Upgrader { |
|
367 |
||
368 |
var $result; |
|
369 |
var $bulk = false; |
|
370 |
var $show_before = ''; |
|
371 |
||
372 |
function upgrade_strings() { |
|
373 |
$this->strings['up_to_date'] = __('The plugin is at the latest version.'); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
374 |
$this->strings['no_package'] = __('Update package not available.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
375 |
$this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
376 |
$this->strings['unpack_package'] = __('Unpacking the update…'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
377 |
$this->strings['remove_old'] = __('Removing the old version of the plugin…'); |
136 | 378 |
$this->strings['remove_old_failed'] = __('Could not remove the old plugin.'); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
379 |
$this->strings['process_failed'] = __('Plugin update failed.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
380 |
$this->strings['process_success'] = __('Plugin updated successfully.'); |
136 | 381 |
} |
382 |
||
383 |
function install_strings() { |
|
384 |
$this->strings['no_package'] = __('Install package not available.'); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
385 |
$this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>…'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
386 |
$this->strings['unpack_package'] = __('Unpacking the package…'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
387 |
$this->strings['installing_package'] = __('Installing the plugin…'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
388 |
$this->strings['process_failed'] = __('Plugin install failed.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
389 |
$this->strings['process_success'] = __('Plugin installed successfully.'); |
136 | 390 |
} |
391 |
||
392 |
function install($package) { |
|
393 |
||
394 |
$this->init(); |
|
395 |
$this->install_strings(); |
|
396 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
397 |
add_filter('upgrader_source_selection', array(&$this, 'check_package') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
398 |
|
136 | 399 |
$this->run(array( |
400 |
'package' => $package, |
|
401 |
'destination' => WP_PLUGIN_DIR, |
|
402 |
'clear_destination' => false, //Do not overwrite files. |
|
403 |
'clear_working' => true, |
|
404 |
'hook_extra' => array() |
|
405 |
)); |
|
406 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
407 |
remove_filter('upgrader_source_selection', array(&$this, 'check_package') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
408 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
409 |
if ( ! $this->result || is_wp_error($this->result) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
410 |
return $this->result; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
411 |
|
136 | 412 |
// Force refresh of plugin update information |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
413 |
delete_site_transient('update_plugins'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
414 |
wp_cache_delete( 'plugins', 'plugins' ); |
136 | 415 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
416 |
return true; |
136 | 417 |
} |
418 |
||
419 |
function upgrade($plugin) { |
|
420 |
||
421 |
$this->init(); |
|
422 |
$this->upgrade_strings(); |
|
423 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
424 |
$current = get_site_transient( 'update_plugins' ); |
136 | 425 |
if ( !isset( $current->response[ $plugin ] ) ) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
426 |
$this->skin->before(); |
136 | 427 |
$this->skin->set_result(false); |
428 |
$this->skin->error('up_to_date'); |
|
429 |
$this->skin->after(); |
|
430 |
return false; |
|
431 |
} |
|
432 |
||
433 |
// Get the URL to the zip file |
|
434 |
$r = $current->response[ $plugin ]; |
|
435 |
||
436 |
add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2); |
|
437 |
add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
438 |
//'source_selection' => array(&$this, 'source_selection'), //there's a trac ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins. |
136 | 439 |
|
440 |
$this->run(array( |
|
441 |
'package' => $r->package, |
|
442 |
'destination' => WP_PLUGIN_DIR, |
|
443 |
'clear_destination' => true, |
|
444 |
'clear_working' => true, |
|
445 |
'hook_extra' => array( |
|
446 |
'plugin' => $plugin |
|
447 |
) |
|
448 |
)); |
|
449 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
450 |
// Cleanup our hooks, in case something else does a upgrade on this connection. |
136 | 451 |
remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade')); |
452 |
remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin')); |
|
453 |
||
454 |
if ( ! $this->result || is_wp_error($this->result) ) |
|
455 |
return $this->result; |
|
456 |
||
457 |
// Force refresh of plugin update information |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
458 |
delete_site_transient('update_plugins'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
459 |
wp_cache_delete( 'plugins', 'plugins' ); |
136 | 460 |
} |
461 |
||
462 |
function bulk_upgrade($plugins) { |
|
463 |
||
464 |
$this->init(); |
|
465 |
$this->bulk = true; |
|
466 |
$this->upgrade_strings(); |
|
467 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
468 |
$current = get_site_transient( 'update_plugins' ); |
136 | 469 |
|
470 |
add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4); |
|
471 |
||
472 |
$this->skin->header(); |
|
473 |
||
474 |
// Connect to the Filesystem first. |
|
475 |
$res = $this->fs_connect( array(WP_CONTENT_DIR, WP_PLUGIN_DIR) ); |
|
476 |
if ( ! $res ) { |
|
477 |
$this->skin->footer(); |
|
478 |
return false; |
|
479 |
} |
|
480 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
481 |
$this->skin->bulk_header(); |
136 | 482 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
483 |
// Only start maintenance mode if running in Multisite OR the plugin is in use |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
484 |
$maintenance = is_multisite(); // @TODO: This should only kick in for individual sites if at all possible. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
485 |
foreach ( $plugins as $plugin ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
486 |
$maintenance = $maintenance || (is_plugin_active($plugin) && isset($current->response[ $plugin ]) ); // Only activate Maintenance mode if a plugin is active AND has an update available |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
487 |
if ( $maintenance ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
488 |
$this->maintenance_mode(true); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
489 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
490 |
$results = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
491 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
492 |
$this->update_count = count($plugins); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
493 |
$this->update_current = 0; |
136 | 494 |
foreach ( $plugins as $plugin ) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
495 |
$this->update_current++; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
496 |
$this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true); |
136 | 497 |
|
498 |
if ( !isset( $current->response[ $plugin ] ) ) { |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
499 |
$this->skin->set_result(true); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
500 |
$this->skin->before(); |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
501 |
$this->skin->feedback('up_to_date'); |
136 | 502 |
$this->skin->after(); |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
503 |
$results[$plugin] = true; |
136 | 504 |
continue; |
505 |
} |
|
506 |
||
507 |
// Get the URL to the zip file |
|
508 |
$r = $current->response[ $plugin ]; |
|
509 |
||
510 |
$this->skin->plugin_active = is_plugin_active($plugin); |
|
511 |
||
512 |
$result = $this->run(array( |
|
513 |
'package' => $r->package, |
|
514 |
'destination' => WP_PLUGIN_DIR, |
|
515 |
'clear_destination' => true, |
|
516 |
'clear_working' => true, |
|
517 |
'is_multi' => true, |
|
518 |
'hook_extra' => array( |
|
519 |
'plugin' => $plugin |
|
520 |
) |
|
521 |
)); |
|
522 |
||
523 |
$results[$plugin] = $this->result; |
|
524 |
||
525 |
// Prevent credentials auth screen from displaying multiple times |
|
526 |
if ( false === $result ) |
|
527 |
break; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
528 |
} //end foreach $plugins |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
529 |
|
136 | 530 |
$this->maintenance_mode(false); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
531 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
532 |
$this->skin->bulk_footer(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
533 |
|
136 | 534 |
$this->skin->footer(); |
535 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
536 |
// Cleanup our hooks, in case something else does a upgrade on this connection. |
136 | 537 |
remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin')); |
538 |
||
539 |
// Force refresh of plugin update information |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
540 |
delete_site_transient('update_plugins'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
541 |
wp_cache_delete( 'plugins', 'plugins' ); |
136 | 542 |
|
543 |
return $results; |
|
544 |
} |
|
545 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
546 |
function check_package($source) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
547 |
global $wp_filesystem; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
548 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
549 |
if ( is_wp_error($source) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
550 |
return $source; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
551 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
552 |
$working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
553 |
if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, lets not prevent installation. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
554 |
return $source; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
555 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
556 |
// Check the folder contains at least 1 valid plugin. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
557 |
$plugins_found = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
558 |
foreach ( glob( $working_directory . '*.php' ) as $file ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
559 |
$info = get_plugin_data($file, false, false); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
560 |
if ( !empty( $info['Name'] ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
561 |
$plugins_found = true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
562 |
break; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
563 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
564 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
565 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
566 |
if ( ! $plugins_found ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
567 |
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('No valid plugins were found.') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
568 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
569 |
return $source; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
570 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
571 |
|
136 | 572 |
//return plugin info. |
573 |
function plugin_info() { |
|
574 |
if ( ! is_array($this->result) ) |
|
575 |
return false; |
|
576 |
if ( empty($this->result['destination_name']) ) |
|
577 |
return false; |
|
578 |
||
579 |
$plugin = get_plugins('/' . $this->result['destination_name']); //Ensure to pass with leading slash |
|
580 |
if ( empty($plugin) ) |
|
581 |
return false; |
|
582 |
||
583 |
$pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list |
|
584 |
||
585 |
return $this->result['destination_name'] . '/' . $pluginfiles[0]; |
|
586 |
} |
|
587 |
||
588 |
//Hooked to pre_install |
|
589 |
function deactivate_plugin_before_upgrade($return, $plugin) { |
|
590 |
||
591 |
if ( is_wp_error($return) ) //Bypass. |
|
592 |
return $return; |
|
593 |
||
594 |
$plugin = isset($plugin['plugin']) ? $plugin['plugin'] : ''; |
|
595 |
if ( empty($plugin) ) |
|
596 |
return new WP_Error('bad_request', $this->strings['bad_request']); |
|
597 |
||
598 |
if ( is_plugin_active($plugin) ) { |
|
599 |
//Deactivate the plugin silently, Prevent deactivation hooks from running. |
|
600 |
deactivate_plugins($plugin, true); |
|
601 |
} |
|
602 |
} |
|
603 |
||
604 |
//Hooked to upgrade_clear_destination |
|
605 |
function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) { |
|
606 |
global $wp_filesystem; |
|
607 |
||
608 |
if ( is_wp_error($removed) ) |
|
609 |
return $removed; //Pass errors through. |
|
610 |
||
611 |
$plugin = isset($plugin['plugin']) ? $plugin['plugin'] : ''; |
|
612 |
if ( empty($plugin) ) |
|
613 |
return new WP_Error('bad_request', $this->strings['bad_request']); |
|
614 |
||
615 |
$plugins_dir = $wp_filesystem->wp_plugins_dir(); |
|
616 |
$this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) ); |
|
617 |
||
618 |
if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If its already vanished. |
|
619 |
return $removed; |
|
620 |
||
621 |
// If plugin is in its own directory, recursively delete the directory. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
622 |
if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory separator AND that its not the root plugin folder |
136 | 623 |
$deleted = $wp_filesystem->delete($this_plugin_dir, true); |
624 |
else |
|
625 |
$deleted = $wp_filesystem->delete($plugins_dir . $plugin); |
|
626 |
||
627 |
if ( ! $deleted ) |
|
628 |
return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']); |
|
629 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
630 |
return true; |
136 | 631 |
} |
632 |
} |
|
633 |
||
634 |
/** |
|
635 |
* Theme Upgrader class for WordPress Themes, It is designed to upgrade/install themes from a local zip, remote zip URL, or uploaded zip file. |
|
636 |
* |
|
637 |
* @TODO More Detailed docs, for methods as well. |
|
638 |
* |
|
639 |
* @package WordPress |
|
640 |
* @subpackage Upgrader |
|
641 |
* @since 2.8.0 |
|
642 |
*/ |
|
643 |
class Theme_Upgrader extends WP_Upgrader { |
|
644 |
||
645 |
var $result; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
646 |
var $bulk = false; |
136 | 647 |
|
648 |
function upgrade_strings() { |
|
649 |
$this->strings['up_to_date'] = __('The theme is at the latest version.'); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
650 |
$this->strings['no_package'] = __('Update package not available.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
651 |
$this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
652 |
$this->strings['unpack_package'] = __('Unpacking the update…'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
653 |
$this->strings['remove_old'] = __('Removing the old version of the theme…'); |
136 | 654 |
$this->strings['remove_old_failed'] = __('Could not remove the old theme.'); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
655 |
$this->strings['process_failed'] = __('Theme update failed.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
656 |
$this->strings['process_success'] = __('Theme updated successfully.'); |
136 | 657 |
} |
658 |
||
659 |
function install_strings() { |
|
660 |
$this->strings['no_package'] = __('Install package not available.'); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
661 |
$this->strings['downloading_package'] = __('Downloading install package from <span class="code">%s</span>…'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
662 |
$this->strings['unpack_package'] = __('Unpacking the package…'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
663 |
$this->strings['installing_package'] = __('Installing the theme…'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
664 |
$this->strings['process_failed'] = __('Theme install failed.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
665 |
$this->strings['process_success'] = __('Theme installed successfully.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
666 |
/* translators: 1: theme name, 2: version */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
667 |
$this->strings['process_success_specific'] = __('Successfully installed the theme <strong>%1$s %2$s</strong>.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
668 |
$this->strings['parent_theme_search'] = __('This theme requires a parent theme. Checking if it is installed…'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
669 |
/* translators: 1: theme name, 2: version */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
670 |
$this->strings['parent_theme_prepare_install'] = __('Preparing to install <strong>%1$s %2$s</strong>…'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
671 |
/* translators: 1: theme name, 2: version */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
672 |
$this->strings['parent_theme_currently_installed'] = __('The parent theme, <strong>%1$s %2$s</strong>, is currently installed.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
673 |
/* translators: 1: theme name, 2: version */ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
674 |
$this->strings['parent_theme_install_success'] = __('Successfully installed the parent theme, <strong>%1$s %2$s</strong>.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
675 |
$this->strings['parent_theme_not_found'] = __('<strong>The parent theme could not be found.</strong> You will need to install the parent theme, <strong>%s</strong>, before you can use this child theme.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
676 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
677 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
678 |
function check_parent_theme_filter($install_result, $hook_extra, $child_result) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
679 |
// Check to see if we need to install a parent theme |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
680 |
$theme_info = $this->theme_info(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
681 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
682 |
if ( ! $theme_info->parent() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
683 |
return $install_result; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
684 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
685 |
$this->skin->feedback( 'parent_theme_search' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
686 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
687 |
if ( ! $theme_info->parent()->errors() ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
688 |
$this->skin->feedback( 'parent_theme_currently_installed', $theme_info->parent()->display('Name'), $theme_info->parent()->display('Version') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
689 |
// We already have the theme, fall through. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
690 |
return $install_result; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
691 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
692 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
693 |
// We don't have the parent theme, lets install it |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
694 |
$api = themes_api('theme_information', array('slug' => $theme_info->get('Template'), 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
695 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
696 |
if ( ! $api || is_wp_error($api) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
697 |
$this->skin->feedback( 'parent_theme_not_found', $theme_info->get('Template') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
698 |
// Don't show activate or preview actions after install |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
699 |
add_filter('install_theme_complete_actions', array(&$this, 'hide_activate_preview_actions') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
700 |
return $install_result; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
701 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
702 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
703 |
// Backup required data we're going to override: |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
704 |
$child_api = $this->skin->api; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
705 |
$child_success_message = $this->strings['process_success']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
706 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
707 |
// Override them |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
708 |
$this->skin->api = $api; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
709 |
$this->strings['process_success_specific'] = $this->strings['parent_theme_install_success'];//, $api->name, $api->version); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
710 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
711 |
$this->skin->feedback('parent_theme_prepare_install', $api->name, $api->version); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
712 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
713 |
add_filter('install_theme_complete_actions', '__return_false', 999); // Don't show any actions after installing the theme. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
714 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
715 |
// Install the parent theme |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
716 |
$parent_result = $this->run( array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
717 |
'package' => $api->download_link, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
718 |
'destination' => WP_CONTENT_DIR . '/themes', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
719 |
'clear_destination' => false, //Do not overwrite files. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
720 |
'clear_working' => true |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
721 |
) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
722 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
723 |
if ( is_wp_error($parent_result) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
724 |
add_filter('install_theme_complete_actions', array(&$this, 'hide_activate_preview_actions') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
725 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
726 |
// Start cleaning up after the parents installation |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
727 |
remove_filter('install_theme_complete_actions', '__return_false', 999); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
728 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
729 |
// Reset child's result and data |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
730 |
$this->result = $child_result; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
731 |
$this->skin->api = $child_api; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
732 |
$this->strings['process_success'] = $child_success_message; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
733 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
734 |
return $install_result; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
735 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
736 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
737 |
function hide_activate_preview_actions($actions) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
738 |
unset($actions['activate'], $actions['preview']); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
739 |
return $actions; |
136 | 740 |
} |
741 |
||
742 |
function install($package) { |
|
743 |
||
744 |
$this->init(); |
|
745 |
$this->install_strings(); |
|
746 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
747 |
add_filter('upgrader_source_selection', array(&$this, 'check_package') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
748 |
add_filter('upgrader_post_install', array(&$this, 'check_parent_theme_filter'), 10, 3); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
749 |
|
136 | 750 |
$options = array( |
751 |
'package' => $package, |
|
752 |
'destination' => WP_CONTENT_DIR . '/themes', |
|
753 |
'clear_destination' => false, //Do not overwrite files. |
|
754 |
'clear_working' => true |
|
755 |
); |
|
756 |
||
757 |
$this->run($options); |
|
758 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
759 |
remove_filter('upgrader_source_selection', array(&$this, 'check_package') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
760 |
remove_filter('upgrader_post_install', array(&$this, 'check_parent_theme_filter'), 10, 3); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
761 |
|
136 | 762 |
if ( ! $this->result || is_wp_error($this->result) ) |
763 |
return $this->result; |
|
764 |
||
765 |
// Force refresh of theme update information |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
766 |
wp_clean_themes_cache(); |
136 | 767 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
768 |
return true; |
136 | 769 |
} |
770 |
||
771 |
function upgrade($theme) { |
|
772 |
||
773 |
$this->init(); |
|
774 |
$this->upgrade_strings(); |
|
775 |
||
776 |
// Is an update available? |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
777 |
$current = get_site_transient( 'update_themes' ); |
136 | 778 |
if ( !isset( $current->response[ $theme ] ) ) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
779 |
$this->skin->before(); |
136 | 780 |
$this->skin->set_result(false); |
781 |
$this->skin->error('up_to_date'); |
|
782 |
$this->skin->after(); |
|
783 |
return false; |
|
784 |
} |
|
785 |
||
786 |
$r = $current->response[ $theme ]; |
|
787 |
||
788 |
add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2); |
|
789 |
add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2); |
|
790 |
add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4); |
|
791 |
||
792 |
$options = array( |
|
793 |
'package' => $r['package'], |
|
794 |
'destination' => WP_CONTENT_DIR . '/themes', |
|
795 |
'clear_destination' => true, |
|
796 |
'clear_working' => true, |
|
797 |
'hook_extra' => array( |
|
798 |
'theme' => $theme |
|
799 |
) |
|
800 |
); |
|
801 |
||
802 |
$this->run($options); |
|
803 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
804 |
remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
805 |
remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
806 |
remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
807 |
|
136 | 808 |
if ( ! $this->result || is_wp_error($this->result) ) |
809 |
return $this->result; |
|
810 |
||
811 |
// Force refresh of theme update information |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
812 |
wp_clean_themes_cache(); |
136 | 813 |
|
814 |
return true; |
|
815 |
} |
|
816 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
817 |
function bulk_upgrade($themes) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
818 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
819 |
$this->init(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
820 |
$this->bulk = true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
821 |
$this->upgrade_strings(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
822 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
823 |
$current = get_site_transient( 'update_themes' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
824 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
825 |
add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
826 |
add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
827 |
add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
828 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
829 |
$this->skin->header(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
830 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
831 |
// Connect to the Filesystem first. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
832 |
$res = $this->fs_connect( array(WP_CONTENT_DIR) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
833 |
if ( ! $res ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
834 |
$this->skin->footer(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
835 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
836 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
837 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
838 |
$this->skin->bulk_header(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
839 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
840 |
// Only start maintenance mode if running in Multisite OR the theme is in use |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
841 |
$maintenance = is_multisite(); // @TODO: This should only kick in for individual sites if at all possible. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
842 |
foreach ( $themes as $theme ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
843 |
$maintenance = $maintenance || $theme == get_stylesheet() || $theme == get_template(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
844 |
if ( $maintenance ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
845 |
$this->maintenance_mode(true); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
846 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
847 |
$results = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
848 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
849 |
$this->update_count = count($themes); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
850 |
$this->update_current = 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
851 |
foreach ( $themes as $theme ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
852 |
$this->update_current++; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
853 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
854 |
$this->skin->theme_info = $this->theme_info($theme); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
855 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
856 |
if ( !isset( $current->response[ $theme ] ) ) { |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
857 |
$this->skin->set_result(true); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
858 |
$this->skin->before(); |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
859 |
$this->skin->feedback('up_to_date'); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
860 |
$this->skin->after(); |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
861 |
$results[$theme] = true; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
862 |
continue; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
863 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
864 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
865 |
// Get the URL to the zip file |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
866 |
$r = $current->response[ $theme ]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
867 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
868 |
$options = array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
869 |
'package' => $r['package'], |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
870 |
'destination' => WP_CONTENT_DIR . '/themes', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
871 |
'clear_destination' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
872 |
'clear_working' => true, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
873 |
'hook_extra' => array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
874 |
'theme' => $theme |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
875 |
) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
876 |
); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
877 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
878 |
$result = $this->run($options); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
879 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
880 |
$results[$theme] = $this->result; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
881 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
882 |
// Prevent credentials auth screen from displaying multiple times |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
883 |
if ( false === $result ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
884 |
break; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
885 |
} //end foreach $plugins |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
886 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
887 |
$this->maintenance_mode(false); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
888 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
889 |
$this->skin->bulk_footer(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
890 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
891 |
$this->skin->footer(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
892 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
893 |
// Cleanup our hooks, in case something else does a upgrade on this connection. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
894 |
remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
895 |
remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
896 |
remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
897 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
898 |
// Force refresh of theme update information |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
899 |
wp_clean_themes_cache(); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
900 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
901 |
return $results; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
902 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
903 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
904 |
function check_package($source) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
905 |
global $wp_filesystem; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
906 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
907 |
if ( is_wp_error($source) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
908 |
return $source; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
909 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
910 |
// Check the folder contains a valid theme |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
911 |
$working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
912 |
if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, lets not prevent installation. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
913 |
return $source; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
914 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
915 |
// A proper archive should have a style.css file in the single subdirectory |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
916 |
if ( ! file_exists( $working_directory . 'style.css' ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
917 |
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>style.css</code> stylesheet.') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
918 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
919 |
$info = get_file_data( $working_directory . 'style.css', array( 'Name' => 'Theme Name', 'Template' => 'Template' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
920 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
921 |
if ( empty( $info['Name'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
922 |
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __("The <code>style.css</code> stylesheet doesn't contain a valid theme header.") ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
923 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
924 |
// If it's not a child theme, it must have at least an index.php to be legit. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
925 |
if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
926 |
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>index.php</code> file.') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
927 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
928 |
return $source; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
929 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
930 |
|
136 | 931 |
function current_before($return, $theme) { |
932 |
||
933 |
if ( is_wp_error($return) ) |
|
934 |
return $return; |
|
935 |
||
936 |
$theme = isset($theme['theme']) ? $theme['theme'] : ''; |
|
937 |
||
938 |
if ( $theme != get_stylesheet() ) //If not current |
|
939 |
return $return; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
940 |
//Change to maintenance mode now. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
941 |
if ( ! $this->bulk ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
942 |
$this->maintenance_mode(true); |
136 | 943 |
|
944 |
return $return; |
|
945 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
946 |
|
136 | 947 |
function current_after($return, $theme) { |
948 |
if ( is_wp_error($return) ) |
|
949 |
return $return; |
|
950 |
||
951 |
$theme = isset($theme['theme']) ? $theme['theme'] : ''; |
|
952 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
953 |
if ( $theme != get_stylesheet() ) // If not current |
136 | 954 |
return $return; |
955 |
||
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
956 |
// Ensure stylesheet name hasn't changed after the upgrade: |
136 | 957 |
if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) { |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
958 |
wp_clean_themes_cache(); |
136 | 959 |
$stylesheet = $this->result['destination_name']; |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
960 |
switch_theme( $stylesheet ); |
136 | 961 |
} |
962 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
963 |
//Time to remove maintenance mode |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
964 |
if ( ! $this->bulk ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
965 |
$this->maintenance_mode(false); |
136 | 966 |
return $return; |
967 |
} |
|
968 |
||
969 |
function delete_old_theme($removed, $local_destination, $remote_destination, $theme) { |
|
970 |
global $wp_filesystem; |
|
971 |
||
972 |
$theme = isset($theme['theme']) ? $theme['theme'] : ''; |
|
973 |
||
974 |
if ( is_wp_error($removed) || empty($theme) ) |
|
975 |
return $removed; //Pass errors through. |
|
976 |
||
977 |
$themes_dir = $wp_filesystem->wp_themes_dir(); |
|
978 |
if ( $wp_filesystem->exists( trailingslashit($themes_dir) . $theme ) ) |
|
979 |
if ( ! $wp_filesystem->delete( trailingslashit($themes_dir) . $theme, true ) ) |
|
980 |
return false; |
|
981 |
return true; |
|
982 |
} |
|
983 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
984 |
function theme_info($theme = null) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
985 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
986 |
if ( empty($theme) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
987 |
if ( !empty($this->result['destination_name']) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
988 |
$theme = $this->result['destination_name']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
989 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
990 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
991 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
992 |
return wp_get_theme( $theme, WP_CONTENT_DIR . '/themes/' ); |
136 | 993 |
} |
994 |
||
995 |
} |
|
996 |
||
997 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
998 |
* Core Upgrader class for WordPress. It allows for WordPress to upgrade itself in combination with the wp-admin/includes/update-core.php file |
136 | 999 |
* |
1000 |
* @TODO More Detailed docs, for methods as well. |
|
1001 |
* |
|
1002 |
* @package WordPress |
|
1003 |
* @subpackage Upgrader |
|
1004 |
* @since 2.8.0 |
|
1005 |
*/ |
|
1006 |
class Core_Upgrader extends WP_Upgrader { |
|
1007 |
||
1008 |
function upgrade_strings() { |
|
1009 |
$this->strings['up_to_date'] = __('WordPress is at the latest version.'); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1010 |
$this->strings['no_package'] = __('Update package not available.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1011 |
$this->strings['downloading_package'] = __('Downloading update from <span class="code">%s</span>…'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1012 |
$this->strings['unpack_package'] = __('Unpacking the update…'); |
136 | 1013 |
$this->strings['copy_failed'] = __('Could not copy files.'); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1014 |
$this->strings['copy_failed_space'] = __('Could not copy files. You may have run out of disk space.' ); |
136 | 1015 |
} |
1016 |
||
1017 |
function upgrade($current) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1018 |
global $wp_filesystem, $wp_version; |
136 | 1019 |
|
1020 |
$this->init(); |
|
1021 |
$this->upgrade_strings(); |
|
1022 |
||
1023 |
if ( !empty($feedback) ) |
|
1024 |
add_filter('update_feedback', $feedback); |
|
1025 |
||
1026 |
// Is an update available? |
|
1027 |
if ( !isset( $current->response ) || $current->response == 'latest' ) |
|
1028 |
return new WP_Error('up_to_date', $this->strings['up_to_date']); |
|
1029 |
||
1030 |
$res = $this->fs_connect( array(ABSPATH, WP_CONTENT_DIR) ); |
|
1031 |
if ( is_wp_error($res) ) |
|
1032 |
return $res; |
|
1033 |
||
1034 |
$wp_dir = trailingslashit($wp_filesystem->abspath()); |
|
1035 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1036 |
// If partial update is returned from the API, use that, unless we're doing a reinstall. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1037 |
// If we cross the new_bundled version number, then use the new_bundled zip. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1038 |
// Don't though if the constant is set to skip bundled items. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1039 |
// If the API returns a no_content zip, go with it. Finally, default to the full zip. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1040 |
if ( $current->packages->partial && 'reinstall' != $current->response && $wp_version == $current->partial_version ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1041 |
$to_download = 'partial'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1042 |
elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1043 |
&& ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1044 |
$to_download = 'new_bundled'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1045 |
elseif ( $current->packages->no_content ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1046 |
$to_download = 'no_content'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1047 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1048 |
$to_download = 'full'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1049 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1050 |
$download = $this->download_package( $current->packages->$to_download ); |
136 | 1051 |
if ( is_wp_error($download) ) |
1052 |
return $download; |
|
1053 |
||
1054 |
$working_dir = $this->unpack_package( $download ); |
|
1055 |
if ( is_wp_error($working_dir) ) |
|
1056 |
return $working_dir; |
|
1057 |
||
1058 |
// Copy update-core.php from the new version into place. |
|
1059 |
if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) { |
|
1060 |
$wp_filesystem->delete($working_dir, true); |
|
1061 |
return new WP_Error('copy_failed', $this->strings['copy_failed']); |
|
1062 |
} |
|
1063 |
$wp_filesystem->chmod($wp_dir . 'wp-admin/includes/update-core.php', FS_CHMOD_FILE); |
|
1064 |
||
1065 |
require(ABSPATH . 'wp-admin/includes/update-core.php'); |
|
1066 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1067 |
if ( ! function_exists( 'update_core' ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1068 |
return new WP_Error( 'copy_failed_space', $this->strings['copy_failed_space'] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1069 |
|
136 | 1070 |
return update_core($working_dir, $wp_dir); |
1071 |
} |
|
1072 |
||
1073 |
} |
|
1074 |
||
1075 |
/** |
|
1076 |
* Generic Skin for the WordPress Upgrader classes. This skin is designed to be extended for specific purposes. |
|
1077 |
* |
|
1078 |
* @TODO More Detailed docs, for methods as well. |
|
1079 |
* |
|
1080 |
* @package WordPress |
|
1081 |
* @subpackage Upgrader |
|
1082 |
* @since 2.8.0 |
|
1083 |
*/ |
|
1084 |
class WP_Upgrader_Skin { |
|
1085 |
||
1086 |
var $upgrader; |
|
1087 |
var $done_header = false; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1088 |
var $result = false; |
136 | 1089 |
|
1090 |
function __construct($args = array()) { |
|
1091 |
$defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false ); |
|
1092 |
$this->options = wp_parse_args($args, $defaults); |
|
1093 |
} |
|
1094 |
||
1095 |
function set_upgrader(&$upgrader) { |
|
1096 |
if ( is_object($upgrader) ) |
|
1097 |
$this->upgrader =& $upgrader; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1098 |
$this->add_strings(); |
136 | 1099 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1100 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1101 |
function add_strings() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1102 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1103 |
|
136 | 1104 |
function set_result($result) { |
1105 |
$this->result = $result; |
|
1106 |
} |
|
1107 |
||
1108 |
function request_filesystem_credentials($error = false) { |
|
1109 |
$url = $this->options['url']; |
|
1110 |
$context = $this->options['context']; |
|
1111 |
if ( !empty($this->options['nonce']) ) |
|
1112 |
$url = wp_nonce_url($url, $this->options['nonce']); |
|
1113 |
return request_filesystem_credentials($url, '', $error, $context); //Possible to bring inline, Leaving as is for now. |
|
1114 |
} |
|
1115 |
||
1116 |
function header() { |
|
1117 |
if ( $this->done_header ) |
|
1118 |
return; |
|
1119 |
$this->done_header = true; |
|
1120 |
echo '<div class="wrap">'; |
|
1121 |
echo screen_icon(); |
|
1122 |
echo '<h2>' . $this->options['title'] . '</h2>'; |
|
1123 |
} |
|
1124 |
function footer() { |
|
1125 |
echo '</div>'; |
|
1126 |
} |
|
1127 |
||
1128 |
function error($errors) { |
|
1129 |
if ( ! $this->done_header ) |
|
1130 |
$this->header(); |
|
1131 |
if ( is_string($errors) ) { |
|
1132 |
$this->feedback($errors); |
|
1133 |
} elseif ( is_wp_error($errors) && $errors->get_error_code() ) { |
|
1134 |
foreach ( $errors->get_error_messages() as $message ) { |
|
1135 |
if ( $errors->get_error_data() ) |
|
1136 |
$this->feedback($message . ' ' . $errors->get_error_data() ); |
|
1137 |
else |
|
1138 |
$this->feedback($message); |
|
1139 |
} |
|
1140 |
} |
|
1141 |
} |
|
1142 |
||
1143 |
function feedback($string) { |
|
1144 |
if ( isset( $this->upgrader->strings[$string] ) ) |
|
1145 |
$string = $this->upgrader->strings[$string]; |
|
1146 |
||
1147 |
if ( strpos($string, '%') !== false ) { |
|
1148 |
$args = func_get_args(); |
|
1149 |
$args = array_splice($args, 1); |
|
1150 |
if ( !empty($args) ) |
|
1151 |
$string = vsprintf($string, $args); |
|
1152 |
} |
|
1153 |
if ( empty($string) ) |
|
1154 |
return; |
|
1155 |
show_message($string); |
|
1156 |
} |
|
1157 |
function before() {} |
|
1158 |
function after() {} |
|
1159 |
||
1160 |
} |
|
1161 |
||
1162 |
/** |
|
1163 |
* Plugin Upgrader Skin for WordPress Plugin Upgrades. |
|
1164 |
* |
|
1165 |
* @TODO More Detailed docs, for methods as well. |
|
1166 |
* |
|
1167 |
* @package WordPress |
|
1168 |
* @subpackage Upgrader |
|
1169 |
* @since 2.8.0 |
|
1170 |
*/ |
|
1171 |
class Plugin_Upgrader_Skin extends WP_Upgrader_Skin { |
|
1172 |
var $plugin = ''; |
|
1173 |
var $plugin_active = false; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1174 |
var $plugin_network_active = false; |
136 | 1175 |
|
1176 |
function __construct($args = array()) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1177 |
$defaults = array( 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => __('Update Plugin') ); |
136 | 1178 |
$args = wp_parse_args($args, $defaults); |
1179 |
||
1180 |
$this->plugin = $args['plugin']; |
|
1181 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1182 |
$this->plugin_active = is_plugin_active( $this->plugin ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1183 |
$this->plugin_network_active = is_plugin_active_for_network( $this->plugin ); |
136 | 1184 |
|
1185 |
parent::__construct($args); |
|
1186 |
} |
|
1187 |
||
1188 |
function after() { |
|
1189 |
$this->plugin = $this->upgrader->plugin_info(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1190 |
if ( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1191 |
echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&networkwide=' . $this->plugin_network_active . '&plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) .'"></iframe>'; |
136 | 1192 |
} |
1193 |
||
1194 |
$update_actions = array( |
|
1195 |
'activate_plugin' => '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>', |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1196 |
'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>' |
136 | 1197 |
); |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1198 |
if ( $this->plugin_active || ! $this->result || is_wp_error( $this->result ) || ! current_user_can( 'activate_plugins' ) ) |
136 | 1199 |
unset( $update_actions['activate_plugin'] ); |
1200 |
||
1201 |
$update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $this->plugin); |
|
1202 |
if ( ! empty($update_actions) ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1203 |
$this->feedback(implode(' | ', (array)$update_actions)); |
136 | 1204 |
} |
1205 |
||
1206 |
function before() { |
|
1207 |
if ( $this->upgrader->show_before ) { |
|
1208 |
echo $this->upgrader->show_before; |
|
1209 |
$this->upgrader->show_before = ''; |
|
1210 |
} |
|
1211 |
} |
|
1212 |
} |
|
1213 |
||
1214 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1215 |
* Plugin Upgrader Skin for WordPress Plugin Upgrades. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1216 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1217 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1218 |
* @subpackage Upgrader |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1219 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1220 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1221 |
class Bulk_Upgrader_Skin extends WP_Upgrader_Skin { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1222 |
var $in_loop = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1223 |
var $error = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1224 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1225 |
function __construct($args = array()) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1226 |
$defaults = array( 'url' => '', 'nonce' => '' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1227 |
$args = wp_parse_args($args, $defaults); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1228 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1229 |
parent::__construct($args); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1230 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1231 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1232 |
function add_strings() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1233 |
$this->upgrader->strings['skin_upgrade_start'] = __('The update process is starting. This process may take a while on some hosts, so please be patient.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1234 |
$this->upgrader->strings['skin_update_failed_error'] = __('An error occurred while updating %1$s: <strong>%2$s</strong>.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1235 |
$this->upgrader->strings['skin_update_failed'] = __('The update of %1$s failed.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1236 |
$this->upgrader->strings['skin_update_successful'] = __('%1$s updated successfully.').' <a onclick="%2$s" href="#" class="hide-if-no-js"><span>'.__('Show Details').'</span><span class="hidden">'.__('Hide Details').'</span>.</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1237 |
$this->upgrader->strings['skin_upgrade_end'] = __('All updates have been completed.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1238 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1239 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1240 |
function feedback($string) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1241 |
if ( isset( $this->upgrader->strings[$string] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1242 |
$string = $this->upgrader->strings[$string]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1243 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1244 |
if ( strpos($string, '%') !== false ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1245 |
$args = func_get_args(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1246 |
$args = array_splice($args, 1); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1247 |
if ( !empty($args) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1248 |
$string = vsprintf($string, $args); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1249 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1250 |
if ( empty($string) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1251 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1252 |
if ( $this->in_loop ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1253 |
echo "$string<br />\n"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1254 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1255 |
echo "<p>$string</p>\n"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1256 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1257 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1258 |
function header() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1259 |
// Nothing, This will be displayed within a iframe. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1260 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1261 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1262 |
function footer() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1263 |
// Nothing, This will be displayed within a iframe. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1264 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1265 |
function error($error) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1266 |
if ( is_string($error) && isset( $this->upgrader->strings[$error] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1267 |
$this->error = $this->upgrader->strings[$error]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1268 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1269 |
if ( is_wp_error($error) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1270 |
foreach ( $error->get_error_messages() as $emessage ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1271 |
if ( $error->get_error_data() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1272 |
$messages[] = $emessage . ' ' . $error->get_error_data(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1273 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1274 |
$messages[] = $emessage; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1275 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1276 |
$this->error = implode(', ', $messages); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1277 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1278 |
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1279 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1280 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1281 |
function bulk_header() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1282 |
$this->feedback('skin_upgrade_start'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1283 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1284 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1285 |
function bulk_footer() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1286 |
$this->feedback('skin_upgrade_end'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1287 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1288 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1289 |
function before($title = '') { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1290 |
$this->in_loop = true; |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1291 |
printf( '<h4>' . $this->upgrader->strings['skin_before_update_header'] . ' <span class="spinner waiting-' . $this->upgrader->update_current . '"></span></h4>', $title, $this->upgrader->update_current, $this->upgrader->update_count); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1292 |
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').css("display", "inline-block");</script>'; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1293 |
echo '<div class="update-messages hide-if-js" id="progress-' . esc_attr($this->upgrader->update_current) . '"><p>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1294 |
$this->flush_output(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1295 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1296 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1297 |
function after($title = '') { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1298 |
echo '</p></div>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1299 |
if ( $this->error || ! $this->result ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1300 |
if ( $this->error ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1301 |
echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed_error'], $title, $this->error) . '</p></div>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1302 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1303 |
echo '<div class="error"><p>' . sprintf($this->upgrader->strings['skin_update_failed'], $title) . '</p></div>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1304 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1305 |
echo '<script type="text/javascript">jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').show();</script>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1306 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1307 |
if ( !empty($this->result) && !is_wp_error($this->result) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1308 |
echo '<div class="updated"><p>' . sprintf($this->upgrader->strings['skin_update_successful'], $title, 'jQuery(\'#progress-' . esc_js($this->upgrader->update_current) . '\').toggle();jQuery(\'span\', this).toggle(); return false;') . '</p></div>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1309 |
echo '<script type="text/javascript">jQuery(\'.waiting-' . esc_js($this->upgrader->update_current) . '\').hide();</script>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1310 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1311 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1312 |
$this->reset(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1313 |
$this->flush_output(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1314 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1315 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1316 |
function reset() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1317 |
$this->in_loop = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1318 |
$this->error = false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1319 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1320 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1321 |
function flush_output() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1322 |
wp_ob_end_flush_all(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1323 |
flush(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1324 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1325 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1326 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1327 |
class Bulk_Plugin_Upgrader_Skin extends Bulk_Upgrader_Skin { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1328 |
var $plugin_info = array(); // Plugin_Upgrader::bulk() will fill this in. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1329 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1330 |
function __construct($args = array()) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1331 |
parent::__construct($args); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1332 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1333 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1334 |
function add_strings() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1335 |
parent::add_strings(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1336 |
$this->upgrader->strings['skin_before_update_header'] = __('Updating Plugin %1$s (%2$d/%3$d)'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1337 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1338 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1339 |
function before() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1340 |
parent::before($this->plugin_info['Title']); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1341 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1342 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1343 |
function after() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1344 |
parent::after($this->plugin_info['Title']); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1345 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1346 |
function bulk_footer() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1347 |
parent::bulk_footer(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1348 |
$update_actions = array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1349 |
'plugins_page' => '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Go to plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1350 |
'updates_page' => '<a href="' . self_admin_url('update-core.php') . '" title="' . esc_attr__('Go to WordPress Updates page') . '" target="_parent">' . __('Return to WordPress Updates') . '</a>' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1351 |
); |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1352 |
if ( ! current_user_can( 'activate_plugins' ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1353 |
unset( $update_actions['plugins_page'] ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1354 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1355 |
$update_actions = apply_filters('update_bulk_plugins_complete_actions', $update_actions, $this->plugin_info); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1356 |
if ( ! empty($update_actions) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1357 |
$this->feedback(implode(' | ', (array)$update_actions)); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1358 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1359 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1360 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1361 |
class Bulk_Theme_Upgrader_Skin extends Bulk_Upgrader_Skin { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1362 |
var $theme_info = array(); // Theme_Upgrader::bulk() will fill this in. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1363 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1364 |
function __construct($args = array()) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1365 |
parent::__construct($args); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1366 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1367 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1368 |
function add_strings() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1369 |
parent::add_strings(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1370 |
$this->upgrader->strings['skin_before_update_header'] = __('Updating Theme %1$s (%2$d/%3$d)'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1371 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1372 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1373 |
function before() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1374 |
parent::before( $this->theme_info->display('Name') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1375 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1376 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1377 |
function after() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1378 |
parent::after( $this->theme_info->display('Name') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1379 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1380 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1381 |
function bulk_footer() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1382 |
parent::bulk_footer(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1383 |
$update_actions = array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1384 |
'themes_page' => '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Go to themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1385 |
'updates_page' => '<a href="' . self_admin_url('update-core.php') . '" title="' . esc_attr__('Go to WordPress Updates page') . '" target="_parent">' . __('Return to WordPress Updates') . '</a>' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1386 |
); |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1387 |
if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1388 |
unset( $update_actions['themes_page'] ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1389 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1390 |
$update_actions = apply_filters('update_bulk_theme_complete_actions', $update_actions, $this->theme_info ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1391 |
if ( ! empty($update_actions) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1392 |
$this->feedback(implode(' | ', (array)$update_actions)); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1393 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1394 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1395 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1396 |
/** |
136 | 1397 |
* Plugin Installer Skin for WordPress Plugin Installer. |
1398 |
* |
|
1399 |
* @TODO More Detailed docs, for methods as well. |
|
1400 |
* |
|
1401 |
* @package WordPress |
|
1402 |
* @subpackage Upgrader |
|
1403 |
* @since 2.8.0 |
|
1404 |
*/ |
|
1405 |
class Plugin_Installer_Skin extends WP_Upgrader_Skin { |
|
1406 |
var $api; |
|
1407 |
var $type; |
|
1408 |
||
1409 |
function __construct($args = array()) { |
|
1410 |
$defaults = array( 'type' => 'web', 'url' => '', 'plugin' => '', 'nonce' => '', 'title' => '' ); |
|
1411 |
$args = wp_parse_args($args, $defaults); |
|
1412 |
||
1413 |
$this->type = $args['type']; |
|
1414 |
$this->api = isset($args['api']) ? $args['api'] : array(); |
|
1415 |
||
1416 |
parent::__construct($args); |
|
1417 |
} |
|
1418 |
||
1419 |
function before() { |
|
1420 |
if ( !empty($this->api) ) |
|
1421 |
$this->upgrader->strings['process_success'] = sprintf( __('Successfully installed the plugin <strong>%s %s</strong>.'), $this->api->name, $this->api->version); |
|
1422 |
} |
|
1423 |
||
1424 |
function after() { |
|
1425 |
||
1426 |
$plugin_file = $this->upgrader->plugin_info(); |
|
1427 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1428 |
$install_actions = array(); |
136 | 1429 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1430 |
$from = isset($_GET['from']) ? stripslashes($_GET['from']) : 'plugins'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1431 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1432 |
if ( 'import' == $from ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1433 |
$install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&from=import&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin & Run Importer') . '</a>'; |
136 | 1434 |
else |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1435 |
$install_actions['activate_plugin'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>'; |
136 | 1436 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1437 |
if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1438 |
$install_actions['network_activate'] = '<a href="' . wp_nonce_url('plugins.php?action=activate&networkwide=1&plugin=' . $plugin_file, 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin for all sites in this network') . '" target="_parent">' . __('Network Activate') . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1439 |
unset( $install_actions['activate_plugin'] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1440 |
} |
136 | 1441 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1442 |
if ( 'import' == $from ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1443 |
$install_actions['importers_page'] = '<a href="' . admin_url('import.php') . '" title="' . esc_attr__('Return to Importers') . '" target="_parent">' . __('Return to Importers') . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1444 |
else if ( $this->type == 'web' ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1445 |
$install_actions['plugins_page'] = '<a href="' . self_admin_url('plugin-install.php') . '" title="' . esc_attr__('Return to Plugin Installer') . '" target="_parent">' . __('Return to Plugin Installer') . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1446 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1447 |
$install_actions['plugins_page'] = '<a href="' . self_admin_url('plugins.php') . '" title="' . esc_attr__('Return to Plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1448 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1449 |
if ( ! $this->result || is_wp_error($this->result) ) { |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1450 |
unset( $install_actions['activate_plugin'], $install_actions['network_activate'] ); |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1451 |
} elseif ( ! current_user_can( 'activate_plugins' ) ) { |
136 | 1452 |
unset( $install_actions['activate_plugin'] ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1453 |
} |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1454 |
|
136 | 1455 |
$install_actions = apply_filters('install_plugin_complete_actions', $install_actions, $this->api, $plugin_file); |
1456 |
if ( ! empty($install_actions) ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1457 |
$this->feedback(implode(' | ', (array)$install_actions)); |
136 | 1458 |
} |
1459 |
} |
|
1460 |
||
1461 |
/** |
|
1462 |
* Theme Installer Skin for the WordPress Theme Installer. |
|
1463 |
* |
|
1464 |
* @TODO More Detailed docs, for methods as well. |
|
1465 |
* |
|
1466 |
* @package WordPress |
|
1467 |
* @subpackage Upgrader |
|
1468 |
* @since 2.8.0 |
|
1469 |
*/ |
|
1470 |
class Theme_Installer_Skin extends WP_Upgrader_Skin { |
|
1471 |
var $api; |
|
1472 |
var $type; |
|
1473 |
||
1474 |
function __construct($args = array()) { |
|
1475 |
$defaults = array( 'type' => 'web', 'url' => '', 'theme' => '', 'nonce' => '', 'title' => '' ); |
|
1476 |
$args = wp_parse_args($args, $defaults); |
|
1477 |
||
1478 |
$this->type = $args['type']; |
|
1479 |
$this->api = isset($args['api']) ? $args['api'] : array(); |
|
1480 |
||
1481 |
parent::__construct($args); |
|
1482 |
} |
|
1483 |
||
1484 |
function before() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1485 |
if ( !empty($this->api) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1486 |
$this->upgrader->strings['process_success'] = sprintf( $this->upgrader->strings['process_success_specific'], $this->api->name, $this->api->version); |
136 | 1487 |
} |
1488 |
||
1489 |
function after() { |
|
1490 |
if ( empty($this->upgrader->result['destination_name']) ) |
|
1491 |
return; |
|
1492 |
||
1493 |
$theme_info = $this->upgrader->theme_info(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1494 |
if ( empty( $theme_info ) ) |
136 | 1495 |
return; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1496 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1497 |
$name = $theme_info->display('Name'); |
136 | 1498 |
$stylesheet = $this->upgrader->result['destination_name']; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1499 |
$template = $theme_info->get_template(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1500 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1501 |
$preview_link = add_query_arg( array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1502 |
'preview' => 1, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1503 |
'template' => urlencode( $template ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1504 |
'stylesheet' => urlencode( $stylesheet ), |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1505 |
), trailingslashit( home_url() ) ); |
136 | 1506 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1507 |
$activate_link = add_query_arg( array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1508 |
'action' => 'activate', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1509 |
'template' => urlencode( $template ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1510 |
'stylesheet' => urlencode( $stylesheet ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1511 |
), admin_url('themes.php') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1512 |
$activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); |
136 | 1513 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1514 |
$install_actions = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1515 |
$install_actions['preview'] = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview “%s”'), $name ) ) . '">' . __('Preview') . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1516 |
$install_actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Preview “%s”'), $name ) ) . '">' . __('Live Preview') . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1517 |
$install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1518 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1519 |
if ( is_network_admin() && current_user_can( 'manage_network_themes' ) ) |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1520 |
$install_actions['network_enable'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=enable&theme=' . urlencode( $stylesheet ), 'enable-theme_' . $stylesheet ) ) . '" title="' . esc_attr__( 'Enable this theme for all sites in this network' ) . '" target="_parent">' . __( 'Network Enable' ) . '</a>'; |
136 | 1521 |
|
1522 |
if ( $this->type == 'web' ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1523 |
$install_actions['themes_page'] = '<a href="' . self_admin_url('theme-install.php') . '" title="' . esc_attr__('Return to Theme Installer') . '" target="_parent">' . __('Return to Theme Installer') . '</a>'; |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1524 |
elseif ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) ) |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1525 |
$install_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>'; |
136 | 1526 |
|
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1527 |
if ( ! $this->result || is_wp_error($this->result) || is_network_admin() || ! current_user_can( 'switch_themes' ) ) |
136 | 1528 |
unset( $install_actions['activate'], $install_actions['preview'] ); |
1529 |
||
1530 |
$install_actions = apply_filters('install_theme_complete_actions', $install_actions, $this->api, $stylesheet, $theme_info); |
|
1531 |
if ( ! empty($install_actions) ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1532 |
$this->feedback(implode(' | ', (array)$install_actions)); |
136 | 1533 |
} |
1534 |
} |
|
1535 |
||
1536 |
/** |
|
1537 |
* Theme Upgrader Skin for WordPress Theme Upgrades. |
|
1538 |
* |
|
1539 |
* @TODO More Detailed docs, for methods as well. |
|
1540 |
* |
|
1541 |
* @package WordPress |
|
1542 |
* @subpackage Upgrader |
|
1543 |
* @since 2.8.0 |
|
1544 |
*/ |
|
1545 |
class Theme_Upgrader_Skin extends WP_Upgrader_Skin { |
|
1546 |
var $theme = ''; |
|
1547 |
||
1548 |
function __construct($args = array()) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1549 |
$defaults = array( 'url' => '', 'theme' => '', 'nonce' => '', 'title' => __('Update Theme') ); |
136 | 1550 |
$args = wp_parse_args($args, $defaults); |
1551 |
||
1552 |
$this->theme = $args['theme']; |
|
1553 |
||
1554 |
parent::__construct($args); |
|
1555 |
} |
|
1556 |
||
1557 |
function after() { |
|
1558 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1559 |
$update_actions = array(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1560 |
if ( ! empty( $this->upgrader->result['destination_name'] ) && $theme_info = $this->upgrader->theme_info() ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1561 |
$name = $theme_info->display('Name'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1562 |
$stylesheet = $this->upgrader->result['destination_name']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1563 |
$template = $theme_info->get_template(); |
136 | 1564 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1565 |
$preview_link = add_query_arg( array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1566 |
'preview' => 1, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1567 |
'template' => urlencode( $template ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1568 |
'stylesheet' => urlencode( $stylesheet ), |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1569 |
), trailingslashit( home_url() ) ); |
136 | 1570 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1571 |
$activate_link = add_query_arg( array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1572 |
'action' => 'activate', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1573 |
'template' => urlencode( $template ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1574 |
'stylesheet' => urlencode( $stylesheet ), |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1575 |
), admin_url('themes.php') ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1576 |
$activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet ); |
136 | 1577 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1578 |
if ( get_stylesheet() == $stylesheet ) { |
204
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1579 |
if ( current_user_can( 'edit_theme_options' ) ) |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1580 |
$update_actions['preview'] = '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Customize “%s”'), $name ) ) . '">' . __('Customize') . '</a>'; |
09a1c134465b
man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
194
diff
changeset
|
1581 |
} elseif ( current_user_can( 'switch_themes' ) ) { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1582 |
$update_actions['preview'] = '<a href="' . esc_url( $preview_link ) . '" class="hide-if-customize" title="' . esc_attr( sprintf( __('Preview “%s”'), $name ) ) . '">' . __('Preview') . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1583 |
$update_actions['preview'] .= '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize" title="' . esc_attr( sprintf( __('Preview “%s”'), $name ) ) . '">' . __('Live Preview') . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1584 |
$update_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1585 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1586 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1587 |
if ( ! $this->result || is_wp_error( $this->result ) || is_network_admin() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1588 |
unset( $update_actions['preview'], $update_actions['activate'] ); |
136 | 1589 |
} |
1590 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1591 |
$update_actions['themes_page'] = '<a href="' . self_admin_url('themes.php') . '" title="' . esc_attr__('Return to Themes page') . '" target="_parent">' . __('Return to Themes page') . '</a>'; |
136 | 1592 |
|
1593 |
$update_actions = apply_filters('update_theme_complete_actions', $update_actions, $this->theme); |
|
1594 |
if ( ! empty($update_actions) ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1595 |
$this->feedback(implode(' | ', (array)$update_actions)); |
136 | 1596 |
} |
1597 |
} |
|
1598 |
||
1599 |
/** |
|
1600 |
* Upgrade Skin helper for File uploads. This class handles the upload process and passes it as if its a local file to the Upgrade/Installer functions. |
|
1601 |
* |
|
1602 |
* @TODO More Detailed docs, for methods as well. |
|
1603 |
* |
|
1604 |
* @package WordPress |
|
1605 |
* @subpackage Upgrader |
|
1606 |
* @since 2.8.0 |
|
1607 |
*/ |
|
1608 |
class File_Upload_Upgrader { |
|
1609 |
var $package; |
|
1610 |
var $filename; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1611 |
var $id = 0; |
136 | 1612 |
|
1613 |
function __construct($form, $urlholder) { |
|
1614 |
||
1615 |
if ( empty($_FILES[$form]['name']) && empty($_GET[$urlholder]) ) |
|
1616 |
wp_die(__('Please select a file')); |
|
1617 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1618 |
//Handle a newly uploaded file, Else assume its already been uploaded |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1619 |
if ( ! empty($_FILES) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1620 |
$overrides = array( 'test_form' => false, 'test_type' => false ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1621 |
$file = wp_handle_upload( $_FILES[$form], $overrides ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1622 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1623 |
if ( isset( $file['error'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1624 |
wp_die( $file['error'] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1625 |
|
136 | 1626 |
$this->filename = $_FILES[$form]['name']; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1627 |
$this->package = $file['file']; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1628 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1629 |
// Construct the object array |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1630 |
$object = array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1631 |
'post_title' => $this->filename, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1632 |
'post_content' => $file['url'], |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1633 |
'post_mime_type' => $file['type'], |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1634 |
'guid' => $file['url'], |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1635 |
'context' => 'upgrader', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1636 |
'post_status' => 'private' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1637 |
); |
136 | 1638 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1639 |
// Save the data |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1640 |
$this->id = wp_insert_attachment( $object, $file['file'] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1641 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1642 |
// schedule a cleanup for 2 hours from now in case of failed install |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1643 |
wp_schedule_single_event( time() + 7200, 'upgrader_scheduled_cleanup', array( $this->id ) ); |
136 | 1644 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1645 |
} elseif ( is_numeric( $_GET[$urlholder] ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1646 |
// Numeric Package = previously uploaded file, see above. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1647 |
$this->id = (int) $_GET[$urlholder]; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1648 |
$attachment = get_post( $this->id ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1649 |
if ( empty($attachment) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1650 |
wp_die(__('Please select a file')); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1651 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1652 |
$this->filename = $attachment->post_title; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1653 |
$this->package = get_attached_file( $attachment->ID ); |
136 | 1654 |
} else { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1655 |
// Else, It's set to something, Back compat for plugins using the old (pre-3.3) File_Uploader handler. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1656 |
if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1657 |
wp_die( $uploads['error'] ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1658 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1659 |
$this->filename = $_GET[$urlholder]; |
136 | 1660 |
$this->package = $uploads['basedir'] . '/' . $this->filename; |
1661 |
} |
|
1662 |
} |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1663 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1664 |
function cleanup() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1665 |
if ( $this->id ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1666 |
wp_delete_attachment( $this->id ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1667 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1668 |
elseif ( file_exists( $this->package ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1669 |
return @unlink( $this->package ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1670 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1671 |
return true; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1672 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1673 |
} |