Edit File by line
/home/zeestwma/redstone.../wp-admin/includes
File: class-wp-upgrader.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Upgrade API: WP_Upgrader class
[2] Fix | Delete
*
[3] Fix | Delete
* Requires skin classes and WP_Upgrader subclasses for backward compatibility.
[4] Fix | Delete
*
[5] Fix | Delete
* @package WordPress
[6] Fix | Delete
* @subpackage Upgrader
[7] Fix | Delete
* @since 2.8.0
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
/** WP_Upgrader_Skin class */
[11] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader-skin.php';
[12] Fix | Delete
[13] Fix | Delete
/** Plugin_Upgrader_Skin class */
[14] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader-skin.php';
[15] Fix | Delete
[16] Fix | Delete
/** Theme_Upgrader_Skin class */
[17] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/class-theme-upgrader-skin.php';
[18] Fix | Delete
[19] Fix | Delete
/** Bulk_Upgrader_Skin class */
[20] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/class-bulk-upgrader-skin.php';
[21] Fix | Delete
[22] Fix | Delete
/** Bulk_Plugin_Upgrader_Skin class */
[23] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/class-bulk-plugin-upgrader-skin.php';
[24] Fix | Delete
[25] Fix | Delete
/** Bulk_Theme_Upgrader_Skin class */
[26] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/class-bulk-theme-upgrader-skin.php';
[27] Fix | Delete
[28] Fix | Delete
/** Plugin_Installer_Skin class */
[29] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/class-plugin-installer-skin.php';
[30] Fix | Delete
[31] Fix | Delete
/** Theme_Installer_Skin class */
[32] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/class-theme-installer-skin.php';
[33] Fix | Delete
[34] Fix | Delete
/** Language_Pack_Upgrader_Skin class */
[35] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/class-language-pack-upgrader-skin.php';
[36] Fix | Delete
[37] Fix | Delete
/** Automatic_Upgrader_Skin class */
[38] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/class-automatic-upgrader-skin.php';
[39] Fix | Delete
[40] Fix | Delete
/** WP_Ajax_Upgrader_Skin class */
[41] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php';
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Core class used for upgrading/installing a local set of files via
[45] Fix | Delete
* the Filesystem Abstraction classes from a Zip file.
[46] Fix | Delete
*
[47] Fix | Delete
* @since 2.8.0
[48] Fix | Delete
*/
[49] Fix | Delete
#[AllowDynamicProperties]
[50] Fix | Delete
class WP_Upgrader {
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* The error/notification strings used to update the user on the progress.
[54] Fix | Delete
*
[55] Fix | Delete
* @since 2.8.0
[56] Fix | Delete
* @var array $strings
[57] Fix | Delete
*/
[58] Fix | Delete
public $strings = array();
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* The upgrader skin being used.
[62] Fix | Delete
*
[63] Fix | Delete
* @since 2.8.0
[64] Fix | Delete
* @var Automatic_Upgrader_Skin|WP_Upgrader_Skin $skin
[65] Fix | Delete
*/
[66] Fix | Delete
public $skin = null;
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* The result of the installation.
[70] Fix | Delete
*
[71] Fix | Delete
* This is set by WP_Upgrader::install_package(), only when the package is installed
[72] Fix | Delete
* successfully. It will then be an array, unless a WP_Error is returned by the
[73] Fix | Delete
* {@see 'upgrader_post_install'} filter. In that case, the WP_Error will be assigned to
[74] Fix | Delete
* it.
[75] Fix | Delete
*
[76] Fix | Delete
* @since 2.8.0
[77] Fix | Delete
*
[78] Fix | Delete
* @var array|WP_Error $result {
[79] Fix | Delete
* @type string $source The full path to the source the files were installed from.
[80] Fix | Delete
* @type string $source_files List of all the files in the source directory.
[81] Fix | Delete
* @type string $destination The full path to the installation destination folder.
[82] Fix | Delete
* @type string $destination_name The name of the destination folder, or empty if `$destination`
[83] Fix | Delete
* and `$local_destination` are the same.
[84] Fix | Delete
* @type string $local_destination The full local path to the destination folder. This is usually
[85] Fix | Delete
* the same as `$destination`.
[86] Fix | Delete
* @type string $remote_destination The full remote path to the destination folder
[87] Fix | Delete
* (i.e., from `$wp_filesystem`).
[88] Fix | Delete
* @type bool $clear_destination Whether the destination folder was cleared.
[89] Fix | Delete
* }
[90] Fix | Delete
*/
[91] Fix | Delete
public $result = array();
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* The total number of updates being performed.
[95] Fix | Delete
*
[96] Fix | Delete
* Set by the bulk update methods.
[97] Fix | Delete
*
[98] Fix | Delete
* @since 3.0.0
[99] Fix | Delete
* @var int $update_count
[100] Fix | Delete
*/
[101] Fix | Delete
public $update_count = 0;
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* The current update if multiple updates are being performed.
[105] Fix | Delete
*
[106] Fix | Delete
* Used by the bulk update methods, and incremented for each update.
[107] Fix | Delete
*
[108] Fix | Delete
* @since 3.0.0
[109] Fix | Delete
* @var int
[110] Fix | Delete
*/
[111] Fix | Delete
public $update_current = 0;
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Stores the list of plugins or themes added to temporary backup directory.
[115] Fix | Delete
*
[116] Fix | Delete
* Used by the rollback functions.
[117] Fix | Delete
*
[118] Fix | Delete
* @since 6.3.0
[119] Fix | Delete
* @var array
[120] Fix | Delete
*/
[121] Fix | Delete
private $temp_backups = array();
[122] Fix | Delete
[123] Fix | Delete
/**
[124] Fix | Delete
* Stores the list of plugins or themes to be restored from temporary backup directory.
[125] Fix | Delete
*
[126] Fix | Delete
* Used by the rollback functions.
[127] Fix | Delete
*
[128] Fix | Delete
* @since 6.3.0
[129] Fix | Delete
* @var array
[130] Fix | Delete
*/
[131] Fix | Delete
private $temp_restores = array();
[132] Fix | Delete
[133] Fix | Delete
/**
[134] Fix | Delete
* Construct the upgrader with a skin.
[135] Fix | Delete
*
[136] Fix | Delete
* @since 2.8.0
[137] Fix | Delete
*
[138] Fix | Delete
* @param WP_Upgrader_Skin $skin The upgrader skin to use. Default is a WP_Upgrader_Skin
[139] Fix | Delete
* instance.
[140] Fix | Delete
*/
[141] Fix | Delete
public function __construct( $skin = null ) {
[142] Fix | Delete
if ( null === $skin ) {
[143] Fix | Delete
$this->skin = new WP_Upgrader_Skin();
[144] Fix | Delete
} else {
[145] Fix | Delete
$this->skin = $skin;
[146] Fix | Delete
}
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* Initializes the upgrader.
[151] Fix | Delete
*
[152] Fix | Delete
* This will set the relationship between the skin being used and this upgrader,
[153] Fix | Delete
* and also add the generic strings to `WP_Upgrader::$strings`.
[154] Fix | Delete
*
[155] Fix | Delete
* Additionally, it will schedule a weekly task to clean up the temporary backup directory.
[156] Fix | Delete
*
[157] Fix | Delete
* @since 2.8.0
[158] Fix | Delete
* @since 6.3.0 Added the `schedule_temp_backup_cleanup()` task.
[159] Fix | Delete
*/
[160] Fix | Delete
public function init() {
[161] Fix | Delete
$this->skin->set_upgrader( $this );
[162] Fix | Delete
$this->generic_strings();
[163] Fix | Delete
[164] Fix | Delete
if ( ! wp_installing() ) {
[165] Fix | Delete
$this->schedule_temp_backup_cleanup();
[166] Fix | Delete
}
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
/**
[170] Fix | Delete
* Schedules the cleanup of the temporary backup directory.
[171] Fix | Delete
*
[172] Fix | Delete
* @since 6.3.0
[173] Fix | Delete
*/
[174] Fix | Delete
protected function schedule_temp_backup_cleanup() {
[175] Fix | Delete
if ( false === wp_next_scheduled( 'wp_delete_temp_updater_backups' ) ) {
[176] Fix | Delete
wp_schedule_event( time(), 'weekly', 'wp_delete_temp_updater_backups' );
[177] Fix | Delete
}
[178] Fix | Delete
}
[179] Fix | Delete
[180] Fix | Delete
/**
[181] Fix | Delete
* Adds the generic strings to WP_Upgrader::$strings.
[182] Fix | Delete
*
[183] Fix | Delete
* @since 2.8.0
[184] Fix | Delete
*/
[185] Fix | Delete
public function generic_strings() {
[186] Fix | Delete
$this->strings['bad_request'] = __( 'Invalid data provided.' );
[187] Fix | Delete
$this->strings['fs_unavailable'] = __( 'Could not access filesystem.' );
[188] Fix | Delete
$this->strings['fs_error'] = __( 'Filesystem error.' );
[189] Fix | Delete
$this->strings['fs_no_root_dir'] = __( 'Unable to locate WordPress root directory.' );
[190] Fix | Delete
/* translators: %s: Directory name. */
[191] Fix | Delete
$this->strings['fs_no_content_dir'] = sprintf( __( 'Unable to locate WordPress content directory (%s).' ), 'wp-content' );
[192] Fix | Delete
$this->strings['fs_no_plugins_dir'] = __( 'Unable to locate WordPress plugin directory.' );
[193] Fix | Delete
$this->strings['fs_no_themes_dir'] = __( 'Unable to locate WordPress theme directory.' );
[194] Fix | Delete
/* translators: %s: Directory name. */
[195] Fix | Delete
$this->strings['fs_no_folder'] = __( 'Unable to locate needed folder (%s).' );
[196] Fix | Delete
[197] Fix | Delete
$this->strings['no_package'] = __( 'Package not available.' );
[198] Fix | Delete
$this->strings['download_failed'] = __( 'Download failed.' );
[199] Fix | Delete
$this->strings['installing_package'] = __( 'Installing the latest version&#8230;' );
[200] Fix | Delete
$this->strings['no_files'] = __( 'The package contains no files.' );
[201] Fix | Delete
$this->strings['folder_exists'] = __( 'Destination folder already exists.' );
[202] Fix | Delete
$this->strings['mkdir_failed'] = __( 'Could not create directory.' );
[203] Fix | Delete
$this->strings['incompatible_archive'] = __( 'The package could not be installed.' );
[204] Fix | Delete
$this->strings['files_not_writable'] = __( 'The update cannot be installed because some files could not be copied. This is usually due to inconsistent file permissions.' );
[205] Fix | Delete
$this->strings['dir_not_readable'] = __( 'A directory could not be read.' );
[206] Fix | Delete
[207] Fix | Delete
$this->strings['maintenance_start'] = __( 'Enabling Maintenance mode&#8230;' );
[208] Fix | Delete
$this->strings['maintenance_end'] = __( 'Disabling Maintenance mode&#8230;' );
[209] Fix | Delete
[210] Fix | Delete
/* translators: %s: upgrade-temp-backup */
[211] Fix | Delete
$this->strings['temp_backup_mkdir_failed'] = sprintf( __( 'Could not create the %s directory.' ), 'upgrade-temp-backup' );
[212] Fix | Delete
/* translators: %s: upgrade-temp-backup */
[213] Fix | Delete
$this->strings['temp_backup_move_failed'] = sprintf( __( 'Could not move the old version to the %s directory.' ), 'upgrade-temp-backup' );
[214] Fix | Delete
/* translators: %s: The plugin or theme slug. */
[215] Fix | Delete
$this->strings['temp_backup_restore_failed'] = __( 'Could not restore the original version of %s.' );
[216] Fix | Delete
/* translators: %s: The plugin or theme slug. */
[217] Fix | Delete
$this->strings['temp_backup_delete_failed'] = __( 'Could not delete the temporary backup directory for %s.' );
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
/**
[221] Fix | Delete
* Connects to the filesystem.
[222] Fix | Delete
*
[223] Fix | Delete
* @since 2.8.0
[224] Fix | Delete
*
[225] Fix | Delete
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
[226] Fix | Delete
*
[227] Fix | Delete
* @param string[] $directories Optional. Array of directories. If any of these do
[228] Fix | Delete
* not exist, a WP_Error object will be returned.
[229] Fix | Delete
* Default empty array.
[230] Fix | Delete
* @param bool $allow_relaxed_file_ownership Whether to allow relaxed file ownership.
[231] Fix | Delete
* Default false.
[232] Fix | Delete
* @return bool|WP_Error True if able to connect, false or a WP_Error otherwise.
[233] Fix | Delete
*/
[234] Fix | Delete
public function fs_connect( $directories = array(), $allow_relaxed_file_ownership = false ) {
[235] Fix | Delete
global $wp_filesystem;
[236] Fix | Delete
[237] Fix | Delete
$credentials = $this->skin->request_filesystem_credentials( false, $directories[0], $allow_relaxed_file_ownership );
[238] Fix | Delete
if ( false === $credentials ) {
[239] Fix | Delete
return false;
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
if ( ! WP_Filesystem( $credentials, $directories[0], $allow_relaxed_file_ownership ) ) {
[243] Fix | Delete
$error = true;
[244] Fix | Delete
if ( is_object( $wp_filesystem ) && $wp_filesystem->errors->has_errors() ) {
[245] Fix | Delete
$error = $wp_filesystem->errors;
[246] Fix | Delete
}
[247] Fix | Delete
// Failed to connect. Error and request again.
[248] Fix | Delete
$this->skin->request_filesystem_credentials( $error, $directories[0], $allow_relaxed_file_ownership );
[249] Fix | Delete
return false;
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
if ( ! is_object( $wp_filesystem ) ) {
[253] Fix | Delete
return new WP_Error( 'fs_unavailable', $this->strings['fs_unavailable'] );
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
if ( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
[257] Fix | Delete
return new WP_Error( 'fs_error', $this->strings['fs_error'], $wp_filesystem->errors );
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
foreach ( (array) $directories as $dir ) {
[261] Fix | Delete
switch ( $dir ) {
[262] Fix | Delete
case ABSPATH:
[263] Fix | Delete
if ( ! $wp_filesystem->abspath() ) {
[264] Fix | Delete
return new WP_Error( 'fs_no_root_dir', $this->strings['fs_no_root_dir'] );
[265] Fix | Delete
}
[266] Fix | Delete
break;
[267] Fix | Delete
case WP_CONTENT_DIR:
[268] Fix | Delete
if ( ! $wp_filesystem->wp_content_dir() ) {
[269] Fix | Delete
return new WP_Error( 'fs_no_content_dir', $this->strings['fs_no_content_dir'] );
[270] Fix | Delete
}
[271] Fix | Delete
break;
[272] Fix | Delete
case WP_PLUGIN_DIR:
[273] Fix | Delete
if ( ! $wp_filesystem->wp_plugins_dir() ) {
[274] Fix | Delete
return new WP_Error( 'fs_no_plugins_dir', $this->strings['fs_no_plugins_dir'] );
[275] Fix | Delete
}
[276] Fix | Delete
break;
[277] Fix | Delete
case get_theme_root():
[278] Fix | Delete
if ( ! $wp_filesystem->wp_themes_dir() ) {
[279] Fix | Delete
return new WP_Error( 'fs_no_themes_dir', $this->strings['fs_no_themes_dir'] );
[280] Fix | Delete
}
[281] Fix | Delete
break;
[282] Fix | Delete
default:
[283] Fix | Delete
if ( ! $wp_filesystem->find_folder( $dir ) ) {
[284] Fix | Delete
return new WP_Error( 'fs_no_folder', sprintf( $this->strings['fs_no_folder'], esc_html( basename( $dir ) ) ) );
[285] Fix | Delete
}
[286] Fix | Delete
break;
[287] Fix | Delete
}
[288] Fix | Delete
}
[289] Fix | Delete
return true;
[290] Fix | Delete
}
[291] Fix | Delete
[292] Fix | Delete
/**
[293] Fix | Delete
* Downloads a package.
[294] Fix | Delete
*
[295] Fix | Delete
* @since 2.8.0
[296] Fix | Delete
* @since 5.2.0 Added the `$check_signatures` parameter.
[297] Fix | Delete
* @since 5.5.0 Added the `$hook_extra` parameter.
[298] Fix | Delete
*
[299] Fix | Delete
* @param string $package The URI of the package. If this is the full path to an
[300] Fix | Delete
* existing local file, it will be returned untouched.
[301] Fix | Delete
* @param bool $check_signatures Whether to validate file signatures. Default false.
[302] Fix | Delete
* @param array $hook_extra Extra arguments to pass to the filter hooks. Default empty array.
[303] Fix | Delete
* @return string|WP_Error The full path to the downloaded package file, or a WP_Error object.
[304] Fix | Delete
*/
[305] Fix | Delete
public function download_package( $package, $check_signatures = false, $hook_extra = array() ) {
[306] Fix | Delete
/**
[307] Fix | Delete
* Filters whether to return the package.
[308] Fix | Delete
*
[309] Fix | Delete
* @since 3.7.0
[310] Fix | Delete
* @since 5.5.0 Added the `$hook_extra` parameter.
[311] Fix | Delete
*
[312] Fix | Delete
* @param bool $reply Whether to bail without returning the package.
[313] Fix | Delete
* Default false.
[314] Fix | Delete
* @param string $package The package file name.
[315] Fix | Delete
* @param WP_Upgrader $upgrader The WP_Upgrader instance.
[316] Fix | Delete
* @param array $hook_extra Extra arguments passed to hooked filters.
[317] Fix | Delete
*/
[318] Fix | Delete
$reply = apply_filters( 'upgrader_pre_download', false, $package, $this, $hook_extra );
[319] Fix | Delete
if ( false !== $reply ) {
[320] Fix | Delete
return $reply;
[321] Fix | Delete
}
[322] Fix | Delete
[323] Fix | Delete
if ( ! preg_match( '!^(http|https|ftp)://!i', $package ) && file_exists( $package ) ) { // Local file or remote?
[324] Fix | Delete
return $package; // Must be a local file.
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
if ( empty( $package ) ) {
[328] Fix | Delete
return new WP_Error( 'no_package', $this->strings['no_package'] );
[329] Fix | Delete
}
[330] Fix | Delete
[331] Fix | Delete
$this->skin->feedback( 'downloading_package', $package );
[332] Fix | Delete
[333] Fix | Delete
$download_file = download_url( $package, 300, $check_signatures );
[334] Fix | Delete
[335] Fix | Delete
if ( is_wp_error( $download_file ) && ! $download_file->get_error_data( 'softfail-filename' ) ) {
[336] Fix | Delete
return new WP_Error( 'download_failed', $this->strings['download_failed'], $download_file->get_error_message() );
[337] Fix | Delete
}
[338] Fix | Delete
[339] Fix | Delete
return $download_file;
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
/**
[343] Fix | Delete
* Unpacks a compressed package file.
[344] Fix | Delete
*
[345] Fix | Delete
* @since 2.8.0
[346] Fix | Delete
*
[347] Fix | Delete
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
[348] Fix | Delete
*
[349] Fix | Delete
* @param string $package Full path to the package file.
[350] Fix | Delete
* @param bool $delete_package Optional. Whether to delete the package file after attempting
[351] Fix | Delete
* to unpack it. Default true.
[352] Fix | Delete
* @return string|WP_Error The path to the unpacked contents, or a WP_Error on failure.
[353] Fix | Delete
*/
[354] Fix | Delete
public function unpack_package( $package, $delete_package = true ) {
[355] Fix | Delete
global $wp_filesystem;
[356] Fix | Delete
[357] Fix | Delete
$this->skin->feedback( 'unpack_package' );
[358] Fix | Delete
[359] Fix | Delete
if ( ! $wp_filesystem->wp_content_dir() ) {
[360] Fix | Delete
return new WP_Error( 'fs_no_content_dir', $this->strings['fs_no_content_dir'] );
[361] Fix | Delete
}
[362] Fix | Delete
[363] Fix | Delete
$upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
[364] Fix | Delete
[365] Fix | Delete
// Clean up contents of upgrade directory beforehand.
[366] Fix | Delete
$upgrade_files = $wp_filesystem->dirlist( $upgrade_folder );
[367] Fix | Delete
if ( ! empty( $upgrade_files ) ) {
[368] Fix | Delete
foreach ( $upgrade_files as $file ) {
[369] Fix | Delete
$wp_filesystem->delete( $upgrade_folder . $file['name'], true );
[370] Fix | Delete
}
[371] Fix | Delete
}
[372] Fix | Delete
[373] Fix | Delete
// We need a working directory - strip off any .tmp or .zip suffixes.
[374] Fix | Delete
$working_dir = $upgrade_folder . basename( basename( $package, '.tmp' ), '.zip' );
[375] Fix | Delete
[376] Fix | Delete
// Clean up working directory.
[377] Fix | Delete
if ( $wp_filesystem->is_dir( $working_dir ) ) {
[378] Fix | Delete
$wp_filesystem->delete( $working_dir, true );
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
// Unzip package to working directory.
[382] Fix | Delete
$result = unzip_file( $package, $working_dir );
[383] Fix | Delete
[384] Fix | Delete
// Once extracted, delete the package if required.
[385] Fix | Delete
if ( $delete_package ) {
[386] Fix | Delete
unlink( $package );
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
if ( is_wp_error( $result ) ) {
[390] Fix | Delete
$wp_filesystem->delete( $working_dir, true );
[391] Fix | Delete
if ( 'incompatible_archive' === $result->get_error_code() ) {
[392] Fix | Delete
return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data() );
[393] Fix | Delete
}
[394] Fix | Delete
return $result;
[395] Fix | Delete
}
[396] Fix | Delete
[397] Fix | Delete
return $working_dir;
[398] Fix | Delete
}
[399] Fix | Delete
[400] Fix | Delete
/**
[401] Fix | Delete
* Flattens the results of WP_Filesystem_Base::dirlist() for iterating over.
[402] Fix | Delete
*
[403] Fix | Delete
* @since 4.9.0
[404] Fix | Delete
*
[405] Fix | Delete
* @param array $nested_files Array of files as returned by WP_Filesystem_Base::dirlist().
[406] Fix | Delete
* @param string $path Relative path to prepend to child nodes. Optional.
[407] Fix | Delete
* @return array A flattened array of the $nested_files specified.
[408] Fix | Delete
*/
[409] Fix | Delete
protected function flatten_dirlist( $nested_files, $path = '' ) {
[410] Fix | Delete
$files = array();
[411] Fix | Delete
[412] Fix | Delete
foreach ( $nested_files as $name => $details ) {
[413] Fix | Delete
$files[ $path . $name ] = $details;
[414] Fix | Delete
[415] Fix | Delete
// Append children recursively.
[416] Fix | Delete
if ( ! empty( $details['files'] ) ) {
[417] Fix | Delete
$children = $this->flatten_dirlist( $details['files'], $path . $name . '/' );
[418] Fix | Delete
[419] Fix | Delete
// Merge keeping possible numeric keys, which array_merge() will reindex from 0..n.
[420] Fix | Delete
$files = $files + $children;
[421] Fix | Delete
}
[422] Fix | Delete
}
[423] Fix | Delete
[424] Fix | Delete
return $files;
[425] Fix | Delete
}
[426] Fix | Delete
[427] Fix | Delete
/**
[428] Fix | Delete
* Clears the directory where this item is going to be installed into.
[429] Fix | Delete
*
[430] Fix | Delete
* @since 4.3.0
[431] Fix | Delete
*
[432] Fix | Delete
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
[433] Fix | Delete
*
[434] Fix | Delete
* @param string $remote_destination The location on the remote filesystem to be cleared.
[435] Fix | Delete
* @return true|WP_Error True upon success, WP_Error on failure.
[436] Fix | Delete
*/
[437] Fix | Delete
public function clear_destination( $remote_destination ) {
[438] Fix | Delete
global $wp_filesystem;
[439] Fix | Delete
[440] Fix | Delete
$files = $wp_filesystem->dirlist( $remote_destination, true, true );
[441] Fix | Delete
[442] Fix | Delete
// False indicates that the $remote_destination doesn't exist.
[443] Fix | Delete
if ( false === $files ) {
[444] Fix | Delete
return true;
[445] Fix | Delete
}
[446] Fix | Delete
[447] Fix | Delete
// Flatten the file list to iterate over.
[448] Fix | Delete
$files = $this->flatten_dirlist( $files );
[449] Fix | Delete
[450] Fix | Delete
// Check all files are writable before attempting to clear the destination.
[451] Fix | Delete
$unwritable_files = array();
[452] Fix | Delete
[453] Fix | Delete
// Check writability.
[454] Fix | Delete
foreach ( $files as $filename => $file_details ) {
[455] Fix | Delete
if ( ! $wp_filesystem->is_writable( $remote_destination . $filename ) ) {
[456] Fix | Delete
// Attempt to alter permissions to allow writes and try again.
[457] Fix | Delete
$wp_filesystem->chmod( $remote_destination . $filename, ( 'd' === $file_details['type'] ? FS_CHMOD_DIR : FS_CHMOD_FILE ) );
[458] Fix | Delete
if ( ! $wp_filesystem->is_writable( $remote_destination . $filename ) ) {
[459] Fix | Delete
$unwritable_files[] = $filename;
[460] Fix | Delete
}
[461] Fix | Delete
}
[462] Fix | Delete
}
[463] Fix | Delete
[464] Fix | Delete
if ( ! empty( $unwritable_files ) ) {
[465] Fix | Delete
return new WP_Error( 'files_not_writable', $this->strings['files_not_writable'], implode( ', ', $unwritable_files ) );
[466] Fix | Delete
}
[467] Fix | Delete
[468] Fix | Delete
if ( ! $wp_filesystem->delete( $remote_destination, true ) ) {
[469] Fix | Delete
return new WP_Error( 'remove_old_failed', $this->strings['remove_old_failed'] );
[470] Fix | Delete
}
[471] Fix | Delete
[472] Fix | Delete
return true;
[473] Fix | Delete
}
[474] Fix | Delete
[475] Fix | Delete
/**
[476] Fix | Delete
* Install a package.
[477] Fix | Delete
*
[478] Fix | Delete
* Copies the contents of a package from a source directory, and installs them in
[479] Fix | Delete
* a destination directory. Optionally removes the source. It can also optionally
[480] Fix | Delete
* clear out the destination folder if it already exists.
[481] Fix | Delete
*
[482] Fix | Delete
* @since 2.8.0
[483] Fix | Delete
* @since 6.2.0 Use move_dir() instead of copy_dir() when possible.
[484] Fix | Delete
*
[485] Fix | Delete
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
[486] Fix | Delete
* @global string[] $wp_theme_directories
[487] Fix | Delete
*
[488] Fix | Delete
* @param array|string $args {
[489] Fix | Delete
* Optional. Array or string of arguments for installing a package. Default empty array.
[490] Fix | Delete
*
[491] Fix | Delete
* @type string $source Required path to the package source. Default empty.
[492] Fix | Delete
* @type string $destination Required path to a folder to install the package in.
[493] Fix | Delete
* Default empty.
[494] Fix | Delete
* @type bool $clear_destination Whether to delete any files already in the destination
[495] Fix | Delete
* folder. Default false.
[496] Fix | Delete
* @type bool $clear_working Whether to delete the files from the working directory
[497] Fix | Delete
* after copying them to the destination. Default false.
[498] Fix | Delete
* @type bool $abort_if_destination_exists Whether to abort the installation if
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function