WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_Upgrader::unpack_package() WP 2.8.0

Unpack a compressed package file.

Это метод класса: WP_Upgrader

Хуков нет.

Возвращает

Строку/WP_Error. The path to the unpacked contents, or a WP_Error on failure.

Использование

$WP_Upgrader = new WP_Upgrader();
$var = $WP_Upgrader->unpack_package( $package, $delete_package );
$package(строка) (обязательный)
Full path to the package file.
$delete_package(true/false)
Whether to delete the package file after attempting to unpack it.
По умолчанию: true

Заметки

  • Global. WP_Filesystem_Base. $wp_filesystem WordPress filesystem subclass.

Список изменений

С версии 2.8.0 Введена.

Код WP Upgrader::unpack package: wp-admin/includes/class-wp-upgrader.php WP 5.2.2

<?php
public function unpack_package( $package, $delete_package = true ) {
	global $wp_filesystem;

	$this->skin->feedback( 'unpack_package' );

	$upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';

	//Clean up contents of upgrade directory beforehand.
	$upgrade_files = $wp_filesystem->dirlist( $upgrade_folder );
	if ( ! empty( $upgrade_files ) ) {
		foreach ( $upgrade_files as $file ) {
			$wp_filesystem->delete( $upgrade_folder . $file['name'], true );
		}
	}

	// We need a working directory - Strip off any .tmp or .zip suffixes
	$working_dir = $upgrade_folder . basename( basename( $package, '.tmp' ), '.zip' );

	// Clean up working directory
	if ( $wp_filesystem->is_dir( $working_dir ) ) {
		$wp_filesystem->delete( $working_dir, true );
	}

	// Unzip package to working directory
	$result = unzip_file( $package, $working_dir );

	// Once extracted, delete the package if required.
	if ( $delete_package ) {
		unlink( $package );
	}

	if ( is_wp_error( $result ) ) {
		$wp_filesystem->delete( $working_dir, true );
		if ( 'incompatible_archive' == $result->get_error_code() ) {
			return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], $result->get_error_data() );
		}
		return $result;
	}

	return $working_dir;
}