WordPress.org

Make WordPress Core

Ticket #42448: 42448.diff

File 42448.diff, 1.2 KB (added by NathanAtmoz, 4 years ago)

Introduce upgrader_pre_unpack filter prior to unpacking the package.

  • src/wp-admin/includes/class-wp-upgrader.php

    diff --git a/src/wp-admin/includes/class-wp-upgrader.php b/src/wp-admin/includes/class-wp-upgrader.php
    index fd70ba4..b10b646 100644
    a b class WP_Upgrader { 
    286286        public function unpack_package( $package, $delete_package = true ) {
    287287                global $wp_filesystem;
    288288
     289
     290                /**
     291                 * Filters the install response before the unpacking of the package has started.
     292                 *
     293                 * Returning a truthy value, or one that could be evaluated as a WP_Error
     294                 * will effectively short-circuit the unpacking, returning that value
     295                 * instead. This hook could be used to verify a package's signature or
     296                 * override the unpacking code entirely.
     297                 *
     298                 * @since 5.0.0
     299                 *
     300                 * @param bool        $reply   Whether to bail without returning the package.
     301                 *                             Default false.
     302                 * @param string      $package The package file name.
     303                 * @param WP_Upgrader $this    The WP_Upgrader instance.
     304                 */
     305                $reply = apply_filters( 'upgrader_pre_unpack', false, $package, $this );
     306                if ( false !== $reply )
     307                        return $reply;
     308
    289309                $this->skin->feedback('unpack_package');
    290310
    291311                $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';