WC_Product_Download::is_allowed_filetype()publicWC 1.0

Check if file is allowed.

{} Это метод класса: WC_Product_Download{}

Хуков нет.

Возвращает

true|false.

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

$WC_Product_Download = new WC_Product_Download();
$WC_Product_Download->is_allowed_filetype();

Код WC_Product_Download::is_allowed_filetype() WC 6.4.1

public function is_allowed_filetype() {
	$file_path = $this->get_file();

	// File types for URL-based files located on the server should get validated.
	$parsed_file_path  = WC_Download_Handler::parse_file_path( $file_path );
	$is_file_on_server = ! $parsed_file_path['remote_file'];
	$file_path_type    = $this->get_type_of_file_path( $file_path );

	// Shortcodes are allowed, validations should be done by the shortcode provider in this case.
	if ( 'shortcode' === $file_path_type ) {
		return true;
	}

	// Remote paths are allowed.
	if ( ! $is_file_on_server && 'relative' !== $file_path_type ) {
		return true;
	}

	// On windows system, local files ending with `.` are not allowed.
	// @link https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN#naming-conventions.
	if ( $is_file_on_server && ! $this->get_file_extension() && 'WIN' === strtoupper( substr( Constants::get_constant( 'PHP_OS' ), 0, 3 ) ) ) {
		if ( '.' === substr( $file_path, -1 ) ) {
			return false;
		}
	}

	return ! $this->get_file_extension() || in_array( $this->get_file_type(), $this->get_allowed_mime_types(), true );
}