WC_Product_Download::check_is_valid()publicWC 1.0

Confirms that the download is of an allowed filetype, that it exists and that it is contained within an approved directory. Used before adding to a product's list of downloads.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$WC_Product_Download = new WC_Product_Download();
$WC_Product_Download->check_is_valid( $auto_add_to_approved_directory_list );
$auto_add_to_approved_directory_list(true|false)
If the download is not already in the approved directory list, automatically add it if possible.
По умолчанию: true

Код WC_Product_Download::check_is_valid() WC 8.7.0

public function check_is_valid( bool $auto_add_to_approved_directory_list = true ) {
	$download_file = $this->get_file();

	if ( ! $this->data['enabled'] ) {
		throw new Exception(
			sprintf(
				/* translators: %s: Downloadable file. */
				__( 'The downloadable file %s cannot be used as it has been disabled.', 'woocommerce' ),
				'<code>' . basename( $download_file ) . '</code>'
			)
		);
	}

	if ( ! $this->is_allowed_filetype() ) {
		throw new Exception(
			sprintf(
				/* translators: 1: Downloadable file, 2: List of allowed filetypes. */
				__( 'The downloadable file %1$s cannot be used as it does not have an allowed file type. Allowed types include: %2$s', 'woocommerce' ),
				'<code>' . basename( $download_file ) . '</code>',
				'<code>' . implode( ', ', array_keys( $this->get_allowed_mime_types() ) ) . '</code>'
			)
		);
	}

	// Validate the file exists.
	if ( ! $this->file_exists() ) {
		$this->raise_invalid_file_exception( $download_file );
	}

	$this->approved_directory_checks( $auto_add_to_approved_directory_list );
}