<html lang="it-it" dir="ltr"><head></head><body># Classe di Esportazione EDD

Panoramica
--------

Il sistema di esportazione di Easy Digital Downloads fornisce un framework robusto per la creazione di esportazioni di dati personalizzate. Questa documentazione copre la classe base `Exporter` e come implementare esportatori personalizzati.

Requisiti
------------

- WordPress 6.2+
- Easy Digital Downloads 3.3.8+
- PHP 7.4+

Classe Base di Esportazione
-----------------

La classe `Exporter` si trova nello spazio dei nomi `EDD\Admin\Exports\Exporters` e funge da fondamento per tutte le funzionalità di esportazione di EDD.

### Metodi Richiesti

Quando estendi la classe Exporter, devi implementare questi metodi astratti:

```
abstract protected function get_export_type(): string;
abstract protected function get_data(): array;
abstract protected function get_data_headers(): array;
abstract protected function get_total(): int;
abstract public function set_properties( $request ): void;
```

Creazione di un Esportatore Personalizzato
--------------------------

### 1. Struttura di Base

Crea una classe che estende la classe `Exporter`:

```
&lt;?php

/**
 * Classe Esportatore Personalizzato.
 */
class CustomExporter extends EDD\Admin\Exports\Exporters\Exporter {

	/**
	 * Ottieni il tipo di esportazione.
	 *
	 * @return string Il tipo di esportazione.
	 */
	protected function get_export_type(): string {
		return 'custom_export';
	}

	/**
	 * Imposta le proprietà.
	 *
	 * @param array $request La richiesta.
	 * @return void
	 */
	public function set_properties( $request ): void {
		$this-&gt;start = isset( $request['custom-export-start'] )
			? sanitize_text_field( $request['custom-export-start'] )
			: '';
		$this-&gt;end   = isset( $request['custom-export-end'] )
			? sanitize_text_field( $request['custom-export-end'] )
			: '';
	}

	/**
	 * Ottieni le intestazioni dei dati.
	 *
	 * @return array Le intestazioni dei dati.
	 */
	protected function get_data_headers(): array {
		return array(
			'id'     =&gt; __( 'ID', 'your-text-domain' ),
			'status' =&gt; __( 'Stato', 'your-text-domain' ),
		);
	}

	protected function get_data(): array {
		$data = array();
		$args = array_merge(
			array(
				'number' =&gt; $this-&gt;per_step,
				'offset' =&gt; ( $this-&gt;step * $this-&gt;per_step ) - $this-&gt;per_step,
			),
			$this-&gt;get_base_args()
		);

		// La tua logica di recupero dati qui
		$items = edd_get_orders( $args );

		foreach ( $items as $item ) {
			$data[] = array(
				'id'     =&gt; $item-&gt;id,
				'status' =&gt; $item-&gt;status,
			);
		}

		return $data;
	}

	/**
	 * Ottieni il totale.
	 *
	 * @return int Il totale.
	 */
	protected function get_total(): int {
		return edd_count_orders( $this-&gt;get_base_args() );
	}

	/**
	 * Ottieni gli argomenti base.
	 *
	 * @return array Gli argomenti base.
	 */
	private function get_base_args(): array {
		$args = array();
		if ( ! empty( $this-&gt;start ) || ! empty( $this-&gt;end ) ) {
			$args['date_query'] = $this-&gt;get_date_query();
		}
		return $args;
	}
}
```

### 2. Registrazione del Tuo Esportatore

Crea una classe per gestire la registrazione e la visualizzazione del modulo:

```
/**
 * Registra l'esportatore personalizzato.
 *
 * @param \EDD\Admin\Exports\Registry $registry L'istanza del registro.
 * @return void
 */
function custom_register_export( \EDD\Admin\Exports\Registry $registry ) {
	$registry-&gt;register_exporter(
		'custom_export',
		array(
			'label'       =&gt; __( 'Esportazione Personalizzata', 'your-text-domain' ),
			'description' =&gt; __( 'Esporta dati personalizzati.', 'your-text-domain' ),
			'class'       =&gt; CustomExporter::class,
			'class_path'  =&gt; __DIR__ . '/class-custom-export.php', // Cambia al percorso della tua classe di esportazione.
			'button'      =&gt; __( 'Esporta Dati', 'your-text-domain' ),
		)
	);
}
add_action( 'edd_export_init', 'custom_register_export' );

/**
 * Visualizza il modulo di esportazione personalizzato.
 *
 * @param string $exporter_id L'ID dell'esportatore.
 * @return void
 */
function custom_export_form( $exporter_id ) {
	if ( 'custom_export' !== $exporter_id ) {
		return;
	}

	$from_to = new \EDD\HTML\FromTo(
		array(
			'legend' =&gt; __( 'Data Esportazione Personalizzata', 'your-text-domain' ),
			'id'     =&gt; 'order-export',
		)
	);
	$from_to-&gt;output();
	?&gt;
		&lt;label for="edd_export_custom_status" class="screen-reader-text"&gt;&lt;?php esc_html_e( 'Seleziona Stato', 'your-text-domain' ); ?&gt;&lt;/label&gt;
		&lt;?php
		$statuses = array();
		foreach ( edd_get_payment_statuses() as $status ) {
			if ( 'publish' === $status ) {
				continue;
			}
			$statuses[ $status ] = edd_get_payment_status_label( $status );
		}
		$select = new \EDD\HTML\Select(
			array(
				'id'               =&gt; 'edd_export_custom_status',
				'name'             =&gt; 'status',
				'show_option_all'  =&gt; __( 'Tutti gli Stati', 'your-text-domain' ),
				'show_option_none' =&gt; false,
				'selected'         =&gt; false,
				'options'          =&gt; $statuses,
			)
		);
		$select-&gt;output();
}
add_action( 'edd_export_form', 'custom_export_form' );
```

Con il nuovo registro di esportazione, una volta configurata la tua classe di esportazione insieme al tuo modulo, EDD gestirà automaticamente il processo di esportazione.

Fonti:

- Classe astratta [EDD\\Admin\\Exports\\Exporters\\Exporter](https://github.com/awesomemotive/easy-digital-downloads/blob/main/src/Admin/Exports/Exporters/Exporter.php)
- [Registro di esportazione](https://github.com/awesomemotive/easy-digital-downloads/blob/main/src/Admin/Exports/Registry.php)
- Classe [APIRequests](https://github.com/awesomemotive/easy-digital-downloads/blob/main/src/Admin/Exports/Exporters/APIRequests.php) che utilizza il nuovo esportatore come esempio</body></html>