Code is Poetry.
WordPress' code just... wasn't. This is now dealt with. Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS. Fixes #41057. Built from https://develop.svn.wordpress.org/trunk@42343 git-svn-id: http://core.svn.wordpress.org/trunk@42172 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -44,16 +44,16 @@ class Plugin_Upgrader extends WP_Upgrader {
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function upgrade_strings() {
|
||||
$this->strings['up_to_date'] = __('The plugin is at the latest version.');
|
||||
$this->strings['no_package'] = __('Update package not available.');
|
||||
$this->strings['up_to_date'] = __( 'The plugin is at the latest version.' );
|
||||
$this->strings['no_package'] = __( 'Update package not available.' );
|
||||
/* translators: %s: package URL */
|
||||
$this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '<span class="code">%s</span>' );
|
||||
$this->strings['unpack_package'] = __('Unpacking the update…');
|
||||
$this->strings['remove_old'] = __('Removing the old version of the plugin…');
|
||||
$this->strings['remove_old_failed'] = __('Could not remove the old plugin.');
|
||||
$this->strings['process_failed'] = __('Plugin update failed.');
|
||||
$this->strings['process_success'] = __('Plugin updated successfully.');
|
||||
$this->strings['process_bulk_success'] = __('Plugins updated successfully.');
|
||||
$this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '<span class="code">%s</span>' );
|
||||
$this->strings['unpack_package'] = __( 'Unpacking the update…' );
|
||||
$this->strings['remove_old'] = __( 'Removing the old version of the plugin…' );
|
||||
$this->strings['remove_old_failed'] = __( 'Could not remove the old plugin.' );
|
||||
$this->strings['process_failed'] = __( 'Plugin update failed.' );
|
||||
$this->strings['process_success'] = __( 'Plugin updated successfully.' );
|
||||
$this->strings['process_bulk_success'] = __( 'Plugins updated successfully.' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,14 +62,14 @@ class Plugin_Upgrader extends WP_Upgrader {
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function install_strings() {
|
||||
$this->strings['no_package'] = __('Installation package not available.');
|
||||
$this->strings['no_package'] = __( 'Installation package not available.' );
|
||||
/* translators: %s: package URL */
|
||||
$this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s…' ), '<span class="code">%s</span>' );
|
||||
$this->strings['unpack_package'] = __('Unpacking the package…');
|
||||
$this->strings['installing_package'] = __('Installing the plugin…');
|
||||
$this->strings['no_files'] = __('The plugin contains no files.');
|
||||
$this->strings['process_failed'] = __('Plugin installation failed.');
|
||||
$this->strings['process_success'] = __('Plugin installed successfully.');
|
||||
$this->strings['unpack_package'] = __( 'Unpacking the package…' );
|
||||
$this->strings['installing_package'] = __( 'Installing the plugin…' );
|
||||
$this->strings['no_files'] = __( 'The plugin contains no files.' );
|
||||
$this->strings['process_failed'] = __( 'Plugin installation failed.' );
|
||||
$this->strings['process_success'] = __( 'Plugin installed successfully.' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,7 +89,7 @@ class Plugin_Upgrader extends WP_Upgrader {
|
||||
*/
|
||||
public function install( $package, $args = array() ) {
|
||||
|
||||
$defaults = array(
|
||||
$defaults = array(
|
||||
'clear_update_cache' => true,
|
||||
);
|
||||
$parsed_args = wp_parse_args( $args, $defaults );
|
||||
@@ -97,28 +97,31 @@ class Plugin_Upgrader extends WP_Upgrader {
|
||||
$this->init();
|
||||
$this->install_strings();
|
||||
|
||||
add_filter('upgrader_source_selection', array($this, 'check_package') );
|
||||
add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
|
||||
if ( $parsed_args['clear_update_cache'] ) {
|
||||
// Clear cache so wp_update_plugins() knows about the new plugin.
|
||||
add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 );
|
||||
}
|
||||
|
||||
$this->run( array(
|
||||
'package' => $package,
|
||||
'destination' => WP_PLUGIN_DIR,
|
||||
'clear_destination' => false, // Do not overwrite files.
|
||||
'clear_working' => true,
|
||||
'hook_extra' => array(
|
||||
'type' => 'plugin',
|
||||
'action' => 'install',
|
||||
$this->run(
|
||||
array(
|
||||
'package' => $package,
|
||||
'destination' => WP_PLUGIN_DIR,
|
||||
'clear_destination' => false, // Do not overwrite files.
|
||||
'clear_working' => true,
|
||||
'hook_extra' => array(
|
||||
'type' => 'plugin',
|
||||
'action' => 'install',
|
||||
),
|
||||
)
|
||||
) );
|
||||
);
|
||||
|
||||
remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
|
||||
remove_filter('upgrader_source_selection', array($this, 'check_package') );
|
||||
remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
|
||||
|
||||
if ( ! $this->result || is_wp_error($this->result) )
|
||||
if ( ! $this->result || is_wp_error( $this->result ) ) {
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
// Force refresh of plugin update information
|
||||
wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
|
||||
@@ -143,7 +146,7 @@ class Plugin_Upgrader extends WP_Upgrader {
|
||||
*/
|
||||
public function upgrade( $plugin, $args = array() ) {
|
||||
|
||||
$defaults = array(
|
||||
$defaults = array(
|
||||
'clear_update_cache' => true,
|
||||
);
|
||||
$parsed_args = wp_parse_args( $args, $defaults );
|
||||
@@ -152,10 +155,10 @@ class Plugin_Upgrader extends WP_Upgrader {
|
||||
$this->upgrade_strings();
|
||||
|
||||
$current = get_site_transient( 'update_plugins' );
|
||||
if ( !isset( $current->response[ $plugin ] ) ) {
|
||||
if ( ! isset( $current->response[ $plugin ] ) ) {
|
||||
$this->skin->before();
|
||||
$this->skin->set_result(false);
|
||||
$this->skin->error('up_to_date');
|
||||
$this->skin->set_result( false );
|
||||
$this->skin->error( 'up_to_date' );
|
||||
$this->skin->after();
|
||||
return false;
|
||||
}
|
||||
@@ -163,33 +166,36 @@ class Plugin_Upgrader extends WP_Upgrader {
|
||||
// Get the URL to the zip file
|
||||
$r = $current->response[ $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);
|
||||
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'), //there's a trac ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins.
|
||||
if ( $parsed_args['clear_update_cache'] ) {
|
||||
// Clear cache so wp_update_plugins() knows about the new plugin.
|
||||
add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 );
|
||||
}
|
||||
|
||||
$this->run( array(
|
||||
'package' => $r->package,
|
||||
'destination' => WP_PLUGIN_DIR,
|
||||
'clear_destination' => true,
|
||||
'clear_working' => true,
|
||||
'hook_extra' => array(
|
||||
'plugin' => $plugin,
|
||||
'type' => 'plugin',
|
||||
'action' => 'update',
|
||||
),
|
||||
) );
|
||||
$this->run(
|
||||
array(
|
||||
'package' => $r->package,
|
||||
'destination' => WP_PLUGIN_DIR,
|
||||
'clear_destination' => true,
|
||||
'clear_working' => true,
|
||||
'hook_extra' => array(
|
||||
'plugin' => $plugin,
|
||||
'type' => 'plugin',
|
||||
'action' => 'update',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// Cleanup our hooks, in case something else does a upgrade on this connection.
|
||||
remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
|
||||
remove_filter('upgrader_pre_install', array($this, 'deactivate_plugin_before_upgrade'));
|
||||
remove_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'));
|
||||
remove_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ) );
|
||||
remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) );
|
||||
|
||||
if ( ! $this->result || is_wp_error($this->result) )
|
||||
if ( ! $this->result || is_wp_error( $this->result ) ) {
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
// Force refresh of plugin update information
|
||||
wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
|
||||
@@ -214,7 +220,7 @@ class Plugin_Upgrader extends WP_Upgrader {
|
||||
*/
|
||||
public function bulk_upgrade( $plugins, $args = array() ) {
|
||||
|
||||
$defaults = array(
|
||||
$defaults = array(
|
||||
'clear_update_cache' => true,
|
||||
);
|
||||
$parsed_args = wp_parse_args( $args, $defaults );
|
||||
@@ -225,12 +231,12 @@ class Plugin_Upgrader extends WP_Upgrader {
|
||||
|
||||
$current = get_site_transient( 'update_plugins' );
|
||||
|
||||
add_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'), 10, 4);
|
||||
add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 );
|
||||
|
||||
$this->skin->header();
|
||||
|
||||
// Connect to the Filesystem first.
|
||||
$res = $this->fs_connect( array(WP_CONTENT_DIR, WP_PLUGIN_DIR) );
|
||||
$res = $this->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) );
|
||||
if ( ! $res ) {
|
||||
$this->skin->footer();
|
||||
return false;
|
||||
@@ -245,70 +251,77 @@ class Plugin_Upgrader extends WP_Upgrader {
|
||||
* @TODO: For multisite, maintenance mode should only kick in for individual sites if at all possible.
|
||||
*/
|
||||
$maintenance = ( is_multisite() && ! empty( $plugins ) );
|
||||
foreach ( $plugins as $plugin )
|
||||
$maintenance = $maintenance || ( is_plugin_active( $plugin ) && isset( $current->response[ $plugin] ) );
|
||||
if ( $maintenance )
|
||||
$this->maintenance_mode(true);
|
||||
foreach ( $plugins as $plugin ) {
|
||||
$maintenance = $maintenance || ( is_plugin_active( $plugin ) && isset( $current->response[ $plugin ] ) );
|
||||
}
|
||||
if ( $maintenance ) {
|
||||
$this->maintenance_mode( true );
|
||||
}
|
||||
|
||||
$results = array();
|
||||
|
||||
$this->update_count = count($plugins);
|
||||
$this->update_count = count( $plugins );
|
||||
$this->update_current = 0;
|
||||
foreach ( $plugins as $plugin ) {
|
||||
$this->update_current++;
|
||||
$this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true);
|
||||
$this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true );
|
||||
|
||||
if ( !isset( $current->response[ $plugin ] ) ) {
|
||||
$this->skin->set_result('up_to_date');
|
||||
if ( ! isset( $current->response[ $plugin ] ) ) {
|
||||
$this->skin->set_result( 'up_to_date' );
|
||||
$this->skin->before();
|
||||
$this->skin->feedback('up_to_date');
|
||||
$this->skin->feedback( 'up_to_date' );
|
||||
$this->skin->after();
|
||||
$results[$plugin] = true;
|
||||
$results[ $plugin ] = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the URL to the zip file.
|
||||
$r = $current->response[ $plugin ];
|
||||
|
||||
$this->skin->plugin_active = is_plugin_active($plugin);
|
||||
$this->skin->plugin_active = is_plugin_active( $plugin );
|
||||
|
||||
$result = $this->run( array(
|
||||
'package' => $r->package,
|
||||
'destination' => WP_PLUGIN_DIR,
|
||||
'clear_destination' => true,
|
||||
'clear_working' => true,
|
||||
'is_multi' => true,
|
||||
'hook_extra' => array(
|
||||
'plugin' => $plugin
|
||||
$result = $this->run(
|
||||
array(
|
||||
'package' => $r->package,
|
||||
'destination' => WP_PLUGIN_DIR,
|
||||
'clear_destination' => true,
|
||||
'clear_working' => true,
|
||||
'is_multi' => true,
|
||||
'hook_extra' => array(
|
||||
'plugin' => $plugin,
|
||||
),
|
||||
)
|
||||
) );
|
||||
);
|
||||
|
||||
$results[$plugin] = $this->result;
|
||||
$results[ $plugin ] = $this->result;
|
||||
|
||||
// Prevent credentials auth screen from displaying multiple times
|
||||
if ( false === $result )
|
||||
if ( false === $result ) {
|
||||
break;
|
||||
}
|
||||
} //end foreach $plugins
|
||||
|
||||
$this->maintenance_mode(false);
|
||||
$this->maintenance_mode( false );
|
||||
|
||||
// Force refresh of plugin update information.
|
||||
wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
|
||||
|
||||
/** This action is documented in wp-admin/includes/class-wp-upgrader.php */
|
||||
do_action( 'upgrader_process_complete', $this, array(
|
||||
'action' => 'update',
|
||||
'type' => 'plugin',
|
||||
'bulk' => true,
|
||||
'plugins' => $plugins,
|
||||
) );
|
||||
do_action(
|
||||
'upgrader_process_complete', $this, array(
|
||||
'action' => 'update',
|
||||
'type' => 'plugin',
|
||||
'bulk' => true,
|
||||
'plugins' => $plugins,
|
||||
)
|
||||
);
|
||||
|
||||
$this->skin->bulk_footer();
|
||||
|
||||
$this->skin->footer();
|
||||
|
||||
// Cleanup our hooks, in case something else does a upgrade on this connection.
|
||||
remove_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'));
|
||||
remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) );
|
||||
|
||||
return $results;
|
||||
}
|
||||
@@ -327,19 +340,21 @@ class Plugin_Upgrader extends WP_Upgrader {
|
||||
* @return string|WP_Error The source as passed, or a WP_Error object
|
||||
* if no plugins were found.
|
||||
*/
|
||||
public function check_package($source) {
|
||||
public function check_package( $source ) {
|
||||
global $wp_filesystem;
|
||||
|
||||
if ( is_wp_error($source) )
|
||||
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, let's not prevent installation.
|
||||
$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, let's not prevent installation.
|
||||
return $source;
|
||||
}
|
||||
|
||||
// Check the folder contains at least 1 valid plugin.
|
||||
$plugins_found = false;
|
||||
$files = glob( $working_directory . '*.php' );
|
||||
$files = glob( $working_directory . '*.php' );
|
||||
if ( $files ) {
|
||||
foreach ( $files as $file ) {
|
||||
$info = get_plugin_data( $file, false, false );
|
||||
@@ -350,8 +365,9 @@ class Plugin_Upgrader extends WP_Upgrader {
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $plugins_found )
|
||||
if ( ! $plugins_found ) {
|
||||
return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) );
|
||||
}
|
||||
|
||||
return $source;
|
||||
}
|
||||
@@ -366,16 +382,19 @@ class Plugin_Upgrader extends WP_Upgrader {
|
||||
* @return string|false The full path to the main plugin file, or false.
|
||||
*/
|
||||
public function plugin_info() {
|
||||
if ( ! is_array($this->result) )
|
||||
if ( ! is_array( $this->result ) ) {
|
||||
return false;
|
||||
if ( empty($this->result['destination_name']) )
|
||||
}
|
||||
if ( empty( $this->result['destination_name'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$plugin = get_plugins('/' . $this->result['destination_name']); //Ensure to pass with leading slash
|
||||
if ( empty($plugin) )
|
||||
$plugin = get_plugins( '/' . $this->result['destination_name'] ); //Ensure to pass with leading slash
|
||||
if ( empty( $plugin ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$pluginfiles = array_keys($plugin); //Assume the requested plugin is the first in the list
|
||||
$pluginfiles = array_keys( $plugin ); //Assume the requested plugin is the first in the list
|
||||
|
||||
return $this->result['destination_name'] . '/' . $pluginfiles[0];
|
||||
}
|
||||
@@ -392,22 +411,25 @@ class Plugin_Upgrader extends WP_Upgrader {
|
||||
* @param array $plugin Plugin package arguments.
|
||||
* @return bool|WP_Error The passed in $return param or WP_Error.
|
||||
*/
|
||||
public function deactivate_plugin_before_upgrade($return, $plugin) {
|
||||
public function deactivate_plugin_before_upgrade( $return, $plugin ) {
|
||||
|
||||
if ( is_wp_error($return) ) //Bypass.
|
||||
if ( is_wp_error( $return ) ) { //Bypass.
|
||||
return $return;
|
||||
}
|
||||
|
||||
// When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it
|
||||
if ( wp_doing_cron() )
|
||||
if ( wp_doing_cron() ) {
|
||||
return $return;
|
||||
}
|
||||
|
||||
$plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
|
||||
if ( empty($plugin) )
|
||||
return new WP_Error('bad_request', $this->strings['bad_request']);
|
||||
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
|
||||
if ( empty( $plugin ) ) {
|
||||
return new WP_Error( 'bad_request', $this->strings['bad_request'] );
|
||||
}
|
||||
|
||||
if ( is_plugin_active($plugin) ) {
|
||||
if ( is_plugin_active( $plugin ) ) {
|
||||
//Deactivate the plugin silently, Prevent deactivation hooks from running.
|
||||
deactivate_plugins($plugin, true);
|
||||
deactivate_plugins( $plugin, true );
|
||||
}
|
||||
|
||||
return $return;
|
||||
@@ -422,37 +444,42 @@ class Plugin_Upgrader extends WP_Upgrader {
|
||||
* @since 2.8.0
|
||||
*
|
||||
* @global WP_Filesystem_Base $wp_filesystem Subclass
|
||||
*
|
||||
*
|
||||
* @param bool|WP_Error $removed
|
||||
* @param string $local_destination
|
||||
* @param string $remote_destination
|
||||
* @param array $plugin
|
||||
* @return WP_Error|bool
|
||||
*/
|
||||
public function delete_old_plugin($removed, $local_destination, $remote_destination, $plugin) {
|
||||
public function delete_old_plugin( $removed, $local_destination, $remote_destination, $plugin ) {
|
||||
global $wp_filesystem;
|
||||
|
||||
if ( is_wp_error($removed) )
|
||||
if ( is_wp_error( $removed ) ) {
|
||||
return $removed; //Pass errors through.
|
||||
}
|
||||
|
||||
$plugin = isset($plugin['plugin']) ? $plugin['plugin'] : '';
|
||||
if ( empty($plugin) )
|
||||
return new WP_Error('bad_request', $this->strings['bad_request']);
|
||||
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
|
||||
if ( empty( $plugin ) ) {
|
||||
return new WP_Error( 'bad_request', $this->strings['bad_request'] );
|
||||
}
|
||||
|
||||
$plugins_dir = $wp_filesystem->wp_plugins_dir();
|
||||
$this_plugin_dir = trailingslashit( dirname($plugins_dir . $plugin) );
|
||||
$plugins_dir = $wp_filesystem->wp_plugins_dir();
|
||||
$this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin ) );
|
||||
|
||||
if ( ! $wp_filesystem->exists($this_plugin_dir) ) //If it's already vanished.
|
||||
if ( ! $wp_filesystem->exists( $this_plugin_dir ) ) { //If it's already vanished.
|
||||
return $removed;
|
||||
}
|
||||
|
||||
// If plugin is in its own directory, recursively delete the directory.
|
||||
if ( strpos($plugin, '/') && $this_plugin_dir != $plugins_dir ) //base check on if plugin includes directory separator AND that it's not the root plugin folder
|
||||
$deleted = $wp_filesystem->delete($this_plugin_dir, true);
|
||||
else
|
||||
$deleted = $wp_filesystem->delete($plugins_dir . $plugin);
|
||||
if ( strpos( $plugin, '/' ) && $this_plugin_dir != $plugins_dir ) { //base check on if plugin includes directory separator AND that it's not the root plugin folder
|
||||
$deleted = $wp_filesystem->delete( $this_plugin_dir, true );
|
||||
} else {
|
||||
$deleted = $wp_filesystem->delete( $plugins_dir . $plugin );
|
||||
}
|
||||
|
||||
if ( ! $deleted )
|
||||
return new WP_Error('remove_old_failed', $this->strings['remove_old_failed']);
|
||||
if ( ! $deleted ) {
|
||||
return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user