EDD_Export Class

The EDD_Export class, located in  includes/class-edd-export.php is the class that handles all CSV export options. It is a simple-to-extend class that lets you setup the columns you want in the CSV and also easily query the database for any kind of data and map it to the CSV columns.

The base EDD_Export class is not meant to be used as is, but is meant to be extended for each individual export type. For example, EDD has a class called  EDD_Customers_Export that extends the EDD_Export class, and also one called EDD_Payments_Export, as well as one called EDD_Download_History_Export.

Let's take a quick look at the base class:

In order to extend this class for your own custom export method, you simply need to setup the CSV columns and populate an array of day. Let's take a look at the Download History Export class extension:

As you can see, there are only three parts of the class that are needed in the extension:

  1. $export_type - This is simply an ID for the export type that will be used when generating the CSV file name. This is also used in the edd_export_get_data_{type} filter.
  2. csv_cols() - This function simply sets up an associative array of the columns we want our CSV to have. The key is the column ID and the value is the name of the column.
  3.  get_data() - This function is what we use for querying the database and mapping our data to the CSV. Our query can be anything. In the example above we're querying the EDD logs system, but yours could be anything. Notice that we are populating a $data array and that each of the keys match the meys in the csv_cols() function.

Processing the export is simple: