Easy Digital Downloads
  • Package
  • Class
  • Tree

Packages

  • EDD
    • Admin
      • Actions
      • Add-ons
      • Dashboard
      • Discounts
      • Downloads
      • Export
      • Notices
      • Pages
      • Payments
      • Reports
      • Settings
      • System
      • Upgrades
      • Upload
      • Welcome
    • Cart
    • Checkout
    • Classes
      • API
      • Fees
      • HTML
      • Roles
      • Session
    • Emails
    • Functions
      • AJAX
      • Compatibility
      • Errors
      • Formatting
      • Install
      • Login
      • Taxes
      • Templates
    • Gateways
    • Logging
    • Payments
    • Shortcodes
    • Widgets

Classes

  • EDD_API_Request_Log_Table
  • EDD_Customer_Reports_Table
  • EDD_Customers_Export
  • EDD_Download_History_Export
  • EDD_Download_Reports_Table
  • EDD_Export
  • EDD_File_Downloads_Log_Table
  • EDD_Gateway_Error_Log_Table
  • EDD_Payments_Export
  • EDD_Sales_Log_Table

Functions

  • edd_draw_chart_image
  • edd_estimated_monthly_stats
  • edd_generate_pdf
  • edd_get_report_dates
  • edd_log_default_views
  • edd_log_views
  • edd_logs_view_api_requests
  • edd_logs_view_file_downloads
  • edd_logs_view_gateway_errors
  • edd_logs_view_sales
  • edd_parse_report_dates
  • edd_report_views
  • edd_reporting_contextual_help
  • edd_reports_customers_table
  • edd_reports_default_views
  • edd_reports_downloads_table
  • edd_reports_earnings
  • edd_reports_graph
  • edd_reports_graph_controls
  • edd_reports_page
  • edd_reports_tab_export
  • edd_reports_tab_logs
  • edd_reports_tab_reports
  • edd_reports_taxes
  1 <?php
  2 /**
  3  * Customers Export Class
  4  *
  5  * This class handles customer export
  6  *
  7  * @package     EDD
  8  * @subpackage  Admin/Reports
  9  * @copyright   Copyright (c) 2013, Pippin Williamson
 10  * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 11  * @since       1.4.4
 12  */
 13 
 14 // Exit if accessed directly
 15 if ( ! defined( 'ABSPATH' ) ) exit;
 16 
 17 /**
 18  * EDD_Customers_Export Class
 19  *
 20  * @since 1.4.4
 21  */
 22 class EDD_Customers_Export extends EDD_Export {
 23     /**
 24      * Our export type. Used for export-type specific filters/actions
 25      *
 26      * @var string
 27      * @since 1.4.4
 28      */
 29     public $export_type = 'customers';
 30 
 31     /**
 32      * Set the export headers
 33      *
 34      * @access public
 35      * @since 1.4.4
 36      * @return void
 37      */
 38     public function headers() {
 39         ignore_user_abort( true );
 40 
 41         if ( ! edd_is_func_disabled( 'set_time_limit' ) && ! ini_get( 'safe_mode' ) )
 42             set_time_limit( 0 );
 43 
 44         $extra = '';
 45 
 46         if ( ! empty( $_POST['edd_export_download'] ) ) {
 47             $extra = sanitize_title( get_the_title( absint( $_POST['edd_export_download'] ) ) ) . '-';
 48         }
 49 
 50         nocache_headers();
 51         header( 'Content-Type: text/csv; charset=utf-8' );
 52         header( 'Content-Disposition: attachment; filename=edd-export-' . $extra . $this->export_type . '-' . date( 'm-d-Y' ) . '.csv' );
 53         header( "Expires: 0" );
 54     }
 55 
 56     /**
 57      * Set the CSV columns
 58      *
 59      * @access public
 60      * @since 1.4.4
 61      * @return array $cols All the columns
 62      */
 63     public function csv_cols() {
 64         if ( ! empty( $_POST['edd_export_download'] ) ) {
 65             $cols = array(
 66                 'name'      => __( 'Name',   'edd' ),
 67                 'email'     => __( 'Email', 'edd' ),
 68                 'date'      => __( 'Date Purchased', 'edd' )
 69             );
 70         } else {
 71             $cols = array(
 72                 'name'      => __( 'Name',   'edd' ),
 73                 'email'     => __( 'Email', 'edd' ),
 74                 'purchases' => __( 'Total Purchases', 'edd' ),
 75                 'amount'    => __( 'Total Purchased', 'edd' )
 76             );
 77         }
 78 
 79         return $cols;
 80     }
 81 
 82     /**
 83      * Get the Export Data
 84      *
 85      * @access public
 86      * @since 1.4.4
 87      * @global object $wpdb Used to query the database using the WordPress
 88      *   Database API
 89      * @global object $edd_logs EDD Logs Object
 90      * @return array $data The data for the CSV file
 91      */
 92     public function get_data() {
 93         global $wpdb;
 94 
 95         $data = array();
 96 
 97         if ( ! empty( $_POST['edd_export_download'] ) ) {
 98             // Export customers of a specific product
 99             global $edd_logs;
100 
101             $args = array(
102                 'post_parent'  => absint( $_POST['edd_export_download'] ),
103                 'log_type'     => 'sale',
104                 'no_paging'    => true
105             );
106 
107             $logs = $edd_logs->get_connected_logs( $args );
108 
109             if ( $logs ) {
110                 foreach ( $logs as $log ) {
111                     $payment_id = get_post_meta( $log->ID, '_edd_log_payment_id', true );
112                     $email      = edd_get_payment_user_email( $payment_id );
113 
114                     $wp_user = get_user_by( 'email', $email );
115 
116                     $data[] = array(
117                         'name'      => $wp_user ? $wp_user->display_name : __( 'Guest', 'edd' ),
118                         'email'     => $email,
119                         'date'      => $log->post_date
120                     );
121                 }
122             }
123         } else {
124             // Export all customers
125             $emails = $wpdb->get_col( "SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = '_edd_payment_user_email' " );
126 
127             foreach ( $emails as $email ) {
128                 $wp_user = get_user_by( 'email', $email );
129 
130                 $data[] = array(
131                     'name'      => $wp_user ? $wp_user->display_name : __( 'Guest', 'edd' ),
132                     'email'     => $email,
133                     'purchases' => edd_count_purchases_of_customer( $email ),
134                     'amount'    => html_entity_decode( edd_currency_filter( edd_format_amount( edd_purchase_total_of_user( $email ) ) ) )
135                 );
136             }
137         }
138 
139         $data = apply_filters( 'edd_export_get_data', $data );
140         $data = apply_filters( 'edd_export_get_data_' . $this->export_type, $data );
141 
142         return $data;
143     }
144 }
Easy Digital Downloads API documentation generated by ApiGen 2.8.0