wppaste
WordPress

WP_Upgrader::download_package( string $package, bool $check_signatures = false, array $hook_extra = array() ): string|WP_Error

Since
2.8.0, 5.2.0, 5.5.0
Source
wp-admin/includes/class-wp-upgrader.php:307
Downloads a package for a WordPress core, plugin, theme, or translation upgrade.

Compatibility

WordPress
since 5.5.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$packagestring
The URI of the package. May be a remote URL or local file path. If this is the full path to an existing local file, it will be returned untouched.
$check_signaturesbooloptional
Whether to validate file signatures. Default false.Default: false
$hook_extraarrayoptional
Extra arguments to pass to the filter hooks. Default empty array.Default: array()

Return value

string|WP_Error
The full path to the downloaded package file, or a WP_Error object.

Performance profile

How much work a call to WP_Upgrader::download_package() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Expensive

Reaches an outbound HTTP request via wp_safe_remote_get().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
15–52

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 63.

Plugin surface
1 hook

Third-party callbacks on 'upgrader_pre_download' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • filesystemfilesystem accessfile_exists()called directly
  • httpoutbound HTTP requestwp_safe_remote_get()one call below WP_Upgrader::download_package()

Further down the call graph this can also reach transient, option, query, cache and serialize. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 8 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Upgrader::download_package() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always15–26apply_filters()
$reply === false && !$package21–30apply_filters(), file_exists()
$reply === false && $package && !empty($package) && !is_wp_error()34apply_filters(), ->feedback(), download_url(), is_wp_error()
$reply === false && $package && !empty($package) && is_wp_error() && ->get_error_data()38apply_filters(), ->feedback(), download_url(), is_wp_error(), ->get_error_data()
$reply === false && !$package && !file_exists() && !empty($package) && !is_wp_error()38apply_filters(), file_exists(), ->feedback(), download_url(), is_wp_error()
$reply === false && !$package && !file_exists() && !empty($package) && is_wp_error() && ->get_error_data()42apply_filters(), file_exists(), ->feedback(), download_url(), is_wp_error(), ->get_error_data()
$reply === false && $package && !empty($package) && is_wp_error() && !->get_error_data()48apply_filters(), ->feedback(), download_url(), is_wp_error(), ->get_error_data(), ->get_error_message()
$reply === false && !$package && !file_exists() && !empty($package) && is_wp_error() && !->get_error_data()52apply_filters(), file_exists(), ->feedback(), download_url(), is_wp_error(), ->get_error_data(), ->get_error_message()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev6315–526
8.56315–526
8.46315–5263 fewer instructions than PHP 8.3
8.36615–556
8.26615–556
8.16615–556
7.46615–556

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while WP_Upgrader::download_package() runs, in this order:

  1. apply_filters( upgrader_pre_download )filterline 322 (+15 into the body)

    Filters whether to download a package for a WordPress core, plugin, theme, or translation upgrade.

Uses · 4

Used by · 1

Source code

	public function download_package( $package, $check_signatures = false, $hook_extra = array() ) {		/**		 * Filters whether to download a package for a WordPress core, plugin, theme, or translation upgrade.		 *		 * Return a non-false value to short-circuit the download and return that value instead.		 *		 * @since 3.7.0		 * @since 5.5.0 Added the `$hook_extra` parameter.		 *		 * @param false|string|WP_Error $reply      Whether to short-circuit the download, the path to the downloaded package,		 *                                          or a WP_Error object. Default false.		 * @param string                $package    The package URI. May be a remote URL or local file path.		 * @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;	}

Changelog

Introduced in 2.8.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

5.5.0
Added the $hook_extra parameter.from the docblock
5.2.0
Added the $check_signatures parameter.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-wp-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.