Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/wpforms-.../src/Helpers
File: PluginSilentUpgrader.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPForms\Helpers;
[2] Fix | Delete
[3] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[4] Fix | Delete
exit;
[5] Fix | Delete
}
[6] Fix | Delete
[7] Fix | Delete
use WP_Error;
[8] Fix | Delete
use WP_Upgrader;
[9] Fix | Delete
use WP_Filesystem_Base;
[10] Fix | Delete
[11] Fix | Delete
/** \WP_Upgrader class */
[12] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
[13] Fix | Delete
[14] Fix | Delete
/** \Plugin_Upgrader class */
[15] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php';
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* In WP 5.3 a PHP 5.6 splat operator (...$args) was added to \WP_Upgrader_Skin::feedback().
[19] Fix | Delete
* We need to remove all calls to *Skin::feedback() method, as we can't override it in own Skins
[20] Fix | Delete
* without breaking support for PHP 5.3-5.5.
[21] Fix | Delete
*
[22] Fix | Delete
* @internal Please do not use this class outside of core WPForms development. May be removed at any time.
[23] Fix | Delete
*
[24] Fix | Delete
* @since 1.5.6.1
[25] Fix | Delete
*/
[26] Fix | Delete
class PluginSilentUpgrader extends \Plugin_Upgrader {
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Run an upgrade/installation.
[30] Fix | Delete
*
[31] Fix | Delete
* Attempt to download the package (if it is not a local file), unpack it, and
[32] Fix | Delete
* install it in the destination folder.
[33] Fix | Delete
*
[34] Fix | Delete
* @since 1.5.6.1
[35] Fix | Delete
*
[36] Fix | Delete
* @param array $options {
[37] Fix | Delete
* Array or string of arguments for upgrading/installing a package.
[38] Fix | Delete
*
[39] Fix | Delete
* @type string $package The full path or URI of the package to install.
[40] Fix | Delete
* Default empty.
[41] Fix | Delete
* @type string $destination The full path to the destination folder.
[42] Fix | Delete
* Default empty.
[43] Fix | Delete
* @type bool $clear_destination Whether to delete any files already in the
[44] Fix | Delete
* destination folder. Default false.
[45] Fix | Delete
* @type bool $clear_working Whether to delete the files form the working
[46] Fix | Delete
* directory after copying to the destination.
[47] Fix | Delete
* Default false.
[48] Fix | Delete
* @type bool $abort_if_destination_exists Whether to abort the installation if the destination
[49] Fix | Delete
* folder already exists. When true, `$clear_destination`
[50] Fix | Delete
* should be false. Default true.
[51] Fix | Delete
* @type bool $is_multi Whether this run is one of multiple upgrade/installation
[52] Fix | Delete
* actions being performed in bulk. When true, the skin
[53] Fix | Delete
* WP_Upgrader::header() and WP_Upgrader::footer()
[54] Fix | Delete
* aren't called. Default false.
[55] Fix | Delete
* @type array $hook_extra Extra arguments to pass to the filter hooks called by
[56] Fix | Delete
* WP_Upgrader::run().
[57] Fix | Delete
* }
[58] Fix | Delete
* @return array|false|WP_error The result from self::install_package() on success, otherwise a WP_Error,
[59] Fix | Delete
* or false if unable to connect to the filesystem.
[60] Fix | Delete
*/
[61] Fix | Delete
public function run( $options ) {
[62] Fix | Delete
[63] Fix | Delete
$defaults = [
[64] Fix | Delete
'package' => '', // Please always pass this.
[65] Fix | Delete
'destination' => '', // And this
[66] Fix | Delete
'clear_destination' => false,
[67] Fix | Delete
'abort_if_destination_exists' => true, // Abort if the Destination directory exists, Pass clear_destination as false please
[68] Fix | Delete
'clear_working' => true,
[69] Fix | Delete
'is_multi' => false,
[70] Fix | Delete
'hook_extra' => [], // Pass any extra $hook_extra args here, this will be passed to any hooked filters.
[71] Fix | Delete
];
[72] Fix | Delete
[73] Fix | Delete
$options = wp_parse_args( $options, $defaults );
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Filter the package options before running an update.
[77] Fix | Delete
*
[78] Fix | Delete
* See also {@see 'upgrader_process_complete'}.
[79] Fix | Delete
*
[80] Fix | Delete
* @since 4.3.0
[81] Fix | Delete
*
[82] Fix | Delete
* @param array $options {
[83] Fix | Delete
* Options used by the upgrader.
[84] Fix | Delete
*
[85] Fix | Delete
* @type string $package Package for update.
[86] Fix | Delete
* @type string $destination Update location.
[87] Fix | Delete
* @type bool $clear_destination Clear the destination resource.
[88] Fix | Delete
* @type bool $clear_working Clear the working resource.
[89] Fix | Delete
* @type bool $abort_if_destination_exists Abort if the Destination directory exists.
[90] Fix | Delete
* @type bool $is_multi Whether the upgrader is running multiple times.
[91] Fix | Delete
* @type array $hook_extra {
[92] Fix | Delete
* Extra hook arguments.
[93] Fix | Delete
*
[94] Fix | Delete
* @type string $action Type of action. Default 'update'.
[95] Fix | Delete
* @type string $type Type of update process. Accepts 'plugin', 'theme', or 'core'.
[96] Fix | Delete
* @type bool $bulk Whether the update process is a bulk update. Default true.
[97] Fix | Delete
* @type string $plugin Path to the plugin file relative to the plugins directory.
[98] Fix | Delete
* @type string $theme The stylesheet or template name of the theme.
[99] Fix | Delete
* @type string $language_update_type The language pack update type. Accepts 'plugin', 'theme',
[100] Fix | Delete
* or 'core'.
[101] Fix | Delete
* @type object $language_update The language pack update offer.
[102] Fix | Delete
* }
[103] Fix | Delete
* }
[104] Fix | Delete
*/
[105] Fix | Delete
$options = apply_filters( 'upgrader_package_options', $options );
[106] Fix | Delete
[107] Fix | Delete
if ( ! $options['is_multi'] ) { // call $this->header separately if running multiple times
[108] Fix | Delete
$this->skin->header();
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
// Connect to the Filesystem first.
[112] Fix | Delete
$res = $this->fs_connect( [ WP_CONTENT_DIR, $options['destination'] ] );
[113] Fix | Delete
// Mainly for non-connected filesystem.
[114] Fix | Delete
if ( ! $res ) {
[115] Fix | Delete
if ( ! $options['is_multi'] ) {
[116] Fix | Delete
$this->skin->footer();
[117] Fix | Delete
}
[118] Fix | Delete
return false;
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
$this->skin->before();
[122] Fix | Delete
[123] Fix | Delete
if ( is_wp_error( $res ) ) {
[124] Fix | Delete
$this->skin->error( $res );
[125] Fix | Delete
$this->skin->after();
[126] Fix | Delete
if ( ! $options['is_multi'] ) {
[127] Fix | Delete
$this->skin->footer();
[128] Fix | Delete
}
[129] Fix | Delete
return $res;
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
/*
[133] Fix | Delete
* Download the package (Note, This just returns the filename
[134] Fix | Delete
* of the file if the package is a local file)
[135] Fix | Delete
*/
[136] Fix | Delete
$download = $this->download_package( $options['package'], true );
[137] Fix | Delete
[138] Fix | Delete
// Allow for signature soft-fail.
[139] Fix | Delete
// WARNING: This may be removed in the future.
[140] Fix | Delete
if ( is_wp_error( $download ) && $download->get_error_data( 'softfail-filename' ) ) {
[141] Fix | Delete
[142] Fix | Delete
// Don't output the 'no signature could be found' failure message for now.
[143] Fix | Delete
if ( (string) $download->get_error_code() !== 'signature_verification_no_signature' || WP_DEBUG ) {
[144] Fix | Delete
// Outout the failure error as a normal feedback, and not as an error:
[145] Fix | Delete
//$this->skin->feedback( $download->get_error_message() );
[146] Fix | Delete
[147] Fix | Delete
// Report this failure back to WordPress.org for debugging purposes.
[148] Fix | Delete
wp_version_check(
[149] Fix | Delete
[
[150] Fix | Delete
'signature_failure_code' => $download->get_error_code(),
[151] Fix | Delete
'signature_failure_data' => $download->get_error_data(),
[152] Fix | Delete
]
[153] Fix | Delete
);
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
// Pretend this error didn't happen.
[157] Fix | Delete
$download = $download->get_error_data( 'softfail-filename' );
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
if ( is_wp_error( $download ) ) {
[161] Fix | Delete
$this->skin->error( $download );
[162] Fix | Delete
$this->skin->after();
[163] Fix | Delete
if ( ! $options['is_multi'] ) {
[164] Fix | Delete
$this->skin->footer();
[165] Fix | Delete
}
[166] Fix | Delete
return $download;
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
$delete_package = ( (string) $download !== (string) $options['package'] ); // Do not delete a "local" file.
[170] Fix | Delete
[171] Fix | Delete
// Unzips the file into a temporary directory.
[172] Fix | Delete
$working_dir = $this->unpack_package( $download, $delete_package );
[173] Fix | Delete
if ( is_wp_error( $working_dir ) ) {
[174] Fix | Delete
$this->skin->error( $working_dir );
[175] Fix | Delete
$this->skin->after();
[176] Fix | Delete
if ( ! $options['is_multi'] ) {
[177] Fix | Delete
$this->skin->footer();
[178] Fix | Delete
}
[179] Fix | Delete
return $working_dir;
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
// With the given options, this installs it to the destination directory.
[183] Fix | Delete
$result = $this->install_package(
[184] Fix | Delete
[
[185] Fix | Delete
'source' => $working_dir,
[186] Fix | Delete
'destination' => $options['destination'],
[187] Fix | Delete
'clear_destination' => $options['clear_destination'],
[188] Fix | Delete
'abort_if_destination_exists' => $options['abort_if_destination_exists'],
[189] Fix | Delete
'clear_working' => $options['clear_working'],
[190] Fix | Delete
'hook_extra' => $options['hook_extra'],
[191] Fix | Delete
]
[192] Fix | Delete
);
[193] Fix | Delete
[194] Fix | Delete
$this->skin->set_result( $result );
[195] Fix | Delete
if ( is_wp_error( $result ) ) {
[196] Fix | Delete
$this->skin->error( $result );
[197] Fix | Delete
//$this->skin->feedback( 'process_failed' );
[198] Fix | Delete
} else {
[199] Fix | Delete
// Installation succeeded.
[200] Fix | Delete
//$this->skin->feedback( 'process_success' );
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
$this->skin->after();
[204] Fix | Delete
[205] Fix | Delete
if ( ! $options['is_multi'] ) {
[206] Fix | Delete
[207] Fix | Delete
/**
[208] Fix | Delete
* Fire when the upgrader process is complete.
[209] Fix | Delete
*
[210] Fix | Delete
* See also {@see 'upgrader_package_options'}.
[211] Fix | Delete
*
[212] Fix | Delete
* @since 3.6.0
[213] Fix | Delete
* @since 3.7.0 Added to WP_Upgrader::run().
[214] Fix | Delete
* @since 4.6.0 `$translations` was added as a possible argument to `$hook_extra`.
[215] Fix | Delete
*
[216] Fix | Delete
* @param WP_Upgrader $this WP_Upgrader instance. In other contexts, $this, might be a
[217] Fix | Delete
* Theme_Upgrader, Plugin_Upgrader, Core_Upgrade, or
[218] Fix | Delete
* Language_Pack_Upgrader instance.
[219] Fix | Delete
* @param array $hook_extra {
[220] Fix | Delete
* Array of bulk item update data.
[221] Fix | Delete
*
[222] Fix | Delete
* @type string $action Type of action. Default 'update'.
[223] Fix | Delete
* @type string $type Type of update process. Accepts 'plugin', 'theme', 'translation', or 'core'.
[224] Fix | Delete
* @type bool $bulk Whether the update process is a bulk update. Default true.
[225] Fix | Delete
* @type array $plugins Array of the basename paths of the plugins' main files.
[226] Fix | Delete
* @type array $themes The theme slugs.
[227] Fix | Delete
* @type array $translations {
[228] Fix | Delete
* Array of translations update data.
[229] Fix | Delete
*
[230] Fix | Delete
* @type string $language The locale the translation is for.
[231] Fix | Delete
* @type string $type Type of translation. Accepts 'plugin', 'theme', or 'core'.
[232] Fix | Delete
* @type string $slug Text domain the translation is for. The slug of a theme/plugin or
[233] Fix | Delete
* 'default' for core translations.
[234] Fix | Delete
* @type string $version The version of a theme, plugin, or core.
[235] Fix | Delete
* }
[236] Fix | Delete
* }
[237] Fix | Delete
*/
[238] Fix | Delete
do_action( 'upgrader_process_complete', $this, $options['hook_extra'] );
[239] Fix | Delete
[240] Fix | Delete
$this->skin->footer();
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
return $result;
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
/**
[247] Fix | Delete
* Toggle maintenance mode for the site.
[248] Fix | Delete
*
[249] Fix | Delete
* Create/delete the maintenance file to enable/disable maintenance mode.
[250] Fix | Delete
*
[251] Fix | Delete
* @since 2.8.0
[252] Fix | Delete
*
[253] Fix | Delete
* @global WP_Filesystem_Base $wp_filesystem Subclass
[254] Fix | Delete
*
[255] Fix | Delete
* @param bool $enable True to enable maintenance mode, false to disable.
[256] Fix | Delete
*/
[257] Fix | Delete
public function maintenance_mode( $enable = false ) {
[258] Fix | Delete
global $wp_filesystem;
[259] Fix | Delete
$file = $wp_filesystem->abspath() . '.maintenance';
[260] Fix | Delete
if ( $enable ) {
[261] Fix | Delete
//$this->skin->feedback( 'maintenance_start' );
[262] Fix | Delete
// Create maintenance file to signal that we are upgrading
[263] Fix | Delete
$maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
[264] Fix | Delete
$wp_filesystem->delete( $file );
[265] Fix | Delete
$wp_filesystem->put_contents( $file, $maintenance_string, FS_CHMOD_FILE );
[266] Fix | Delete
} elseif ( ! $enable && $wp_filesystem->exists( $file ) ) {
[267] Fix | Delete
//$this->skin->feedback( 'maintenance_end' );
[268] Fix | Delete
$wp_filesystem->delete( $file );
[269] Fix | Delete
}
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
/**
[273] Fix | Delete
* Download a package.
[274] Fix | Delete
*
[275] Fix | Delete
* @since 2.8.0
[276] Fix | Delete
* @since 5.5.0 Added the `$hook_extra` parameter.
[277] Fix | Delete
*
[278] Fix | Delete
* @param string $package The URI of the package. If this is the full path to an
[279] Fix | Delete
* existing local file, it will be returned untouched.
[280] Fix | Delete
* @param bool $check_signatures Whether to validate file signatures. Default false.
[281] Fix | Delete
* @param array $hook_extra Extra arguments to pass to the filter hooks. Default empty array.
[282] Fix | Delete
* @return string|WP_Error The full path to the downloaded package file, or a WP_Error object.
[283] Fix | Delete
*/
[284] Fix | Delete
public function download_package( $package, $check_signatures = false, $hook_extra = [] ) {
[285] Fix | Delete
[286] Fix | Delete
/**
[287] Fix | Delete
* Filters whether to return the package.
[288] Fix | Delete
*
[289] Fix | Delete
* @since 3.7.0
[290] Fix | Delete
* @since 5.5.0 Added the `$hook_extra` parameter.
[291] Fix | Delete
*
[292] Fix | Delete
* @param bool $reply Whether to bail without returning the package.
[293] Fix | Delete
* Default false.
[294] Fix | Delete
* @param string $package The package file name.
[295] Fix | Delete
* @param WP_Upgrader $this The WP_Upgrader instance.
[296] Fix | Delete
* @param array $hook_extra Extra arguments passed to hooked filters.
[297] Fix | Delete
*/
[298] Fix | Delete
$reply = apply_filters( 'upgrader_pre_download', false, $package, $this, $hook_extra );
[299] Fix | Delete
if ( false !== $reply ) {
[300] Fix | Delete
return $reply;
[301] Fix | Delete
}
[302] Fix | Delete
[303] Fix | Delete
if ( ! preg_match( '!^(http|https|ftp)://!i', $package ) && file_exists( $package ) ) { // Local file or remote?
[304] Fix | Delete
return $package; // Must be a local file.
[305] Fix | Delete
}
[306] Fix | Delete
[307] Fix | Delete
if ( empty( $package ) ) {
[308] Fix | Delete
return new WP_Error( 'no_package', $this->strings['no_package'] );
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
//$this->skin->feedback( 'downloading_package', $package );
[312] Fix | Delete
[313] Fix | Delete
$download_file = download_url( $package, 300, $check_signatures );
[314] Fix | Delete
[315] Fix | Delete
if ( is_wp_error( $download_file ) && ! $download_file->get_error_data( 'softfail-filename' ) ) {
[316] Fix | Delete
return new WP_Error( 'download_failed', $this->strings['download_failed'], $download_file->get_error_message() );
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
return $download_file;
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
/**
[323] Fix | Delete
* Unpack a compressed package file.
[324] Fix | Delete
*
[325] Fix | Delete
* @since 2.8.0
[326] Fix | Delete
*
[327] Fix | Delete
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
[328] Fix | Delete
*
[329] Fix | Delete
* @param string $package Full path to the package file.
[330] Fix | Delete
* @param bool $delete_package Optional. Whether to delete the package file after attempting
[331] Fix | Delete
* to unpack it. Default true.
[332] Fix | Delete
* @return string|WP_Error The path to the unpacked contents, or a WP_Error on failure.
[333] Fix | Delete
*/
[334] Fix | Delete
public function unpack_package( $package, $delete_package = true ) {
[335] Fix | Delete
global $wp_filesystem;
[336] Fix | Delete
[337] Fix | Delete
//$this->skin->feedback( 'unpack_package' );
[338] Fix | Delete
[339] Fix | Delete
$upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
[340] Fix | Delete
[341] Fix | Delete
//Clean up contents of upgrade directory beforehand.
[342] Fix | Delete
$upgrade_files = $wp_filesystem->dirlist( $upgrade_folder );
[343] Fix | Delete
if ( ! empty( $upgrade_files ) ) {
[344] Fix | Delete
foreach ( $upgrade_files as $file ) {
[345] Fix | Delete
$wp_filesystem->delete( $upgrade_folder . $file['name'], true );
[346] Fix | Delete
}
[347] Fix | Delete
}
[348] Fix | Delete
[349] Fix | Delete
// We need a working directory - Strip off any .tmp or .zip suffixes
[350] Fix | Delete
$working_dir = $upgrade_folder . basename( basename( $package, '.tmp' ), '.zip' );
[351] Fix | Delete
[352] Fix | Delete
// Clean up working directory
[353] Fix | Delete
if ( $wp_filesystem->is_dir( $working_dir ) ) {
[354] Fix | Delete
$wp_filesystem->delete( $working_dir, true );
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
// Unzip package to working directory
[358] Fix | Delete
$result = unzip_file( $package, $working_dir );
[359] Fix | Delete
[360] Fix | Delete
// Once extracted, delete the package if required.
[361] Fix | Delete
if ( $delete_package ) {
[362] Fix | Delete
// phpcs:ignore WordPress.WP.AlternativeFunctions.unlink_unlink
[363] Fix | Delete
unlink( $package );
[364] Fix | Delete
}
[365] Fix | Delete
[366] Fix | Delete
if ( is_wp_error( $result ) ) {
[367] Fix | Delete
$wp_filesystem->delete( $working_dir, true );
[368] Fix | Delete
if ( $result->get_error_code() === 'incompatible_archive' ) {
[369] Fix | Delete
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data() );
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
return $result;
[373] Fix | Delete
}
[374] Fix | Delete
[375] Fix | Delete
return $working_dir;
[376] Fix | Delete
}
[377] Fix | Delete
[378] Fix | Delete
/**
[379] Fix | Delete
* Install a package.
[380] Fix | Delete
*
[381] Fix | Delete
* Copies the contents of a package form a source directory, and installs them in
[382] Fix | Delete
* a destination directory. Optionally removes the source. It can also optionally
[383] Fix | Delete
* clear out the destination folder if it already exists.
[384] Fix | Delete
*
[385] Fix | Delete
* @since 2.8.0
[386] Fix | Delete
*
[387] Fix | Delete
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
[388] Fix | Delete
* @global array $wp_theme_directories
[389] Fix | Delete
*
[390] Fix | Delete
* @param array|string $args {
[391] Fix | Delete
* Optional. Array or string of arguments for installing a package. Default empty array.
[392] Fix | Delete
*
[393] Fix | Delete
* @type string $source Required path to the package source. Default empty.
[394] Fix | Delete
* @type string $destination Required path to a folder to install the package in.
[395] Fix | Delete
* Default empty.
[396] Fix | Delete
* @type bool $clear_destination Whether to delete any files already in the destination
[397] Fix | Delete
* folder. Default false.
[398] Fix | Delete
* @type bool $clear_working Whether to delete the files form the working directory
[399] Fix | Delete
* after copying to the destination. Default false.
[400] Fix | Delete
* @type bool $abort_if_destination_exists Whether to abort the installation if
[401] Fix | Delete
* the destination folder already exists. Default true.
[402] Fix | Delete
* @type array $hook_extra Extra arguments to pass to the filter hooks called by
[403] Fix | Delete
* WP_Upgrader::install_package(). Default empty array.
[404] Fix | Delete
* }
[405] Fix | Delete
*
[406] Fix | Delete
* @return array|WP_Error The result (also stored in `WP_Upgrader::$result`), or a WP_Error on failure.
[407] Fix | Delete
*/
[408] Fix | Delete
public function install_package( $args = [] ) {
[409] Fix | Delete
[410] Fix | Delete
global $wp_filesystem, $wp_theme_directories;
[411] Fix | Delete
[412] Fix | Delete
$defaults = [
[413] Fix | Delete
'source' => '', // Please always pass this
[414] Fix | Delete
'destination' => '', // and this
[415] Fix | Delete
'clear_destination' => false,
[416] Fix | Delete
'clear_working' => false,
[417] Fix | Delete
'abort_if_destination_exists' => true,
[418] Fix | Delete
'hook_extra' => [],
[419] Fix | Delete
];
[420] Fix | Delete
[421] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[422] Fix | Delete
[423] Fix | Delete
// These were previously extract()'d.
[424] Fix | Delete
$source = $args['source'];
[425] Fix | Delete
$destination = $args['destination'];
[426] Fix | Delete
$clear_destination = $args['clear_destination'];
[427] Fix | Delete
[428] Fix | Delete
wpforms_set_time_limit( 300 );
[429] Fix | Delete
[430] Fix | Delete
if ( empty( $source ) || empty( $destination ) ) {
[431] Fix | Delete
return new WP_Error( 'bad_request', $this->strings['bad_request'] );
[432] Fix | Delete
}
[433] Fix | Delete
//$this->skin->feedback( 'installing_package' );
[434] Fix | Delete
[435] Fix | Delete
/**
[436] Fix | Delete
* Filter the install response before the installation has started.
[437] Fix | Delete
*
[438] Fix | Delete
* Returning a truthy value, or one that could be evaluated as a WP_Error
[439] Fix | Delete
* will effectively short-circuit the installation, returning that value
[440] Fix | Delete
* instead.
[441] Fix | Delete
*
[442] Fix | Delete
* @since 2.8.0
[443] Fix | Delete
*
[444] Fix | Delete
* @param bool|WP_Error $response Response.
[445] Fix | Delete
* @param array $hook_extra Extra arguments passed to hooked filters.
[446] Fix | Delete
*/
[447] Fix | Delete
$res = apply_filters( 'upgrader_pre_install', true, $args['hook_extra'] );
[448] Fix | Delete
[449] Fix | Delete
if ( is_wp_error( $res ) ) {
[450] Fix | Delete
return $res;
[451] Fix | Delete
}
[452] Fix | Delete
[453] Fix | Delete
// Retain the Original source and destinations.
[454] Fix | Delete
$remote_source = $args['source'];
[455] Fix | Delete
$local_destination = $destination;
[456] Fix | Delete
[457] Fix | Delete
$source_files = array_keys( $wp_filesystem->dirlist( $remote_source ) );
[458] Fix | Delete
$remote_destination = $wp_filesystem->find_folder( $local_destination );
[459] Fix | Delete
$count_source_files = count( $source_files );
[460] Fix | Delete
[461] Fix | Delete
// Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
[462] Fix | Delete
if ( $count_source_files === 1 && $wp_filesystem->is_dir( trailingslashit( $args['source'] ) . $source_files[0] . '/' ) ) { // Only one folder? Then we want its contents.
[463] Fix | Delete
$source = trailingslashit( $args['source'] ) . trailingslashit( $source_files[0] );
[464] Fix | Delete
} elseif ( $count_source_files === 0 ) {
[465] Fix | Delete
return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] ); // There are no files?
[466] Fix | Delete
} else { // It's only a single file, the upgrader will use the folder name of this file as the destination folder. Folder name is based on zip filename.
[467] Fix | Delete
$source = trailingslashit( $args['source'] );
[468] Fix | Delete
}
[469] Fix | Delete
[470] Fix | Delete
/**
[471] Fix | Delete
* Filter the source file location for the upgrade package.
[472] Fix | Delete
*
[473] Fix | Delete
* @since 2.8.0
[474] Fix | Delete
* @since 4.4.0 The $hook_extra parameter became available.
[475] Fix | Delete
*
[476] Fix | Delete
* @param string $source File source location.
[477] Fix | Delete
* @param string $remote_source Remote file source location.
[478] Fix | Delete
* @param WP_Upgrader $this WP_Upgrader instance.
[479] Fix | Delete
* @param array $hook_extra Extra arguments passed to hooked filters.
[480] Fix | Delete
*/
[481] Fix | Delete
$source = apply_filters( 'upgrader_source_selection', $source, $remote_source, $this, $args['hook_extra'] );
[482] Fix | Delete
[483] Fix | Delete
if ( is_wp_error( $source ) ) {
[484] Fix | Delete
return $source;
[485] Fix | Delete
}
[486] Fix | Delete
[487] Fix | Delete
// Has the source location changed? If so, we need a new source_files list.
[488] Fix | Delete
if ( $source !== $remote_source ) {
[489] Fix | Delete
$source_files = array_keys( $wp_filesystem->dirlist( $source ) );
[490] Fix | Delete
}
[491] Fix | Delete
[492] Fix | Delete
/*
[493] Fix | Delete
* Protection against deleting files in any important base directories.
[494] Fix | Delete
* Theme_Upgrader & Plugin_Upgrader also trigger this, as they pass the
[495] Fix | Delete
* destination directory (WP_PLUGIN_DIR / wp-content/themes) intending
[496] Fix | Delete
* to copy the directory into the directory, whilst they pass the source
[497] Fix | Delete
* as the actual files to copy.
[498] Fix | Delete
*/
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function