WC_Product_CSV_Importer_Controller::handle_upload()publicWC 1.0

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

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

Хуков нет.

Возвращает

Строку|WP_Error.

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

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

Код WC_Product_CSV_Importer_Controller::handle_upload() WC 9.7.1

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

	try {
		if ( ! empty( $file_url ) ) {
			$path = ABSPATH . $file_url;
			self::check_file_path( $path );
		} else {
			$csv_import_util = wc_get_container()->get( Automattic\WooCommerce\Internal\Admin\ImportExport\CSVUploadHelper::class );
			$upload          = $csv_import_util->handle_csv_upload( 'product', 'import', self::get_valid_csv_filetypes() );
			$path            = $upload['file'];
		}

		return $path;
	} catch ( \Exception $e ) {
		return new \WP_Error( 'woocommerce_product_csv_importer_upload_invalid_file', $e->getMessage() );
	}
}