File_Upload_Upgrader
- Since
- 2.8.0, 4.6.0
- Source
wp-admin/includes/class-file-upload-upgrader.php:19
Core class used for handling file uploads.
Description
This class handles the upload process and passes it as if it's a local file to the Upgrade/Installer functions.
Properties · 3
$packagestringpublic- The full path to the file package.
$filenamestringpublic- The name of the file.
$idintpublic- The ID of the attachment post for this file.
Methods · 2
- __construct()Construct the upgrader for a form.
- cleanup()Deletes the attachment/uploaded file.
Source
#[AllowDynamicProperties]class File_Upload_Upgrader { /** * The full path to the file package. * * @since 2.8.0 * @var string $package */ public $package; /** * The name of the file. * * @since 2.8.0 * @var string $filename */ public $filename; /** * The ID of the attachment post for this file. * * @since 3.3.0 * @var int $id */ public $id = 0; /** * Construct the upgrader for a form. * * @since 2.8.0 * * @param string $form The name of the form the file was uploaded from. * @param string $urlholder The name of the `GET` parameter that holds the filename. */ public function __construct( $form, $urlholder ) { if ( empty( $_FILES[ $form ]['name'] ) && empty( $_GET[ $urlholder ] ) ) { wp_die( __( 'Please select a file' ) ); } // Handle a newly uploaded file. Else, assume it's already been uploaded. if ( ! empty( $_FILES ) ) { $overrides = array( 'test_form' => false, 'test_type' => false, ); $file = wp_handle_upload( $_FILES[ $form ], $overrides ); if ( isset( $file['error'] ) ) { wp_die( $file['error'] ); } if ( 'pluginzip' === $form || 'themezip' === $form ) { if ( ! wp_zip_file_is_valid( $file['file'] ) ) { wp_delete_file( $file['file'] ); if ( 'pluginzip' === $form ) { $plugins_page = sprintf( '<a href="%s">%s</a>', self_admin_url( 'plugin-install.php' ), __( 'Return to the Plugin Installer' ) ); wp_die( __( 'Incompatible Archive.' ) . '<br />' . $plugins_page ); } if ( 'themezip' === $form ) { $themes_page = sprintf( '<a href="%s" target="_parent">%s</a>', self_admin_url( 'theme-install.php' ), __( 'Return to the Theme Installer' ) ); wp_die( __( 'Incompatible Archive.' ) . '<br />' . $themes_page ); } } } $this->filename = $_FILES[ $form ]['name']; $this->package = $file['file'];History
Introduced in 2.8.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
4.6.0
Moved to its own file from wp-admin/includes/class-wp-upgrader.php.from the docblock
2.8.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-admin/includes/class-file-upload-upgrader.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.