2016-05-10 07:45:42 -04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-05-10 07:52:28 -04:00
|
|
|
* Upgrade API: Plugin_Upgrader class
|
2016-05-10 07:45:42 -04:00
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Upgrader
|
2016-05-10 07:52:28 -04:00
|
|
|
* @since 4.6.0
|
2016-05-10 07:45:42 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Core class used for upgrading/installing plugins.
|
|
|
|
*
|
|
|
|
* It is designed to upgrade/install plugins from a local zip, remote zip URL,
|
|
|
|
* or uploaded zip file.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
2016-05-13 16:59:27 -04:00
|
|
|
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader.php.
|
2016-05-10 07:45:42 -04:00
|
|
|
*
|
|
|
|
* @see WP_Upgrader
|
|
|
|
*/
|
|
|
|
class Plugin_Upgrader extends WP_Upgrader {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin upgrade result.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
* @var array|WP_Error $result
|
|
|
|
*
|
|
|
|
* @see WP_Upgrader::$result
|
|
|
|
*/
|
|
|
|
public $result;
|
|
|
|
|
|
|
|
/**
|
2017-08-22 07:52:48 -04:00
|
|
|
* Whether a bulk upgrade/installation is being performed.
|
2016-05-10 07:45:42 -04:00
|
|
|
*
|
|
|
|
* @since 2.9.0
|
|
|
|
* @var bool $bulk
|
|
|
|
*/
|
|
|
|
public $bulk = false;
|
|
|
|
|
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
|
|
|
/**
|
|
|
|
* New plugin info.
|
|
|
|
*
|
|
|
|
* @since 5.5.0
|
|
|
|
* @var array $new_plugin_data
|
|
|
|
*
|
|
|
|
* @see check_package()
|
|
|
|
*/
|
|
|
|
public $new_plugin_data = array();
|
|
|
|
|
2016-05-10 07:45:42 -04:00
|
|
|
/**
|
|
|
|
* Initialize the upgrade strings.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*/
|
|
|
|
public function upgrade_strings() {
|
2017-11-30 18:11:00 -05:00
|
|
|
$this->strings['up_to_date'] = __( 'The plugin is at the latest version.' );
|
|
|
|
$this->strings['no_package'] = __( 'Update package not available.' );
|
2019-09-02 20:41:05 -04:00
|
|
|
/* translators: %s: Package URL. */
|
2017-11-30 18:11:00 -05:00
|
|
|
$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.' );
|
2016-05-10 07:45:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-22 07:52:48 -04:00
|
|
|
* Initialize the installation strings.
|
2016-05-10 07:45:42 -04:00
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*/
|
|
|
|
public function install_strings() {
|
2017-11-30 18:11:00 -05:00
|
|
|
$this->strings['no_package'] = __( 'Installation package not available.' );
|
2019-09-02 20:41:05 -04:00
|
|
|
/* translators: %s: Package URL. */
|
2017-10-18 13:15:47 -04:00
|
|
|
$this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s…' ), '<span class="code">%s</span>' );
|
2017-11-30 18:11:00 -05:00
|
|
|
$this->strings['unpack_package'] = __( 'Unpacking the package…' );
|
|
|
|
$this->strings['installing_package'] = __( 'Installing the plugin…' );
|
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
|
|
|
$this->strings['remove_old'] = __( 'Removing the current plugin…' );
|
|
|
|
$this->strings['remove_old_failed'] = __( 'Could not remove the current plugin.' );
|
2017-11-30 18:11:00 -05:00
|
|
|
$this->strings['no_files'] = __( 'The plugin contains no files.' );
|
|
|
|
$this->strings['process_failed'] = __( 'Plugin installation failed.' );
|
|
|
|
$this->strings['process_success'] = __( 'Plugin installed successfully.' );
|
2020-08-04 13:54:04 -04:00
|
|
|
/* translators: 1: Plugin name, 2: Plugin version. */
|
|
|
|
$this->strings['process_success_specific'] = __( 'Successfully installed the plugin <strong>%1$s %2$s</strong>.' );
|
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
|
|
|
|
|
|
|
if ( ! empty( $this->skin->overwrite ) ) {
|
|
|
|
if ( 'update-plugin' === $this->skin->overwrite ) {
|
|
|
|
$this->strings['installing_package'] = __( 'Updating the plugin…' );
|
|
|
|
$this->strings['process_failed'] = __( 'Plugin update failed.' );
|
|
|
|
$this->strings['process_success'] = __( 'Plugin updated successfully.' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( 'downgrade-plugin' === $this->skin->overwrite ) {
|
|
|
|
$this->strings['installing_package'] = __( 'Downgrading the plugin…' );
|
|
|
|
$this->strings['process_failed'] = __( 'Plugin downgrade failed.' );
|
|
|
|
$this->strings['process_success'] = __( 'Plugin downgraded successfully.' );
|
|
|
|
}
|
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Install a plugin package.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
* @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
|
|
|
|
*
|
|
|
|
* @param string $package The full local path or URI of the package.
|
|
|
|
* @param array $args {
|
|
|
|
* Optional. Other arguments for installing a plugin package. Default empty array.
|
|
|
|
*
|
|
|
|
* @type bool $clear_update_cache Whether to clear the plugin updates cache if successful.
|
|
|
|
* Default true.
|
|
|
|
* }
|
2017-08-22 07:52:48 -04:00
|
|
|
* @return bool|WP_Error True if the installation was successful, false or a WP_Error otherwise.
|
2016-05-10 07:45:42 -04:00
|
|
|
*/
|
|
|
|
public function install( $package, $args = array() ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$defaults = array(
|
2016-05-10 07:45:42 -04:00
|
|
|
'clear_update_cache' => true,
|
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
|
|
|
'overwrite_package' => false, // Do not overwrite files.
|
2016-05-10 07:45:42 -04:00
|
|
|
);
|
|
|
|
$parsed_args = wp_parse_args( $args, $defaults );
|
|
|
|
|
|
|
|
$this->init();
|
|
|
|
$this->install_strings();
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
|
2020-07-29 09:09:04 -04:00
|
|
|
|
2016-11-13 04:53:32 -05:00
|
|
|
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 );
|
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$this->run(
|
|
|
|
array(
|
|
|
|
'package' => $package,
|
|
|
|
'destination' => WP_PLUGIN_DIR,
|
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
|
|
|
'clear_destination' => $parsed_args['overwrite_package'],
|
2017-11-30 18:11:00 -05:00
|
|
|
'clear_working' => true,
|
|
|
|
'hook_extra' => array(
|
|
|
|
'type' => 'plugin',
|
|
|
|
'action' => 'install',
|
|
|
|
),
|
2016-05-10 07:45:42 -04:00
|
|
|
)
|
2017-11-30 18:11:00 -05:00
|
|
|
);
|
2016-05-10 07:45:42 -04:00
|
|
|
|
|
|
|
remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
|
2017-11-30 18:11:00 -05:00
|
|
|
remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! $this->result || is_wp_error( $this->result ) ) {
|
2016-05-10 07:45:42 -04:00
|
|
|
return $this->result;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Force refresh of plugin update information.
|
2016-05-10 07:45:42 -04:00
|
|
|
wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
|
|
|
|
|
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
|
|
|
if ( $parsed_args['overwrite_package'] ) {
|
|
|
|
/**
|
|
|
|
* Fires when the upgrader has successfully overwritten a currently installed
|
|
|
|
* plugin or theme with an uploaded zip package.
|
|
|
|
*
|
|
|
|
* @since 5.5.0
|
|
|
|
*
|
2020-12-10 18:38:04 -05:00
|
|
|
* @param string $package The package file.
|
|
|
|
* @param array $data The new plugin or theme data.
|
|
|
|
* @param string $package_type The package type ('plugin' or 'theme').
|
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
|
|
|
*/
|
|
|
|
do_action( 'upgrader_overwrote_package', $package, $this->new_plugin_data, 'plugin' );
|
|
|
|
}
|
|
|
|
|
2016-05-10 07:45:42 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Upgrade a plugin.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
* @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
|
|
|
|
*
|
2018-03-05 16:50:31 -05:00
|
|
|
* @param string $plugin Path to the plugin file relative to the plugins directory.
|
2016-05-10 07:45:42 -04:00
|
|
|
* @param array $args {
|
|
|
|
* Optional. Other arguments for upgrading a plugin package. Default empty array.
|
|
|
|
*
|
|
|
|
* @type bool $clear_update_cache Whether to clear the plugin updates cache if successful.
|
|
|
|
* Default true.
|
|
|
|
* }
|
|
|
|
* @return bool|WP_Error True if the upgrade was successful, false or a WP_Error object otherwise.
|
|
|
|
*/
|
|
|
|
public function upgrade( $plugin, $args = array() ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$defaults = array(
|
2016-05-10 07:45:42 -04:00
|
|
|
'clear_update_cache' => true,
|
|
|
|
);
|
|
|
|
$parsed_args = wp_parse_args( $args, $defaults );
|
|
|
|
|
|
|
|
$this->init();
|
|
|
|
$this->upgrade_strings();
|
|
|
|
|
|
|
|
$current = get_site_transient( 'update_plugins' );
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! isset( $current->response[ $plugin ] ) ) {
|
2016-05-10 07:45:42 -04:00
|
|
|
$this->skin->before();
|
2017-11-30 18:11:00 -05:00
|
|
|
$this->skin->set_result( false );
|
|
|
|
$this->skin->error( 'up_to_date' );
|
2016-05-10 07:45:42 -04:00
|
|
|
$this->skin->after();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Get the URL to the zip file.
|
2016-05-10 07:45:42 -04:00
|
|
|
$r = $current->response[ $plugin ];
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
add_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ), 10, 2 );
|
2020-02-11 15:14:05 -05:00
|
|
|
add_filter( 'upgrader_pre_install', array( $this, 'active_before' ), 10, 2 );
|
2017-11-30 18:11:00 -05:00
|
|
|
add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 );
|
2020-02-11 15:14:05 -05:00
|
|
|
add_filter( 'upgrader_post_install', array( $this, 'active_after' ), 10, 2 );
|
2020-01-28 19:45:18 -05:00
|
|
|
// There's a Trac ticket to move up the directory for zips which are made a bit differently, useful for non-.org plugins.
|
|
|
|
// 'source_selection' => array( $this, 'source_selection' ),
|
2016-11-13 04:53:32 -05:00
|
|
|
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 );
|
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$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',
|
|
|
|
),
|
|
|
|
)
|
|
|
|
);
|
2016-05-10 07:45:42 -04:00
|
|
|
|
|
|
|
// Cleanup our hooks, in case something else does a upgrade on this connection.
|
|
|
|
remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
|
2017-11-30 18:11:00 -05:00
|
|
|
remove_filter( 'upgrader_pre_install', array( $this, 'deactivate_plugin_before_upgrade' ) );
|
2020-02-11 15:14:05 -05:00
|
|
|
remove_filter( 'upgrader_pre_install', array( $this, 'active_before' ) );
|
2017-11-30 18:11:00 -05:00
|
|
|
remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) );
|
2020-02-11 15:14:05 -05:00
|
|
|
remove_filter( 'upgrader_post_install', array( $this, 'active_after' ) );
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! $this->result || is_wp_error( $this->result ) ) {
|
2016-05-10 07:45:42 -04:00
|
|
|
return $this->result;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Force refresh of plugin update information.
|
2016-05-10 07:45:42 -04:00
|
|
|
wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
|
|
|
|
|
2020-07-11 21:19:03 -04:00
|
|
|
// Ensure any future auto-update failures trigger a failure email by removing
|
|
|
|
// the last failure notification from the list when plugins update successfully.
|
2020-07-07 15:00:02 -04:00
|
|
|
$past_failure_emails = get_option( 'auto_plugin_theme_update_emails', array() );
|
|
|
|
|
|
|
|
if ( isset( $past_failure_emails[ $plugin ] ) ) {
|
|
|
|
unset( $past_failure_emails[ $plugin ] );
|
|
|
|
update_option( 'auto_plugin_theme_update_emails', $past_failure_emails );
|
|
|
|
}
|
|
|
|
|
2016-05-10 07:45:42 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bulk upgrade several plugins at once.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
* @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
|
|
|
|
*
|
2018-03-05 16:50:31 -05:00
|
|
|
* @param string[] $plugins Array of paths to plugin files relative to the plugins directory.
|
|
|
|
* @param array $args {
|
|
|
|
* Optional. Other arguments for upgrading several plugins at once.
|
2016-05-10 07:45:42 -04:00
|
|
|
*
|
2018-03-05 16:50:31 -05:00
|
|
|
* @type bool $clear_update_cache Whether to clear the plugin updates cache if successful. Default true.
|
2016-05-10 07:45:42 -04:00
|
|
|
* }
|
|
|
|
* @return array|false An array of results indexed by plugin file, or false if unable to connect to the filesystem.
|
|
|
|
*/
|
|
|
|
public function bulk_upgrade( $plugins, $args = array() ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$defaults = array(
|
2016-05-10 07:45:42 -04:00
|
|
|
'clear_update_cache' => true,
|
|
|
|
);
|
|
|
|
$parsed_args = wp_parse_args( $args, $defaults );
|
|
|
|
|
|
|
|
$this->init();
|
|
|
|
$this->bulk = true;
|
|
|
|
$this->upgrade_strings();
|
|
|
|
|
|
|
|
$current = get_site_transient( 'update_plugins' );
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 );
|
2016-05-10 07:45:42 -04:00
|
|
|
|
|
|
|
$this->skin->header();
|
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Connect to the filesystem first.
|
2017-11-30 18:11:00 -05:00
|
|
|
$res = $this->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) );
|
2016-05-10 07:45:42 -04:00
|
|
|
if ( ! $res ) {
|
|
|
|
$this->skin->footer();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->skin->bulk_header();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only start maintenance mode if:
|
|
|
|
* - running Multisite and there are one or more plugins specified, OR
|
|
|
|
* - a plugin with an update available is currently active.
|
2020-01-28 19:45:18 -05:00
|
|
|
* @todo For multisite, maintenance mode should only kick in for individual sites if at all possible.
|
2016-05-10 07:45:42 -04:00
|
|
|
*/
|
|
|
|
$maintenance = ( is_multisite() && ! empty( $plugins ) );
|
2017-11-30 18:11:00 -05:00
|
|
|
foreach ( $plugins as $plugin ) {
|
|
|
|
$maintenance = $maintenance || ( is_plugin_active( $plugin ) && isset( $current->response[ $plugin ] ) );
|
|
|
|
}
|
|
|
|
if ( $maintenance ) {
|
|
|
|
$this->maintenance_mode( true );
|
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
|
|
|
$results = array();
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$this->update_count = count( $plugins );
|
2016-05-10 07:45:42 -04:00
|
|
|
$this->update_current = 0;
|
|
|
|
foreach ( $plugins as $plugin ) {
|
|
|
|
$this->update_current++;
|
2017-11-30 18:11:00 -05:00
|
|
|
$this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true );
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! isset( $current->response[ $plugin ] ) ) {
|
|
|
|
$this->skin->set_result( 'up_to_date' );
|
2016-05-10 07:45:42 -04:00
|
|
|
$this->skin->before();
|
2017-11-30 18:11:00 -05:00
|
|
|
$this->skin->feedback( 'up_to_date' );
|
2016-05-10 07:45:42 -04:00
|
|
|
$this->skin->after();
|
2017-11-30 18:11:00 -05:00
|
|
|
$results[ $plugin ] = true;
|
2016-05-10 07:45:42 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the URL to the zip file.
|
|
|
|
$r = $current->response[ $plugin ];
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$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,
|
|
|
|
),
|
2016-05-10 07:45:42 -04:00
|
|
|
)
|
2017-11-30 18:11:00 -05:00
|
|
|
);
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$results[ $plugin ] = $this->result;
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Prevent credentials auth screen from displaying multiple times.
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( false === $result ) {
|
2016-05-10 07:45:42 -04:00
|
|
|
break;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2020-01-28 19:45:18 -05:00
|
|
|
} // End foreach $plugins.
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$this->maintenance_mode( false );
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2016-11-13 04:53:32 -05:00
|
|
|
// Force refresh of plugin update information.
|
|
|
|
wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
|
|
|
|
|
2016-05-10 08:20:27 -04:00
|
|
|
/** This action is documented in wp-admin/includes/class-wp-upgrader.php */
|
2018-08-16 21:51:36 -04:00
|
|
|
do_action(
|
|
|
|
'upgrader_process_complete',
|
|
|
|
$this,
|
|
|
|
array(
|
|
|
|
'action' => 'update',
|
|
|
|
'type' => 'plugin',
|
|
|
|
'bulk' => true,
|
|
|
|
'plugins' => $plugins,
|
|
|
|
)
|
|
|
|
);
|
2016-05-10 07:45:42 -04:00
|
|
|
|
|
|
|
$this->skin->bulk_footer();
|
|
|
|
|
|
|
|
$this->skin->footer();
|
|
|
|
|
|
|
|
// Cleanup our hooks, in case something else does a upgrade on this connection.
|
2017-11-30 18:11:00 -05:00
|
|
|
remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ) );
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2020-07-11 21:19:03 -04:00
|
|
|
// Ensure any future auto-update failures trigger a failure email by removing
|
|
|
|
// the last failure notification from the list when plugins update successfully.
|
2020-07-07 15:00:02 -04:00
|
|
|
$past_failure_emails = get_option( 'auto_plugin_theme_update_emails', array() );
|
|
|
|
|
|
|
|
foreach ( $results as $plugin => $result ) {
|
|
|
|
// Maintain last failure notification when plugins failed to update manually.
|
|
|
|
if ( ! $result || is_wp_error( $result ) || ! isset( $past_failure_emails[ $plugin ] ) ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
unset( $past_failure_emails[ $plugin ] );
|
|
|
|
}
|
2020-07-11 21:16:05 -04:00
|
|
|
|
2020-07-07 15:00:02 -04:00
|
|
|
update_option( 'auto_plugin_theme_update_emails', $past_failure_emails );
|
|
|
|
|
2016-05-10 07:45:42 -04:00
|
|
|
return $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-05 09:44:11 -04:00
|
|
|
* Checks that the source package contains a valid plugin.
|
2016-05-10 07:45:42 -04:00
|
|
|
*
|
2020-10-05 09:44:11 -04:00
|
|
|
* Hooked to the {@see 'upgrader_source_selection'} filter by Plugin_Upgrader::install().
|
2016-05-10 07:45:42 -04:00
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*
|
2018-03-04 16:58:30 -05:00
|
|
|
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
|
2020-09-11 20:12:08 -04:00
|
|
|
* @global string $wp_version The WordPress version string.
|
2016-05-10 07:45:42 -04:00
|
|
|
*
|
|
|
|
* @param string $source The path to the downloaded package source.
|
2020-10-05 09:44:11 -04:00
|
|
|
* @return string|WP_Error The source as passed, or a WP_Error object on failure.
|
2016-05-10 07:45:42 -04:00
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
public function check_package( $source ) {
|
2020-09-11 20:12:08 -04:00
|
|
|
global $wp_filesystem, $wp_version;
|
2016-05-10 07:45:42 -04:00
|
|
|
|
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
|
|
|
$this->new_plugin_data = array();
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( is_wp_error( $source ) ) {
|
2016-05-10 07:45:42 -04:00
|
|
|
return $source;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$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.
|
2016-05-10 07:45:42 -04:00
|
|
|
return $source;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Check that the folder contains at least 1 valid plugin.
|
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
|
|
|
$files = glob( $working_directory . '*.php' );
|
2016-05-10 07:45:42 -04:00
|
|
|
if ( $files ) {
|
|
|
|
foreach ( $files as $file ) {
|
|
|
|
$info = get_plugin_data( $file, false, false );
|
|
|
|
if ( ! empty( $info['Name'] ) ) {
|
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
|
|
|
$this->new_plugin_data = $info;
|
2016-05-10 07:45:42 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
|
|
|
if ( empty( $this->new_plugin_data ) ) {
|
2016-05-10 07:45:42 -04:00
|
|
|
return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) );
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2020-07-28 12:07:02 -04:00
|
|
|
$requires_php = isset( $info['RequiresPHP'] ) ? $info['RequiresPHP'] : null;
|
|
|
|
$requires_wp = isset( $info['RequiresWP'] ) ? $info['RequiresWP'] : null;
|
|
|
|
|
|
|
|
if ( ! is_php_version_compatible( $requires_php ) ) {
|
|
|
|
$error = sprintf(
|
|
|
|
/* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */
|
|
|
|
__( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ),
|
|
|
|
phpversion(),
|
|
|
|
$requires_php
|
|
|
|
);
|
|
|
|
|
|
|
|
return new WP_Error( 'incompatible_php_required_version', $this->strings['incompatible_archive'], $error );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! is_wp_version_compatible( $requires_wp ) ) {
|
|
|
|
$error = sprintf(
|
|
|
|
/* translators: 1: Current WordPress version, 2: Version required by the uploaded plugin. */
|
|
|
|
__( 'Your WordPress version is %1$s, however the uploaded plugin requires %2$s.' ),
|
2020-09-11 20:12:08 -04:00
|
|
|
$wp_version,
|
2020-07-28 12:07:02 -04:00
|
|
|
$requires_wp
|
|
|
|
);
|
|
|
|
|
|
|
|
return new WP_Error( 'incompatible_wp_required_version', $this->strings['incompatible_archive'], $error );
|
|
|
|
}
|
|
|
|
|
2016-05-10 07:45:42 -04:00
|
|
|
return $source;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the path to the file that contains the plugin info.
|
|
|
|
*
|
|
|
|
* This isn't used internally in the class, but is called by the skins.
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*
|
|
|
|
* @return string|false The full path to the main plugin file, or false.
|
|
|
|
*/
|
|
|
|
public function plugin_info() {
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! is_array( $this->result ) ) {
|
2016-05-10 07:45:42 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
|
|
|
if ( empty( $this->result['destination_name'] ) ) {
|
2016-05-10 07:45:42 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Ensure to pass with leading slash.
|
|
|
|
$plugin = get_plugins( '/' . $this->result['destination_name'] );
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( empty( $plugin ) ) {
|
2016-05-10 07:45:42 -04:00
|
|
|
return false;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Assume the requested plugin is the first in the list.
|
|
|
|
$pluginfiles = array_keys( $plugin );
|
2016-05-10 07:45:42 -04:00
|
|
|
|
|
|
|
return $this->result['destination_name'] . '/' . $pluginfiles[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deactivates a plugin before it is upgraded.
|
|
|
|
*
|
|
|
|
* Hooked to the {@see 'upgrader_pre_install'} filter by Plugin_Upgrader::upgrade().
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
* @since 4.1.0 Added a return value.
|
|
|
|
*
|
2020-03-03 06:39:08 -05:00
|
|
|
* @param bool|WP_Error $return Upgrade offer return.
|
|
|
|
* @param array $plugin Plugin package arguments.
|
2016-05-10 07:45:42 -04:00
|
|
|
* @return bool|WP_Error The passed in $return param or WP_Error.
|
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
public function deactivate_plugin_before_upgrade( $return, $plugin ) {
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
if ( is_wp_error( $return ) ) { // Bypass.
|
2016-05-10 07:45:42 -04:00
|
|
|
return $return;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it.
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( wp_doing_cron() ) {
|
2016-05-10 07:45:42 -04:00
|
|
|
return $return;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
|
|
|
|
if ( empty( $plugin ) ) {
|
|
|
|
return new WP_Error( 'bad_request', $this->strings['bad_request'] );
|
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( is_plugin_active( $plugin ) ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
// Deactivate the plugin silently, Prevent deactivation hooks from running.
|
2017-11-30 18:11:00 -05:00
|
|
|
deactivate_plugins( $plugin, true );
|
2016-05-10 07:45:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2020-02-11 15:14:05 -05:00
|
|
|
/**
|
2020-03-02 19:29:06 -05:00
|
|
|
* Turns on maintenance mode before attempting to background update an active plugin.
|
2020-02-11 15:14:05 -05:00
|
|
|
*
|
|
|
|
* Hooked to the {@see 'upgrader_pre_install'} filter by Plugin_Upgrader::upgrade().
|
|
|
|
*
|
|
|
|
* @since 5.4.0
|
|
|
|
*
|
2020-03-02 19:29:06 -05:00
|
|
|
* @param bool|WP_Error $return Upgrade offer return.
|
|
|
|
* @param array $plugin Plugin package arguments.
|
|
|
|
* @return bool|WP_Error The passed in $return param or WP_Error.
|
2020-02-11 15:14:05 -05:00
|
|
|
*/
|
|
|
|
public function active_before( $return, $plugin ) {
|
|
|
|
if ( is_wp_error( $return ) ) {
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only enable maintenance mode when in cron (background update).
|
|
|
|
if ( ! wp_doing_cron() ) {
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
|
|
|
|
|
2020-03-03 06:39:08 -05:00
|
|
|
// Only run if plugin is active.
|
2020-03-02 19:29:06 -05:00
|
|
|
if ( ! is_plugin_active( $plugin ) ) {
|
2020-02-11 15:14:05 -05:00
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2020-03-02 19:29:06 -05:00
|
|
|
// Change to maintenance mode. Bulk edit handles this separately.
|
2020-02-11 15:14:05 -05:00
|
|
|
if ( ! $this->bulk ) {
|
|
|
|
$this->maintenance_mode( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-03-02 19:29:06 -05:00
|
|
|
* Turns off maintenance mode after upgrading an active plugin.
|
2020-02-11 15:14:05 -05:00
|
|
|
*
|
|
|
|
* Hooked to the {@see 'upgrader_post_install'} filter by Plugin_Upgrader::upgrade().
|
|
|
|
*
|
|
|
|
* @since 5.4.0
|
|
|
|
*
|
2020-03-03 06:39:08 -05:00
|
|
|
* @param bool|WP_Error $return Upgrade offer return.
|
|
|
|
* @param array $plugin Plugin package arguments.
|
2020-03-02 19:29:06 -05:00
|
|
|
* @return bool|WP_Error The passed in $return param or WP_Error.
|
2020-02-11 15:14:05 -05:00
|
|
|
*/
|
|
|
|
public function active_after( $return, $plugin ) {
|
|
|
|
if ( is_wp_error( $return ) ) {
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only disable maintenance mode when in cron (background update).
|
|
|
|
if ( ! wp_doing_cron() ) {
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
|
|
|
|
|
2020-03-02 19:29:06 -05:00
|
|
|
// Only run if plugin is active
|
|
|
|
if ( ! is_plugin_active( $plugin ) ) {
|
2020-02-11 15:14:05 -05:00
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2020-03-02 19:29:06 -05:00
|
|
|
// Time to remove maintenance mode. Bulk edit handles this separately.
|
2020-02-11 15:14:05 -05:00
|
|
|
if ( ! $this->bulk ) {
|
|
|
|
$this->maintenance_mode( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2016-05-10 07:45:42 -04:00
|
|
|
/**
|
2020-03-02 19:29:06 -05:00
|
|
|
* Deletes the old plugin during an upgrade.
|
2016-05-10 07:45:42 -04:00
|
|
|
*
|
|
|
|
* Hooked to the {@see 'upgrader_clear_destination'} filter by
|
|
|
|
* Plugin_Upgrader::upgrade() and Plugin_Upgrader::bulk_upgrade().
|
|
|
|
*
|
|
|
|
* @since 2.8.0
|
|
|
|
*
|
2018-03-04 16:58:30 -05:00
|
|
|
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
|
2017-11-30 18:11:00 -05:00
|
|
|
*
|
2020-03-03 06:39:08 -05:00
|
|
|
* @param bool|WP_Error $removed Whether the destination was cleared.
|
|
|
|
* True on success, WP_Error on failure.
|
2020-03-02 19:29:06 -05:00
|
|
|
* @param string $local_destination The local package destination.
|
|
|
|
* @param string $remote_destination The remote package destination.
|
|
|
|
* @param array $plugin Extra arguments passed to hooked filters.
|
2019-11-10 21:43:03 -05:00
|
|
|
* @return bool|WP_Error
|
2016-05-10 07:45:42 -04:00
|
|
|
*/
|
2017-11-30 18:11:00 -05:00
|
|
|
public function delete_old_plugin( $removed, $local_destination, $remote_destination, $plugin ) {
|
2016-05-10 07:45:42 -04:00
|
|
|
global $wp_filesystem;
|
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( is_wp_error( $removed ) ) {
|
2020-01-28 19:45:18 -05:00
|
|
|
return $removed; // Pass errors through.
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
|
|
|
|
if ( empty( $plugin ) ) {
|
|
|
|
return new WP_Error( 'bad_request', $this->strings['bad_request'] );
|
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
$plugins_dir = $wp_filesystem->wp_plugins_dir();
|
|
|
|
$this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin ) );
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
if ( ! $wp_filesystem->exists( $this_plugin_dir ) ) { // If it's already vanished.
|
2016-05-10 07:45:42 -04:00
|
|
|
return $removed;
|
2017-11-30 18:11:00 -05:00
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
|
|
|
// If plugin is in its own directory, recursively delete the directory.
|
2020-01-28 19:45:18 -05:00
|
|
|
// Base check on if plugin includes directory separator AND that it's not the root plugin folder.
|
2020-05-17 05:39:11 -04:00
|
|
|
if ( strpos( $plugin, '/' ) && $this_plugin_dir !== $plugins_dir ) {
|
2017-11-30 18:11:00 -05:00
|
|
|
$deleted = $wp_filesystem->delete( $this_plugin_dir, true );
|
|
|
|
} else {
|
|
|
|
$deleted = $wp_filesystem->delete( $plugins_dir . $plugin );
|
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
2017-11-30 18:11:00 -05:00
|
|
|
if ( ! $deleted ) {
|
|
|
|
return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );
|
|
|
|
}
|
2016-05-10 07:45:42 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|