WC_Product_CSV_Importer_Controller::check_file_path()protected staticWC 9.3.0

Runs before controller actions to check that the file used during the import is valid.

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

Хуков нет.

Возвращает

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

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

$result = WC_Product_CSV_Importer_Controller::check_file_path( $path ): void;
$path(строка) (обязательный)
Path to test.

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

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

Код WC_Product_CSV_Importer_Controller::check_file_path() WC 9.4.2

protected static function check_file_path( string $path ): void {
	$wp_filesystem = FilesystemUtil::get_wp_filesystem();

	// File must exist and be readable.
	$is_valid_file = $wp_filesystem->is_readable( $path );

	// Check that file is within an allowed location.
	if ( $is_valid_file ) {
		$is_valid_file = self::file_is_in_directory( $path, $wp_filesystem->abspath() );
		if ( ! $is_valid_file ) {
			$upload_dir    = wp_get_upload_dir();
			$is_valid_file = false === $upload_dir['error'] && self::file_is_in_directory( $path, $upload_dir['basedir'] );
		}
	}

	if ( ! $is_valid_file ) {
		throw new \Exception( esc_html__( 'File path provided for import is invalid.', 'woocommerce' ) );
	}

	if ( ! self::is_file_valid_csv( $path ) ) {
		throw new \Exception( esc_html__( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) );
	}
}