$this->strings['installing_package'] = __('Installing the latest version…');
$this->strings['folder_exists'] = __('Destination folder already exists.');
$this->strings['mkdir_failed'] = __('Could not create directory.');
- $this->strings['bad_package'] = __('Incompatible Archive.');
+ $this->strings['incompatible_archive'] = __('The package could not be installed.');
$this->strings['maintenance_start'] = __('Enabling Maintenance mode…');
$this->strings['maintenance_end'] = __('Disabling Maintenance mode…');
if ( is_wp_error($result) ) {
$wp_filesystem->delete($working_dir, true);
+ if ( 'incompatible_archive' == $result->get_error_code() ) {
+ return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data() );
+ }
return $result;
}
if ( 1 == count($source_files) && $wp_filesystem->is_dir( trailingslashit($source) . $source_files[0] . '/') ) //Only one folder? Then we want its contents.
$source = trailingslashit($source) . trailingslashit($source_files[0]);
elseif ( count($source_files) == 0 )
- return new WP_Error('bad_package', $this->strings['bad_package']); //There are no files?
- //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.
+ return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __( 'The plugin contains no files.' ) ); //There are no files?
+ 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.
+ $source = trailingslashit($source);
//Hook ability to change the source file location..
$source = apply_filters('upgrader_source_selection', $source, $remote_source, $this);
}
if ( $clear_destination ) {
- //We're going to clear the destination if theres something there
+ //We're going to clear the destination if there's something there
$this->skin->feedback('remove_old');
$removed = true;
if ( $wp_filesystem->exists($remote_destination) )
else if ( ! $removed )
return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
} elseif ( $wp_filesystem->exists($remote_destination) ) {
- //If we're not clearing the destination folder and something exists there allready, Bail.
+ //If we're not clearing the destination folder and something exists there already, Bail.
//But first check to see if there are actually any files in the folder.
$_files = $wp_filesystem->dirlist($remote_destination);
if ( ! empty($_files) ) {
$delete_package = ($download != $package); // Do not delete a "local" file
- //Unzip's the file into a temporary directory
+ //Unzips the file into a temporary directory
$working_dir = $this->unpack_package( $download, $delete_package );
if ( is_wp_error($working_dir) ) {
$this->skin->error($working_dir);
$this->skin->error($result);
$this->skin->feedback('process_failed');
} else {
- //Install Suceeded
+ //Install Succeeded
$this->skin->feedback('process_success');
}
$this->skin->after();
$this->init();
$this->install_strings();
+ add_filter('upgrader_source_selection', array(&$this, 'check_package') );
+
$this->run(array(
'package' => $package,
'destination' => WP_PLUGIN_DIR,
'hook_extra' => array()
));
+ remove_filter('upgrader_source_selection', array(&$this, 'check_package') );
+
+ if ( ! $this->result || is_wp_error($this->result) )
+ return $this->result;
+
// Force refresh of plugin update information
delete_site_transient('update_plugins');
+ return true;
}
function upgrade($plugin) {
add_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'), 10, 2);
add_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'), 10, 4);
- //'source_selection' => array(&$this, 'source_selection'), //theres a track ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins.
+ //'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.
$this->run(array(
'package' => $r->package,
)
));
- // Cleanup our hooks, incase something else does a upgrade on this connection.
+ // Cleanup our hooks, in case something else does a upgrade on this connection.
remove_filter('upgrader_pre_install', array(&$this, 'deactivate_plugin_before_upgrade'));
remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
$this->skin->footer();
- // Cleanup our hooks, incase something else does a upgrade on this connection.
+ // Cleanup our hooks, in case something else does a upgrade on this connection.
remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_plugin'));
// Force refresh of plugin update information
return $results;
}
+ function check_package($source) {
+ global $wp_filesystem;
+
+ if ( is_wp_error($source) )
+ return $source;
+
+ $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source);
+ if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, lets not prevent installation.
+ return $source;
+
+ // Check the folder contains at least 1 valid plugin.
+ $plugins_found = false;
+ foreach ( glob( $working_directory . '*.php' ) as $file ) {
+ $info = get_plugin_data($file, false, false);
+ if ( !empty( $info['Name'] ) ) {
+ $plugins_found = true;
+ break;
+ }
+ }
+
+ if ( ! $plugins_found )
+ return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('No valid plugins were found.') );
+
+ return $source;
+ }
+
//return plugin info.
function plugin_info() {
if ( ! is_array($this->result) )
class Theme_Upgrader extends WP_Upgrader {
var $result;
+ var $bulk = false;
function upgrade_strings() {
$this->strings['up_to_date'] = __('The theme is at the latest version.');
$this->init();
$this->install_strings();
+ add_filter('upgrader_source_selection', array(&$this, 'check_package') );
+
$options = array(
'package' => $package,
'destination' => WP_CONTENT_DIR . '/themes',
$this->run($options);
+ remove_filter('upgrader_source_selection', array(&$this, 'check_package') );
+
if ( ! $this->result || is_wp_error($this->result) )
return $this->result;
// Force refresh of theme update information
delete_site_transient('update_themes');
- if ( empty($result['destination_name']) )
- return false;
- else
- return $result['destination_name'];
+ return true;
}
function upgrade($theme) {
$this->run($options);
+ remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
+ remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
+ remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
+
if ( ! $this->result || is_wp_error($this->result) )
return $this->result;
$this->skin->footer();
- // Cleanup our hooks, incase something else does a upgrade on this connection.
+ // Cleanup our hooks, in case something else does a upgrade on this connection.
remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2);
remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2);
remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4);
return $results;
}
+ function check_package($source) {
+ global $wp_filesystem;
+
+ if ( is_wp_error($source) )
+ return $source;
+
+ // Check the folder contains a valid theme
+ $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source);
+ if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, lets not prevent installation.
+ return $source;
+
+ if ( ! file_exists( $working_directory . 'style.css' ) ) // A proper archive should have a style.css file in the single subdirectory
+ return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>style.css</code> stylesheet.') );
+
+ $info = get_theme_data( $working_directory . 'style.css' );
+ if ( empty($info['Name']) )
+ return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __("The <code>style.css</code> stylesheet doesn't contain a valid theme header.") );
+
+ if ( empty($info['Template']) && ! file_exists( $working_directory . 'index.php' ) ) // If no template is set, it must have at least an index.php to be legit.
+ return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>index.php</code> file.') );
+
+ return $source;
+ }
+
function current_before($return, $theme) {
if ( is_wp_error($return) )
return $return;
}
+
function current_after($return, $theme) {
if ( is_wp_error($return) )
return $return;
return $return;
//Ensure stylesheet name hasnt changed after the upgrade:
- // @TODO: Note, This doesnt handle the Template changing, or the Template name changing.
+ // @TODO: Note, This doesn't handle the Template changing, or the Template name changing.
if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) {
$theme_info = $this->theme_info();
$stylesheet = $this->result['destination_name'];
}
/**
- * Core Upgrader class for WordPress. It allows for WordPress to upgrade itself in combiantion with the wp-admin/includes/update-core.php file
+ * Core Upgrader class for WordPress. It allows for WordPress to upgrade itself in combination with the wp-admin/includes/update-core.php file
*
* @TODO More Detailed docs, for methods as well.
*
'activate' => '<a href="' . $activate_link . '" class="activatelink" title="' . esc_attr( sprintf( __('Activate “%s”'), $name ) ) . '">' . __('Activate') . '</a>'
);
+ if ( is_network_admin() && current_user_can( 'manage_network_themes' ) )
+ $install_actions['network_enable'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=enable&theme=' . $template, 'enable-theme_' . $template ) ) . '" title="' . esc_attr__( 'Enable this theme for all sites in this network' ) . '" target="_parent">' . __( 'Network Enable' ) . '</a>';
+
if ( $this->type == 'web' )
$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>';
else
class File_Upload_Upgrader {
var $package;
var $filename;
+ var $id = 0;
function __construct($form, $urlholder) {
- if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
- wp_die($uploads['error']);
if ( empty($_FILES[$form]['name']) && empty($_GET[$urlholder]) )
wp_die(__('Please select a file'));
- if ( !empty($_FILES) )
- $this->filename = $_FILES[$form]['name'];
- else if ( isset($_GET[$urlholder]) )
- $this->filename = $_GET[$urlholder];
-
//Handle a newly uploaded file, Else assume its already been uploaded
- if ( !empty($_FILES) ) {
- $this->filename = wp_unique_filename( $uploads['basedir'], $this->filename );
- $this->package = $uploads['basedir'] . '/' . $this->filename;
+ if ( ! empty($_FILES) ) {
+ $overrides = array( 'test_form' => false, 'test_type' => false );
+ $file = wp_handle_upload( $_FILES[$form], $overrides );
- // Move the file to the uploads dir
- if ( false === @ move_uploaded_file( $_FILES[$form]['tmp_name'], $this->package) )
- wp_die( sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path']));
+ if ( isset( $file['error'] ) )
+ wp_die( $file['error'] );
+
+ $this->filename = $_FILES[$form]['name'];
+ $this->package = $file['file'];
+
+ // Construct the object array
+ $object = array(
+ 'post_title' => $this->filename,
+ 'post_content' => $file['url'],
+ 'post_mime_type' => $file['type'],
+ 'guid' => $file['url'],
+ 'context' => 'upgrader',
+ 'post_status' => 'private'
+ );
+
+ // Save the data
+ $this->id = wp_insert_attachment( $object, $file['file'] );
+
+ // schedule a cleanup for 2 hours from now in case of failed install
+ wp_schedule_single_event( time() + 7200, 'upgrader_scheduled_cleanup', array( $this->id ) );
+
+ } elseif ( is_numeric( $_GET[$urlholder] ) ) {
+ // Numeric Package = previously uploaded file, see above.
+ $this->id = (int) $_GET[$urlholder];
+ $attachment = get_post( $this->id );
+ if ( empty($attachment) )
+ wp_die(__('Please select a file'));
+
+ $this->filename = $attachment->post_title;
+ $this->package = get_attached_file( $attachment->ID );
} else {
+ // Else, It's set to something, Back compat for plugins using the old (pre-3.3) File_Uploader handler.
+ if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
+ wp_die( $uploads['error'] );
+
+ $this->filename = $_GET[$urlholder];
$this->package = $uploads['basedir'] . '/' . $this->filename;
}
}
-}
\ No newline at end of file
+
+ function cleanup() {
+ if ( $this->id )
+ wp_delete_attachment( $this->id );
+
+ elseif ( file_exists( $this->package ) )
+ return @unlink( $this->package );
+
+ return true;
+ }
+}