{"id":34910581,"url":"https://github.com/arraypress/edd-register-recount-tools","last_synced_at":"2026-05-25T05:37:01.087Z","repository":{"id":327947807,"uuid":"1020840071","full_name":"arraypress/edd-register-recount-tools","owner":"arraypress","description":"A library for registering custom recount tools in Easy Digital Downloads admin area.","archived":false,"fork":false,"pushed_at":"2025-12-10T11:16:28.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-10T15:46:18.147Z","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-07-16T13:25:35.000Z","updated_at":"2025-12-10T11:16:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"0df8c76a-b48e-468b-a18c-877638ea3f2a","html_url":"https://github.com/arraypress/edd-register-recount-tools","commit_stats":null,"previous_names":["arraypress/edd-register-recount-tools"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/arraypress/edd-register-recount-tools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fedd-register-recount-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fedd-register-recount-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fedd-register-recount-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fedd-register-recount-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arraypress","download_url":"https://codeload.github.com/arraypress/edd-register-recount-tools/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arraypress%2Fedd-register-recount-tools/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33462501,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-25T02:24:28.008Z","status":"ssl_error","status_checked_at":"2026-05-25T02:23:23.339Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-12-26T11:08:21.035Z","updated_at":"2026-05-25T05:37:01.082Z","avatar_url":"https://github.com/arraypress.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EDD Recount Tools - Register Custom Recount Tools\n\nAdd custom recount/batch processing tools to Easy Digital Downloads admin Tools page.\n\n## Installation\n\n```bash\ncomposer require arraypress/edd-register-recount-tools\n```\n\n## Basic Usage (Simple Callbacks)\n\n```php\n// Register callback-based recount tools (recommended)\nedd_register_recount_tools( [\n    'recount-customer-downloads' =\u003e [\n        'label'          =\u003e 'Customer Download Counts',\n        'description'    =\u003e 'Recalculates the total number of file downloads for each customer.',\n        'batch_size'     =\u003e 20,\n        'count_callback' =\u003e function() {\n            return edd_count_customers();\n        },\n        'callback'       =\u003e function( $offset, $batch_size ) {\n            $customers = edd_get_customers( [\n                'number' =\u003e $batch_size,\n                'offset' =\u003e $offset,\n                'fields' =\u003e 'id'\n            ] );\n\n            foreach ( $customers as $customer_id ) {\n                $customer = new EDD_Customer( $customer_id );\n                \n                // Count file downloads for this customer\n                $download_count = edd_count_file_downloads_of_customer( $customer-\u003eid );\n                \n                // Update customer meta\n                edd_update_customer_meta( $customer-\u003eid, 'total_downloads', $download_count );\n                \n                edd_debug_log( sprintf( 'Updated download count for customer #%d: %d downloads', $customer-\u003eid, $download_count ) );\n            }\n\n            return $customers; // Return the processed items\n        }\n    ],\n    'recount-product-reviews' =\u003e [\n        'label'          =\u003e 'Product Review Counts',\n        'description'    =\u003e 'Updates the review count and average rating for all downloads.',\n        'batch_size'     =\u003e 10,\n        'count_callback' =\u003e function() {\n            return wp_count_posts( 'download' )-\u003epublish;\n        },\n        'callback'       =\u003e function( $offset, $batch_size ) {\n            $downloads = get_posts( [\n                'post_type'      =\u003e 'download',\n                'posts_per_page' =\u003e $batch_size,\n                'offset'         =\u003e $offset,\n                'fields'         =\u003e 'ids'\n            ] );\n\n            foreach ( $downloads as $download_id ) {\n                // Count reviews\n                $review_count = get_comments_number( $download_id );\n                \n                // Calculate average rating\n                $reviews = get_comments( [\n                    'post_id'      =\u003e $download_id,\n                    'meta_key'     =\u003e 'rating',\n                    'meta_compare' =\u003e 'EXISTS'\n                ] );\n\n                $total_rating = 0;\n                $rating_count = 0;\n\n                foreach ( $reviews as $review ) {\n                    $rating = get_comment_meta( $review-\u003ecomment_ID, 'rating', true );\n                    if ( $rating ) {\n                        $total_rating += (int) $rating;\n                        $rating_count++;\n                    }\n                }\n\n                $average_rating = $rating_count \u003e 0 ? round( $total_rating / $rating_count, 2 ) : 0;\n\n                // Update post meta\n                update_post_meta( $download_id, '_edd_review_count', $review_count );\n                update_post_meta( $download_id, '_edd_average_rating', $average_rating );\n            }\n\n            return $downloads;\n        }\n    ]\n] );\n```\n\n## Real Examples\n\n### Sync Customer Data with CRM\n\n```php\nedd_register_recount_tools( [\n    'sync-crm-data' =\u003e [\n        'label'          =\u003e 'Sync CRM Data',\n        'description'    =\u003e 'Synchronizes customer purchase data with external CRM system.',\n        'batch_size'     =\u003e 5, // Smaller batches for API calls\n        'count_callback' =\u003e function() {\n            return edd_count_customers();\n        },\n        'callback'       =\u003e function( $offset, $batch_size ) {\n            $customers = edd_get_customers( [\n                'number' =\u003e $batch_size,\n                'offset' =\u003e $offset\n            ] );\n\n            foreach ( $customers as $customer ) {\n                // Prepare customer data for CRM\n                $crm_data = [\n                    'email'         =\u003e $customer-\u003eemail,\n                    'name'          =\u003e $customer-\u003ename,\n                    'total_spent'   =\u003e $customer-\u003epurchase_value,\n                    'order_count'   =\u003e $customer-\u003epurchase_count,\n                    'last_purchase' =\u003e $customer-\u003edate_created\n                ];\n\n                // Send to CRM\n                $response = wp_remote_post( 'https://your-crm.com/api/customers', [\n                    'body' =\u003e json_encode( $crm_data ),\n                    'headers' =\u003e [\n                        'Content-Type' =\u003e 'application/json',\n                        'Authorization' =\u003e 'Bearer ' . get_option( 'crm_api_key' )\n                    ]\n                ] );\n\n                if ( is_wp_error( $response ) ) {\n                    edd_debug_log( sprintf( 'CRM sync failed for customer #%d: %s', $customer-\u003eid, $response-\u003eget_error_message() ), true );\n                } else {\n                    // Mark as synced\n                    edd_update_customer_meta( $customer-\u003eid, 'crm_synced', current_time( 'timestamp' ) );\n                }\n\n                // Rate limiting\n                sleep( 1 );\n            }\n\n            return array_column( $customers, 'id' );\n        }\n    ]\n] );\n```\n\n### Update Custom Fields\n\n```php\nedd_register_recount_tools( [\n    'update-lifetime-value' =\u003e [\n        'label'          =\u003e 'Calculate Lifetime Value',\n        'description'    =\u003e 'Calculates and updates customer lifetime value predictions.',\n        'batch_size'     =\u003e 15,\n        'count_callback' =\u003e function() {\n            return edd_count_customers();\n        },\n        'callback'       =\u003e function( $offset, $batch_size ) {\n            $customers = edd_get_customers( [\n                'number' =\u003e $batch_size,\n                'offset' =\u003e $offset\n            ] );\n\n            foreach ( $customers as $customer ) {\n                if ( $customer-\u003epurchase_count \u003c 2 ) {\n                    $ltv = $customer-\u003epurchase_value;\n                } else {\n                    // Complex LTV calculation\n                    $payments = edd_get_payments( [\n                        'customer' =\u003e $customer-\u003eid,\n                        'status'   =\u003e 'publish',\n                        'number'   =\u003e -1\n                    ] );\n                    \n                    $purchase_dates = array_map( function( $payment ) {\n                        return strtotime( $payment-\u003edate );\n                    }, $payments );\n                    \n                    sort( $purchase_dates );\n                    \n                    // Calculate average time between purchases\n                    $intervals = [];\n                    for ( $i = 1; $i \u003c count( $purchase_dates ); $i++ ) {\n                        $intervals[] = $purchase_dates[$i] - $purchase_dates[$i-1];\n                    }\n                    \n                    $avg_interval = array_sum( $intervals ) / count( $intervals );\n                    $avg_days = $avg_interval / DAY_IN_SECONDS;\n                    \n                    // Predict 2 years of purchases\n                    $predicted_purchases = (365 * 2) / $avg_days;\n                    $avg_order_value = $customer-\u003epurchase_value / $customer-\u003epurchase_count;\n                    \n                    $ltv = round( $predicted_purchases * $avg_order_value, 2 );\n                }\n\n                // Update customer meta\n                edd_update_customer_meta( $customer-\u003eid, 'predicted_ltv', $ltv );\n            }\n\n            return array_column( $customers, 'id' );\n        }\n    ]\n] );\n```\n\n## Advanced Usage (Custom Classes)\n\nFor complex processing, you can still use custom classes:\n\n```php\nedd_register_recount_tools( [\n    'complex-recount' =\u003e [\n        'class'       =\u003e 'EDD_Batch_Complex_Recount',\n        'file'        =\u003e __DIR__ . '/includes/class-complex-recount.php',\n        'label'       =\u003e 'Complex Data Processing',\n        'description' =\u003e 'Performs complex multi-step data processing.'\n    ]\n] );\n```\n\n## Configuration Options\n\n### Callback-Based Tools\n\n| Option | Required | Description |\n|--------|----------|-------------|\n| `callback` | **Yes** | Function that processes items (`function($offset, $batch_size)`) |\n| `count_callback` | **Yes** | Function that returns total item count |\n| `label` | No | Display name (auto-generated from key if not provided) |\n| `description` | No | Description shown in admin interface |\n| `batch_size` | No | Items per batch (default: 20) |\n\n### Class-Based Tools\n\n| Option | Required | Description |\n|--------|----------|-------------|\n| `class` | **Yes** | PHP class name that extends `EDD_Batch_Export` |\n| `file` | **Yes** | Full path to file containing the class |\n| `label` | No | Display name (auto-generated from key if not provided) |\n| `description` | No | Description shown in admin interface |\n\n## Callback Guidelines\n\n1. **Return processed items** - Your callback should return the items it processed\n2. **Handle pagination** - Use `$offset` and `$batch_size` parameters\n3. **Keep batches small** - 10-50 items per batch to avoid timeouts\n4. **Include logging** - Use `edd_debug_log()` for progress tracking\n5. **Handle errors gracefully** - Use try/catch blocks\n6. **Rate limiting** - Add delays for external API calls\n\n## Requirements\n\n- PHP 7.4+\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-custom-stats)\n- [Issue Tracker](https://github.com/arraypress/edd-register-custom-stats/issues)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farraypress%2Fedd-register-recount-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farraypress%2Fedd-register-recount-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farraypress%2Fedd-register-recount-tools/lists"}