Downloads a package.
Parameters
$package
stringrequired- The URI of the package. If this is the full path to an existing local file, it will be returned untouched.
$check_signatures
booloptional- Whether to validate file signatures.
Default:
false
$hook_extra
arrayoptional- Extra arguments to pass to the filter hooks.
Default:
array()
Source
public function download_package( $package, $check_signatures = false, $hook_extra = array() ) {
/**
* Filters whether to return the package.
*
* @since 3.7.0
* @since 5.5.0 Added the `$hook_extra` parameter.
*
* @param bool $reply Whether to bail without returning the package.
* Default false.
* @param string $package The package file name.
* @param WP_Upgrader $upgrader The WP_Upgrader instance.
* @param array $hook_extra Extra arguments passed to hooked filters.
*/
$reply = apply_filters( 'upgrader_pre_download', false, $package, $this, $hook_extra );
if ( false !== $reply ) {
return $reply;
}
if ( ! preg_match( '!^(http|https|ftp)://!i', $package ) && file_exists( $package ) ) { // Local file or remote?
return $package; // Must be a local file.
}
if ( empty( $package ) ) {
return new WP_Error( 'no_package', $this->strings['no_package'] );
}
$this->skin->feedback( 'downloading_package', $package );
$download_file = download_url( $package, 300, $check_signatures );
if ( is_wp_error( $download_file ) && ! $download_file->get_error_data( 'softfail-filename' ) ) {
return new WP_Error( 'download_failed', $this->strings['download_failed'], $download_file->get_error_message() );
}
return $download_file;
}
Hooks
- apply_filters( ‘upgrader_pre_download’,
bool $reply ,string $package ,WP_Upgrader $upgrader ,array $hook_extra ) Filters whether to return the package.
User Contributed Notes
You must log in before being able to contribute a note or feedback.