wp_zip_file_is_valid( string $file ): bool

Determines whether the given file is a valid ZIP file.

Description

This function does not test to ensure that a file exists. Non-existent files are not valid ZIPs, so those will also return false.

Parameters

$filestringrequired
Full path to the ZIP file.

Return

bool Whether the file is a valid ZIP file.

Source

			$archive->close();
			return true;
		}
	}

	// Fall through to PclZip if ZipArchive is not available, or encountered an error opening the file.
	require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';

	$archive          = new PclZip( $file );
	$archive_is_valid = is_array( $archive->properties() );

	return $archive_is_valid;
}

/**
 * Unzips a specified ZIP file to a location on the filesystem via the WordPress
 * Filesystem Abstraction.
 *
 * Assumes that WP_Filesystem() has already been called and set up. Does not extract

Hooks

apply_filters( ‘unzip_file_use_ziparchive’, bool $ziparchive )

Filters whether to use ZipArchive to unzip archives.

Changelog

VersionDescription
6.4.4Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.