{"id":24247465,"url":"https://github.com/arraypress/edd-register-exporters","last_synced_at":"2026-02-04T02:08:30.758Z","repository":{"id":271133194,"uuid":"912486565","full_name":"arraypress/edd-register-exporters","owner":"arraypress","description":"A library for easily registering custom exporters in Easy Digital Downloads","archived":false,"fork":false,"pushed_at":"2025-01-06T17:40:16.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-14T23:46:55.833Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arraypress.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-05T17:51:02.000Z","updated_at":"2025-01-06T17:40:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"04f98ec2-16f5-43f1-806b-5de969f33461","html_url":"https://github.com/arraypress/edd-register-exporters","commit_stats":null,"previous_names":["arraypress/edd-register-exporters"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fedd-register-exporters","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fedd-register-exporters/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fedd-register-exporters/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fedd-register-exporters/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arraypress","download_url":"https://codeload.github.com/arraypress/edd-register-exporters/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241877485,"owners_count":20035417,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-14T23:46:14.969Z","updated_at":"2026-02-04T02:08:30.750Z","avatar_url":"https://github.com/arraypress.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EDD Register Custom Exporters\n\nRegister custom batch export classes with metabox forms for Easy Digital Downloads 3.0+ export system.\n\n## Installation\n\n```bash\ncomposer require arraypress/edd-register-exporters\n```\n\n## Basic Usage\n\n### Register Multiple Exporters\n\n```php\n// Register multiple batch exporters with optional metabox forms\nedd_register_custom_batch_exporters( [\n    'customer-analytics' =\u003e [\n        'class'       =\u003e 'EDD_Customer_Analytics_Export',\n        'file'        =\u003e 'exports/class-customer-analytics.php',\n        'title'       =\u003e 'Customer Analytics Export',\n        'description' =\u003e 'Export detailed customer analytics and behavior data.',\n        'fields'      =\u003e [\n            [\n                'type'   =\u003e 'date',\n                'id'     =\u003e 'analytics_date',\n                'name'   =\u003e 'date',\n                'legend' =\u003e 'Select date range'\n            ],\n            [\n                'type' =\u003e 'customer',\n                'id'   =\u003e 'analytics_customer',\n                'name' =\u003e 'customer_id'\n            ]\n        ]\n    ],\n    'product-performance' =\u003e [\n        'class'       =\u003e 'EDD_Product_Performance_Export', \n        'file'        =\u003e 'exports/product-performance.php',\n        'title'       =\u003e 'Product Performance Report',\n        'description' =\u003e 'Analyze product sales performance and metrics.',\n        'fields'      =\u003e [\n            [\n                'type' =\u003e 'product',\n                'id'   =\u003e 'performance_product',\n                'name' =\u003e 'product'\n            ],\n            [\n                'type' =\u003e 'date',\n                'id'   =\u003e 'performance_date',\n                'name' =\u003e 'date'\n            ]\n        ]\n    ],\n    'financial-summary' =\u003e [\n        'class'       =\u003e 'EDD_Financial_Summary_Export',\n        'file'        =\u003e 'exports/financial-summary.php',\n        'title'       =\u003e 'Financial Summary Export',\n        'description' =\u003e 'Export complete financial data for accounting.'\n        // No fields = metabox with just title, description, and export button\n    ]\n], __DIR__ ); // Base path for relative file paths\n```\n\n### Register Single Exporter\n\n```php\n// Register a single batch exporter\nedd_register_custom_batch_exporter(\n    'all-orders',\n    [\n        'class'       =\u003e 'EDD_All_Orders_Export',\n        'file'        =\u003e 'exports/all-orders.php',\n        'title'       =\u003e 'Export All Orders',\n        'description' =\u003e 'Download complete order history.',\n        'fields'      =\u003e [\n            [\n                'type'   =\u003e 'date',\n                'id'     =\u003e 'orders_date',\n                'name'   =\u003e 'date',\n                'legend' =\u003e 'Select date range'\n            ]\n        ]\n    ],\n    __DIR__\n);\n```\n\n## Exports Without Form Fields\n\nIf you don't specify `fields`, the metabox will still render with:\n- Title\n- Description (if provided)\n- Export button\n\nThis is perfect for simple \"export all\" functionality that doesn't need filtering.\n\n```php\nedd_register_custom_batch_exporter(\n    'simple-export',\n    [\n        'class'       =\u003e 'EDD_Simple_Export',\n        'file'        =\u003e 'exports/simple-export.php',\n        'title'       =\u003e 'Export All Data',\n        'description' =\u003e 'Download complete dataset with no filters.'\n        // No fields - just shows a button to trigger export\n    ],\n    __DIR__\n);\n```\n\n## Real-World Examples\n\n### Product Performance with Advanced Filtering\n\n```php\nedd_register_custom_batch_exporters( [\n    'advanced-product-analysis' =\u003e [\n        'class'       =\u003e 'EDD_Advanced_Product_Export',\n        'file'        =\u003e 'exports/advanced-product.php',\n        'title'       =\u003e 'Advanced Product Analysis',\n        'description' =\u003e 'Comprehensive product performance analysis with multiple filters.',\n        'fields'      =\u003e [\n            [\n                'type'     =\u003e 'product',\n                'id'       =\u003e 'analysis_product',\n                'name'     =\u003e 'product',\n                'multiple' =\u003e true\n            ],\n            [\n                'type'   =\u003e 'date',\n                'id'     =\u003e 'analysis_date',\n                'name'   =\u003e 'date',\n                'legend' =\u003e 'Select date range'\n            ],\n            [\n                'type' =\u003e 'country',\n                'id'   =\u003e 'analysis_country',\n                'name' =\u003e 'country'\n            ],\n            [\n                'type' =\u003e 'order_statuses',\n                'id'   =\u003e 'analysis_status',\n                'name' =\u003e 'status'\n            ]\n        ]\n    ]\n], __DIR__ );\n\n// Export class that uses all the form data\nclass EDD_Advanced_Product_Export extends EDD_Batch_Export {\n\n    public $export_type = 'advanced_product_analysis';\n\n    public function csv_cols() {\n        return [\n            'product_id'        =\u003e __( 'Product ID', 'textdomain' ),\n            'product_name'      =\u003e __( 'Product Name', 'textdomain' ),\n            'filtered_sales'    =\u003e __( 'Sales', 'textdomain' ),\n            'filtered_earnings' =\u003e __( 'Earnings', 'textdomain' ),\n            'avg_sale_value'    =\u003e __( 'Avg Sale', 'textdomain' ),\n            'conversion_rate'   =\u003e __( 'Conversion', 'textdomain' ),\n            'total_views'       =\u003e __( 'Views', 'textdomain' ),\n            'price'             =\u003e __( 'Price', 'textdomain' ),\n            'created_date'      =\u003e __( 'Created', 'textdomain' ),\n        ];\n    }\n\n    public function get_data() {\n        $downloads = get_posts( [\n            'post_type'      =\u003e 'download',\n            'post_status'    =\u003e 'publish',\n            'posts_per_page' =\u003e 15,\n            'offset'         =\u003e ( $this-\u003estep - 1 ) * 15,\n            'post__in'       =\u003e $this-\u003eget_filtered_products()\n        ] );\n\n        if ( empty( $downloads ) ) {\n            return false;\n        }\n\n        $data = [];\n\n        foreach ( $downloads as $download ) {\n            // Get filtered sales data\n            $payment_args = [\n                'download' =\u003e $download-\u003eID,\n                'number'   =\u003e -1\n            ];\n\n            // Apply date filters\n            if ( ! empty( $this-\u003estart ) ) {\n                $payment_args['start_date'] = $this-\u003estart;\n            }\n\n            if ( ! empty( $this-\u003eend ) ) {\n                $payment_args['end_date'] = $this-\u003eend;\n            }\n\n            // Apply status filter\n            if ( ! empty( $_REQUEST['status'] ) ) {\n                $payment_args['status'] = sanitize_text_field( $_REQUEST['status'] );\n            }\n\n            $payments = edd_get_payments( $payment_args );\n\n            // Filter by country if specified\n            if ( ! empty( $_REQUEST['country'] ) ) {\n                $country = sanitize_text_field( $_REQUEST['country'] );\n                $payments = array_filter( $payments, function( $payment ) use ( $country ) {\n                    $address = $payment-\u003eaddress;\n                    return isset( $address['country'] ) \u0026\u0026 $address['country'] === $country;\n                } );\n            }\n\n            $filtered_sales = count( $payments );\n            $filtered_earnings = array_sum( array_map( function( $payment ) {\n                return $payment-\u003etotal;\n            }, $payments ) );\n\n            // Get conversion data\n            $views = get_post_meta( $download-\u003eID, '_edd_download_views', true ) ?: 1;\n            $conversion_rate = round( ( $filtered_sales / $views ) * 100, 2 );\n\n            $data[] = [\n                'product_id'         =\u003e $download-\u003eID,\n                'product_name'       =\u003e $download-\u003epost_title,\n                'filtered_sales'     =\u003e $filtered_sales,\n                'filtered_earnings'  =\u003e $filtered_earnings,\n                'avg_sale_value'     =\u003e $filtered_sales \u003e 0 ? round( $filtered_earnings / $filtered_sales, 2 ) : 0,\n                'conversion_rate'    =\u003e $conversion_rate . '%',\n                'total_views'        =\u003e $views,\n                'price'              =\u003e edd_get_download_price( $download-\u003eID ),\n                'created_date'       =\u003e $download-\u003epost_date\n            ];\n        }\n\n        return $data;\n    }\n\n    public function get_percentage_complete() {\n        $total = wp_count_posts( 'download' )-\u003epublish;\n        $percentage = ( $total \u003e 0 ) ? ( ( 15 * $this-\u003estep ) / $total ) * 100 : 100;\n        return min( $percentage, 100 );\n    }\n\n    public function set_properties( $request ) {\n        $this-\u003estart = isset( $request['date-start'] ) ? sanitize_text_field( $request['date-start'] ) : '';\n        $this-\u003eend   = isset( $request['date-end'] ) ? sanitize_text_field( $request['date-end'] ) : '';\n    }\n\n    private function get_filtered_products() {\n        if ( ! empty( $_REQUEST['product'] ) ) {\n            $products = (array) $_REQUEST['product'];\n            return array_map( 'absint', $products );\n        }\n\n        return null; // No filter applied\n    }\n}\n```\n\n### Customer Segmentation Export\n\n```php\nedd_register_custom_batch_exporters( [\n    'customer-segments' =\u003e [\n        'class'       =\u003e 'EDD_Customer_Segments_Export',\n        'file'        =\u003e 'exports/customer-segments.php',\n        'title'       =\u003e 'Customer Segmentation Export',\n        'description' =\u003e 'Export customers grouped by spending behavior and engagement.',\n        'fields'      =\u003e [\n            [\n                'type'    =\u003e 'select',\n                'id'      =\u003e 'segment_type',\n                'name'    =\u003e 'segment',\n                'options' =\u003e [\n                    ''             =\u003e 'All Segments',\n                    'high_value'   =\u003e 'High Value ($500+)',\n                    'medium_value' =\u003e 'Medium Value ($100-$499)',\n                    'low_value'    =\u003e 'Low Value ($1-$99)',\n                    'single_buyer' =\u003e 'Single Purchase Only',\n                    'repeat_buyer' =\u003e 'Repeat Buyers (2+)',\n                    'inactive'     =\u003e 'Inactive (6+ months)'\n                ]\n            ],\n            [\n                'type'   =\u003e 'date',\n                'id'     =\u003e 'segment_date',\n                'name'   =\u003e 'date',\n                'legend' =\u003e 'Select date range'\n            ]\n        ]\n    ]\n], __DIR__ );\n```\n\n### Simple Export (No Filters)\n\n```php\nedd_register_custom_batch_exporter(\n    'complete-database',\n    [\n        'class'       =\u003e 'EDD_Complete_Database_Export',\n        'file'        =\u003e 'exports/complete-database.php',\n        'title'       =\u003e 'Complete Database Export',\n        'description' =\u003e 'Export entire EDD database for backup or migration.'\n        // No fields needed - one-click export\n    ],\n    __DIR__\n);\n```\n\n## Available Field Types\n\n| Type | Description | Form Control |\n|------|-------------|--------------|\n| `customer` | Customer dropdown | Single or multiple customer selection |\n| `product` | Product dropdown | Single or multiple product selection |\n| `country` | Country selector | Country dropdown |\n| `region` | Region selector | Region dropdown |\n| `order_statuses` | Payment status | Order status dropdown |\n| `date` | Date range picker | Start and end date fields |\n| `month_year` | Month/year dropdowns | Month and year selectors |\n| `select` | Custom dropdown | Custom options dropdown |\n| `text` | Text input | Text input field |\n| `separator` | Visual separator | Styling element |\n\n## Configuration Options\n\n| Option | Required | Description |\n|--------|----------|-------------|\n| `class` | **Yes** | PHP class name that extends `EDD_Batch_Export` |\n| `file` | **Yes** | Path to file containing the class |\n| `title` | No | Display title for metabox (auto-generated from key if omitted) |\n| `description` | No | Description shown in metabox |\n| `fields` | No | Array of form fields (metabox renders with or without fields) |\n| `label` | No | Alternative to title |\n\n## Form Data Access\n\nIn your export class, access form data through:\n\n- `$this-\u003estart` and `$this-\u003eend` - Date range fields (set via `set_properties()`)\n- `$_REQUEST['field_name']` - Other form fields\n- `set_properties( $request )` - Method to process and store form data\n\nExample:\n```php\npublic function set_properties( $request ) {\n    $this-\u003estart  = isset( $request['date-start'] ) ? sanitize_text_field( $request['date-start'] ) : '';\n    $this-\u003eend    = isset( $request['date-end'] ) ? sanitize_text_field( $request['date-end'] ) : '';\n    $this-\u003estatus = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : '';\n}\n```\n\n## API Functions\n\n### `edd_register_custom_batch_exporter()`\n\nRegister a single batch exporter.\n\n```php\nedd_register_custom_batch_exporter( string $key, array $export, ?string $base_path = null )\n```\n\n**Parameters:**\n- `$key` (string) - Unique identifier for the export\n- `$export` (array) - Export configuration\n- `$base_path` (string|null) - Optional base path for the export file\n\n**Returns:** `bool|WP_Error` - True on success, WP_Error on failure\n\n### `edd_register_custom_batch_exporters()`\n\nRegister multiple batch exporters at once.\n\n```php\nedd_register_custom_batch_exporters( array $exports, ?string $base_path = null )\n```\n\n**Parameters:**\n- `$exports` (array) - Associative array of export configurations\n- `$base_path` (string|null) - Optional base path for export files\n\n**Returns:** `bool|WP_Error` - True on success, WP_Error on failure\n\n## Requirements\n\n- PHP 8.0+\n- WordPress 5.0+\n- Easy Digital Downloads 3.0+\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the GPL-2.0-or-later License.\n\n## Support\n\n- [Documentation](https://github.com/arraypress/edd-register-batch-exporters)\n- [Issue Tracker](https://github.com/arraypress/edd-register-batch-exporters/issues)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farraypress%2Fedd-register-exporters","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farraypress%2Fedd-register-exporters","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farraypress%2Fedd-register-exporters/lists"}