Upgrade/Install: Add `hook_extra` parameter to the `upgrader_pre_download` filter.

This provides additional context to code running on this hook, including which plugin or theme update will be downloaded. It also brings consistency to this filter with others throughout the upgrade process.

Props obliviousharmony, desrosj.
Fixes #49686.

git-svn-id: https://develop.svn.wordpress.org/trunk@48399 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2020-07-07 19:13:30 +00:00
parent 86ffb51a33
commit 61803a37a4
1 changed files with 9 additions and 8 deletions

View File

@ -248,10 +248,10 @@ class WP_Upgrader {
* @param string $package The URI of the package. If this is the full path to an
* existing local file, it will be returned untouched.
* @param bool $check_signatures Whether to validate file signatures. Default false.
* @param array $hook_extra Extra arguments to pass to the filter hooks. Default empty array.
* @return string|WP_Error The full path to the downloaded package file, or a WP_Error object.
*/
public function download_package( $package, $check_signatures = false ) {
public function download_package( $package, $check_signatures = false, $hook_extra = array() ) {
/**
* Filters whether to return the package.
*
@ -261,8 +261,9 @@ class WP_Upgrader {
* Default false.
* @param string $package The package file name.
* @param WP_Upgrader $this The WP_Upgrader instance.
* @param array $hook_extra Extra arguments passed to hooked filters.
*/
$reply = apply_filters( 'upgrader_pre_download', false, $package, $this );
$reply = apply_filters( 'upgrader_pre_download', false, $package, $this, $hook_extra );
if ( false !== $reply ) {
return $reply;
}
@ -737,7 +738,7 @@ class WP_Upgrader {
* Download the package (Note, This just returns the filename
* of the file if the package is a local file)
*/
$download = $this->download_package( $options['package'], true );
$download = $this->download_package( $options['package'], true, $options['hook_extra'] );
// Allow for signature soft-fail.
// WARNING: This may be removed in the future.