Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../clone/wp-admin/includes
File: class-file-upload-upgrader.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Upgrade API: File_Upload_Upgrader class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Upgrader
[5] Fix | Delete
* @since 4.6.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Core class used for handling file uploads.
[10] Fix | Delete
*
[11] Fix | Delete
* This class handles the upload process and passes it as if it's a local file
[12] Fix | Delete
* to the Upgrade/Installer functions.
[13] Fix | Delete
*
[14] Fix | Delete
* @since 2.8.0
[15] Fix | Delete
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader.php.
[16] Fix | Delete
*/
[17] Fix | Delete
#[AllowDynamicProperties]
[18] Fix | Delete
class File_Upload_Upgrader {
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* The full path to the file package.
[22] Fix | Delete
*
[23] Fix | Delete
* @since 2.8.0
[24] Fix | Delete
* @var string $package
[25] Fix | Delete
*/
[26] Fix | Delete
public $package;
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* The name of the file.
[30] Fix | Delete
*
[31] Fix | Delete
* @since 2.8.0
[32] Fix | Delete
* @var string $filename
[33] Fix | Delete
*/
[34] Fix | Delete
public $filename;
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* The ID of the attachment post for this file.
[38] Fix | Delete
*
[39] Fix | Delete
* @since 3.3.0
[40] Fix | Delete
* @var int $id
[41] Fix | Delete
*/
[42] Fix | Delete
public $id = 0;
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Construct the upgrader for a form.
[46] Fix | Delete
*
[47] Fix | Delete
* @since 2.8.0
[48] Fix | Delete
*
[49] Fix | Delete
* @param string $form The name of the form the file was uploaded from.
[50] Fix | Delete
* @param string $urlholder The name of the `GET` parameter that holds the filename.
[51] Fix | Delete
*/
[52] Fix | Delete
public function __construct( $form, $urlholder ) {
[53] Fix | Delete
[54] Fix | Delete
if ( empty( $_FILES[ $form ]['name'] ) && empty( $_GET[ $urlholder ] ) ) {
[55] Fix | Delete
wp_die( __( 'Please select a file' ) );
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
// Handle a newly uploaded file. Else, assume it's already been uploaded.
[59] Fix | Delete
if ( ! empty( $_FILES ) ) {
[60] Fix | Delete
$overrides = array(
[61] Fix | Delete
'test_form' => false,
[62] Fix | Delete
'test_type' => false,
[63] Fix | Delete
);
[64] Fix | Delete
$file = wp_handle_upload( $_FILES[ $form ], $overrides );
[65] Fix | Delete
[66] Fix | Delete
if ( isset( $file['error'] ) ) {
[67] Fix | Delete
wp_die( $file['error'] );
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
if ( 'pluginzip' === $form || 'themezip' === $form ) {
[71] Fix | Delete
if ( ! wp_zip_file_is_valid( $file['file'] ) ) {
[72] Fix | Delete
wp_delete_file( $file['file'] );
[73] Fix | Delete
[74] Fix | Delete
if ( 'pluginzip' === $form ) {
[75] Fix | Delete
$plugins_page = sprintf(
[76] Fix | Delete
'<a href="%s">%s</a>',
[77] Fix | Delete
self_admin_url( 'plugin-install.php' ),
[78] Fix | Delete
__( 'Return to the Plugin Installer' )
[79] Fix | Delete
);
[80] Fix | Delete
wp_die( __( 'Incompatible Archive.' ) . '<br />' . $plugins_page );
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
if ( 'themezip' === $form ) {
[84] Fix | Delete
$themes_page = sprintf(
[85] Fix | Delete
'<a href="%s" target="_parent">%s</a>',
[86] Fix | Delete
self_admin_url( 'theme-install.php' ),
[87] Fix | Delete
__( 'Return to the Theme Installer' )
[88] Fix | Delete
);
[89] Fix | Delete
wp_die( __( 'Incompatible Archive.' ) . '<br />' . $themes_page );
[90] Fix | Delete
}
[91] Fix | Delete
}
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
$this->filename = $_FILES[ $form ]['name'];
[95] Fix | Delete
$this->package = $file['file'];
[96] Fix | Delete
[97] Fix | Delete
// Construct the attachment array.
[98] Fix | Delete
$attachment = array(
[99] Fix | Delete
'post_title' => $this->filename,
[100] Fix | Delete
'post_content' => $file['url'],
[101] Fix | Delete
'post_mime_type' => $file['type'],
[102] Fix | Delete
'guid' => $file['url'],
[103] Fix | Delete
'context' => 'upgrader',
[104] Fix | Delete
'post_status' => 'private',
[105] Fix | Delete
);
[106] Fix | Delete
[107] Fix | Delete
// Save the data.
[108] Fix | Delete
$this->id = wp_insert_attachment( $attachment, $file['file'] );
[109] Fix | Delete
[110] Fix | Delete
// Schedule a cleanup for 2 hours from now in case of failed installation.
[111] Fix | Delete
wp_schedule_single_event( time() + 2 * HOUR_IN_SECONDS, 'upgrader_scheduled_cleanup', array( $this->id ) );
[112] Fix | Delete
[113] Fix | Delete
} elseif ( is_numeric( $_GET[ $urlholder ] ) ) {
[114] Fix | Delete
// Numeric Package = previously uploaded file, see above.
[115] Fix | Delete
$this->id = (int) $_GET[ $urlholder ];
[116] Fix | Delete
$attachment = get_post( $this->id );
[117] Fix | Delete
if ( empty( $attachment ) ) {
[118] Fix | Delete
wp_die( __( 'Please select a file' ) );
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
$this->filename = $attachment->post_title;
[122] Fix | Delete
$this->package = get_attached_file( $attachment->ID );
[123] Fix | Delete
} else {
[124] Fix | Delete
// Else, It's set to something, Back compat for plugins using the old (pre-3.3) File_Uploader handler.
[125] Fix | Delete
$uploads = wp_upload_dir();
[126] Fix | Delete
if ( ! ( $uploads && false === $uploads['error'] ) ) {
[127] Fix | Delete
wp_die( $uploads['error'] );
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
$this->filename = sanitize_file_name( $_GET[ $urlholder ] );
[131] Fix | Delete
$this->package = $uploads['basedir'] . '/' . $this->filename;
[132] Fix | Delete
[133] Fix | Delete
if ( ! str_starts_with( realpath( $this->package ), realpath( $uploads['basedir'] ) ) ) {
[134] Fix | Delete
wp_die( __( 'Please select a file' ) );
[135] Fix | Delete
}
[136] Fix | Delete
}
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Deletes the attachment/uploaded file.
[141] Fix | Delete
*
[142] Fix | Delete
* @since 3.2.2
[143] Fix | Delete
*
[144] Fix | Delete
* @return bool Whether the cleanup was successful.
[145] Fix | Delete
*/
[146] Fix | Delete
public function cleanup() {
[147] Fix | Delete
if ( $this->id ) {
[148] Fix | Delete
wp_delete_attachment( $this->id );
[149] Fix | Delete
[150] Fix | Delete
} elseif ( file_exists( $this->package ) ) {
[151] Fix | Delete
return @unlink( $this->package );
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
return true;
[155] Fix | Delete
}
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function