79 |
79 |
80 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) |
80 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) |
81 return new WP_Error('fs_error', $this->strings['fs_error'], $wp_filesystem->errors); |
81 return new WP_Error('fs_error', $this->strings['fs_error'], $wp_filesystem->errors); |
82 |
82 |
83 foreach ( (array)$directories as $dir ) { |
83 foreach ( (array)$directories as $dir ) { |
84 if ( ABSPATH == $dir && ! $wp_filesystem->abspath() ) |
84 switch ( $dir ) { |
85 return new WP_Error('fs_no_root_dir', $this->strings['fs_no_root_dir']); |
85 case ABSPATH: |
86 |
86 if ( ! $wp_filesystem->abspath() ) |
87 elseif ( WP_CONTENT_DIR == $dir && ! $wp_filesystem->wp_content_dir() ) |
87 return new WP_Error('fs_no_root_dir', $this->strings['fs_no_root_dir']); |
88 return new WP_Error('fs_no_content_dir', $this->strings['fs_no_content_dir']); |
88 break; |
89 |
89 case WP_CONTENT_DIR: |
90 elseif ( WP_PLUGIN_DIR == $dir && ! $wp_filesystem->wp_plugins_dir() ) |
90 if ( ! $wp_filesystem->wp_content_dir() ) |
91 return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']); |
91 return new WP_Error('fs_no_content_dir', $this->strings['fs_no_content_dir']); |
92 |
92 break; |
93 elseif ( WP_CONTENT_DIR . '/themes' == $dir && ! $wp_filesystem->find_folder(WP_CONTENT_DIR . '/themes') ) |
93 case WP_PLUGIN_DIR: |
94 return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']); |
94 if ( ! $wp_filesystem->wp_plugins_dir() ) |
95 |
95 return new WP_Error('fs_no_plugins_dir', $this->strings['fs_no_plugins_dir']); |
96 elseif ( ! $wp_filesystem->find_folder($dir) ) |
96 break; |
97 return new WP_Error('fs_no_folder', sprintf($strings['fs_no_folder'], $dir)); |
97 case WP_CONTENT_DIR . '/themes': |
|
98 if ( ! $wp_filesystem->find_folder(WP_CONTENT_DIR . '/themes') ) |
|
99 return new WP_Error('fs_no_themes_dir', $this->strings['fs_no_themes_dir']); |
|
100 break; |
|
101 default: |
|
102 if ( ! $wp_filesystem->find_folder($dir) ) |
|
103 return new WP_Error('fs_no_folder', sprintf($this->strings['fs_no_folder'], $dir)); |
|
104 break; |
|
105 } |
98 } |
106 } |
99 return true; |
107 return true; |
100 } //end fs_connect(); |
108 } //end fs_connect(); |
101 |
109 |
102 function download_package($package) { |
110 function download_package($package) { |
200 if ( in_array( $destination, array(ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes') ) ) { |
208 if ( in_array( $destination, array(ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes') ) ) { |
201 $remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source)); |
209 $remote_destination = trailingslashit($remote_destination) . trailingslashit(basename($source)); |
202 $destination = trailingslashit($destination) . trailingslashit(basename($source)); |
210 $destination = trailingslashit($destination) . trailingslashit(basename($source)); |
203 } |
211 } |
204 |
212 |
205 //If we're not clearing the destination folder, and something exists there allready, Bail. |
213 if ( $wp_filesystem->exists($remote_destination) ) { |
206 if ( ! $clear_destination && $wp_filesystem->exists($remote_destination) ) { |
214 if ( $clear_destination ) { |
207 $wp_filesystem->delete($remote_source, true); //Clear out the source files. |
215 //We're going to clear the destination if theres something there |
208 return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination ); |
216 $this->skin->feedback('remove_old'); |
209 } else if ( $clear_destination ) { |
|
210 //We're going to clear the destination if theres something there |
|
211 $this->skin->feedback('remove_old'); |
|
212 |
|
213 $removed = true; |
|
214 if ( $wp_filesystem->exists($remote_destination) ) |
|
215 $removed = $wp_filesystem->delete($remote_destination, true); |
217 $removed = $wp_filesystem->delete($remote_destination, true); |
216 |
218 $removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra); |
217 $removed = apply_filters('upgrader_clear_destination', $removed, $local_destination, $remote_destination, $hook_extra); |
219 |
218 |
220 if ( is_wp_error($removed) ) |
219 if ( is_wp_error($removed) ) |
221 return $removed; |
220 return $removed; |
222 else if ( ! $removed ) |
221 else if ( ! $removed ) |
223 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']); |
222 return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']); |
224 } else { |
|
225 //If we're not clearing the destination folder and something exists there allready, Bail. |
|
226 //But first check to see if there are actually any files in the folder. |
|
227 $_files = $wp_filesystem->dirlist($remote_destination); |
|
228 if ( ! empty($_files) ) { |
|
229 $wp_filesystem->delete($remote_source, true); //Clear out the source files. |
|
230 return new WP_Error('folder_exists', $this->strings['folder_exists'], $remote_destination ); |
|
231 } |
|
232 } |
223 } |
233 } |
224 |
234 |
225 //Create destination if needed |
235 //Create destination if needed |
226 if ( !$wp_filesystem->exists($remote_destination) ) |
236 if ( !$wp_filesystem->exists($remote_destination) ) |
227 if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) ) |
237 if ( !$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR) ) |
259 |
269 |
260 $defaults = array( 'package' => '', //Please always pass this. |
270 $defaults = array( 'package' => '', //Please always pass this. |
261 'destination' => '', //And this |
271 'destination' => '', //And this |
262 'clear_destination' => false, |
272 'clear_destination' => false, |
263 'clear_working' => true, |
273 'clear_working' => true, |
|
274 'is_multi' => false, |
264 'hook_extra' => array() //Pass any extra $hook_extra args here, this will be passed to any hooked filters. |
275 'hook_extra' => array() //Pass any extra $hook_extra args here, this will be passed to any hooked filters. |
265 ); |
276 ); |
266 |
277 |
267 $options = wp_parse_args($options, $defaults); |
278 $options = wp_parse_args($options, $defaults); |
268 extract($options); |
279 extract($options); |
275 if ( is_wp_error($res) ) { |
286 if ( is_wp_error($res) ) { |
276 $this->skin->error($res); |
287 $this->skin->error($res); |
277 return $res; |
288 return $res; |
278 } |
289 } |
279 |
290 |
280 $this->skin->header(); |
291 if ( !$is_multi ) // call $this->header separately if running multiple times |
|
292 $this->skin->header(); |
|
293 |
281 $this->skin->before(); |
294 $this->skin->before(); |
282 |
295 |
283 //Download the package (Note, This just returns the filename of the file if the package is a local file) |
296 //Download the package (Note, This just returns the filename of the file if the package is a local file) |
284 $download = $this->download_package( $package ); |
297 $download = $this->download_package( $package ); |
285 if ( is_wp_error($download) ) { |
298 if ( is_wp_error($download) ) { |
412 'hook_extra' => array( |
430 'hook_extra' => array( |
413 'plugin' => $plugin |
431 'plugin' => $plugin |
414 ) |
432 ) |
415 )); |
433 )); |
416 |
434 |
417 //Cleanup our hooks, incase something else does a upgrade on this connection. |
435 // Cleanup our hooks, incase something else does a upgrade on this connection. |
418 remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade')); |
436 remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade')); |
419 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin')); |
437 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin')); |
420 |
438 |
421 if ( ! $this->result || is_wp_error($this->result) ) |
439 if ( ! $this->result || is_wp_error($this->result) ) |
422 return $this->result; |
440 return $this->result; |
423 |
441 |
424 // Force refresh of plugin update information |
442 // Force refresh of plugin update information |
425 delete_transient('update_plugins'); |
443 delete_transient('update_plugins'); |
|
444 } |
|
445 |
|
446 function bulk_upgrade($plugins) { |
|
447 |
|
448 $this->init(); |
|
449 $this->bulk = true; |
|
450 $this->upgrade_strings(); |
|
451 |
|
452 $current = get_transient( 'update_plugins' ); |
|
453 |
|
454 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4); |
|
455 |
|
456 $this->skin->header(); |
|
457 |
|
458 // Connect to the Filesystem first. |
|
459 $res = $this->fs_connect( array(WP_CONTENT_DIR, WP_PLUGIN_DIR) ); |
|
460 if ( ! $res ) { |
|
461 $this->skin->footer(); |
|
462 return false; |
|
463 } |
|
464 |
|
465 $this->maintenance_mode(true); |
|
466 |
|
467 $all = count($plugins); |
|
468 $i = 1; |
|
469 foreach ( $plugins as $plugin ) { |
|
470 |
|
471 $this->show_before = sprintf( '<h4>' . __('Updating plugin %1$d of %2$d...') . '</h4>', $i, $all ); |
|
472 $i++; |
|
473 |
|
474 if ( !isset( $current->response[ $plugin ] ) ) { |
|
475 $this->skin->set_result(false); |
|
476 $this->skin->error('up_to_date'); |
|
477 $this->skin->after(); |
|
478 $results[$plugin] = false; |
|
479 continue; |
|
480 } |
|
481 |
|
482 // Get the URL to the zip file |
|
483 $r = $current->response[ $plugin ]; |
|
484 |
|
485 $this->skin->plugin_active = is_plugin_active($plugin); |
|
486 |
|
487 $result = $this->run(array( |
|
488 'package' => $r->package, |
|
489 'destination' => WP_PLUGIN_DIR, |
|
490 'clear_destination' => true, |
|
491 'clear_working' => true, |
|
492 'is_multi' => true, |
|
493 'hook_extra' => array( |
|
494 'plugin' => $plugin |
|
495 ) |
|
496 )); |
|
497 |
|
498 $results[$plugin] = $this->result; |
|
499 |
|
500 // Prevent credentials auth screen from displaying multiple times |
|
501 if ( false === $result ) |
|
502 break; |
|
503 } |
|
504 $this->maintenance_mode(false); |
|
505 $this->skin->footer(); |
|
506 |
|
507 // Cleanup our hooks, incase something else does a upgrade on this connection. |
|
508 remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin')); |
|
509 |
|
510 // Force refresh of plugin update information |
|
511 delete_transient('update_plugins'); |
|
512 |
|
513 return $results; |
426 } |
514 } |
427 |
515 |
428 //return plugin info. |
516 //return plugin info. |
429 function plugin_info() { |
517 function plugin_info() { |
430 if ( ! is_array($this->result) ) |
518 if ( ! is_array($this->result) ) |
558 $this->skin->set_result(false); |
646 $this->skin->set_result(false); |
559 $this->skin->error('up_to_date'); |
647 $this->skin->error('up_to_date'); |
560 $this->skin->after(); |
648 $this->skin->after(); |
561 return false; |
649 return false; |
562 } |
650 } |
563 |
651 |
564 $r = $current->response[ $theme ]; |
652 $r = $current->response[ $theme ]; |
565 |
653 |
566 add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2); |
654 add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2); |
567 add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2); |
655 add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2); |
568 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4); |
656 add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4); |
818 |
906 |
819 parent::__construct($args); |
907 parent::__construct($args); |
820 } |
908 } |
821 |
909 |
822 function after() { |
910 function after() { |
|
911 if ( $this->upgrader->bulk ) |
|
912 return; |
|
913 |
823 $this->plugin = $this->upgrader->plugin_info(); |
914 $this->plugin = $this->upgrader->plugin_info(); |
824 if( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){ |
915 if( !empty($this->plugin) && !is_wp_error($this->result) && $this->plugin_active ){ |
825 show_message(__('Attempting reactivation of the plugin')); |
916 show_message(__('Attempting reactivation of the plugin')); |
826 echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) .'"></iframe>'; |
917 echo '<iframe style="border:0;overflow:hidden" width="100%" height="170px" src="' . wp_nonce_url('update.php?action=activate-plugin&plugin=' . $this->plugin, 'activate-plugin_' . $this->plugin) .'"></iframe>'; |
827 } |
918 } |
|
919 |
828 $update_actions = array( |
920 $update_actions = array( |
829 '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>', |
921 '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>', |
830 'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . esc_attr__('Goto plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>' |
922 'plugins_page' => '<a href="' . admin_url('plugins.php') . '" title="' . esc_attr__('Goto plugins page') . '" target="_parent">' . __('Return to Plugins page') . '</a>' |
831 ); |
923 ); |
832 if ( $this->plugin_active ) |
924 if ( $this->plugin_active ) |
836 |
928 |
837 $update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $this->plugin); |
929 $update_actions = apply_filters('update_plugin_complete_actions', $update_actions, $this->plugin); |
838 if ( ! empty($update_actions) ) |
930 if ( ! empty($update_actions) ) |
839 $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$update_actions)); |
931 $this->feedback('<strong>' . __('Actions:') . '</strong> ' . implode(' | ', (array)$update_actions)); |
840 } |
932 } |
|
933 |
|
934 function before() { |
|
935 if ( $this->upgrader->show_before ) { |
|
936 echo $this->upgrader->show_before; |
|
937 $this->upgrader->show_before = ''; |
|
938 } |
|
939 } |
841 } |
940 } |
842 |
941 |
843 /** |
942 /** |
844 * Plugin Installer Skin for WordPress Plugin Installer. |
943 * Plugin Installer Skin for WordPress Plugin Installer. |
845 * |
944 * |
994 !empty($theme_info) ) { |
1093 !empty($theme_info) ) { |
995 |
1094 |
996 $name = $theme_info['Name']; |
1095 $name = $theme_info['Name']; |
997 $stylesheet = $this->upgrader->result['destination_name']; |
1096 $stylesheet = $this->upgrader->result['destination_name']; |
998 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet; |
1097 $template = !empty($theme_info['Template']) ? $theme_info['Template'] : $stylesheet; |
999 |
1098 |
1000 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) ); |
1099 $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), trailingslashit(esc_url(get_option('home'))) ) ); |
1001 $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template); |
1100 $activate_link = wp_nonce_url("themes.php?action=activate&template=" . urlencode($template) . "&stylesheet=" . urlencode($stylesheet), 'switch-theme_' . $template); |
1002 |
1101 |
1003 $update_actions = array( |
1102 $update_actions = array( |
1004 'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview “%s”'), $name)) . '">' . __('Preview') . '</a>', |
1103 'preview' => '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr(sprintf(__('Preview “%s”'), $name)) . '">' . __('Preview') . '</a>', |
1005 'activate' => '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>', |
1104 'activate' => '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>', |
1006 ); |
1105 ); |
1007 if ( ( ! $this->result || is_wp_error($this->result) ) || $stylesheet == get_stylesheet() ) |
1106 if ( ( ! $this->result || is_wp_error($this->result) ) || $stylesheet == get_stylesheet() ) |