WC_Tax_Rate_Importer::handle_upload()publicWC 1.0

Handles the CSV upload and initial parsing of the file to prepare for. displaying author import options.

Method of the class: WC_Tax_Rate_Importer{}

No Hooks.

Return

true|false. False if error uploading or invalid file, true otherwise

Usage

$WC_Tax_Rate_Importer = new WC_Tax_Rate_Importer();
$WC_Tax_Rate_Importer->handle_upload();

WC_Tax_Rate_Importer::handle_upload() code WC 8.6.1

public function handle_upload() {
	$file_url = isset( $_POST['file_url'] ) ? wc_clean( wp_unslash( $_POST['file_url'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce already verified in WC_Tax_Rate_Importer::dispatch()

	if ( empty( $file_url ) ) {
		$file = wp_import_handle_upload();

		if ( isset( $file['error'] ) ) {
			$this->set_import_error_message( $file['error'] );

			return false;
		}

		if ( ! wc_is_file_valid_csv( $file['file'], false ) ) {
			// Remove file if not valid.
			wp_delete_attachment( $file['id'], true );

			$this->set_import_error_message( __( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) );

			return false;
		}

		$this->id = absint( $file['id'] );
	} elseif (
		( 0 === stripos( realpath( ABSPATH . $file_url ), ABSPATH ) ) &&
		file_exists( ABSPATH . $file_url )
	) {
		if ( ! wc_is_file_valid_csv( ABSPATH . $file_url ) ) {
			$this->set_import_error_message( __( 'Invalid file type. The importer supports CSV and TXT file formats.', 'woocommerce' ) );

			return false;
		}

		$this->file_url = esc_attr( $file_url );
	} else {
		return false;
	}

	return true;
}