Article Overview
- Category: Developer Extensibility, Webhooks & Custom Code
- Audience: WordPress Developers, Theme Authors & System Integrators
- Applies To: NextGen Smart Data Importer (Community Free & Enterprise Pro Editions)
- Purpose: Comprehensive developer reference for writing custom PHP transformation snippets inside the In-App Function Editor, setting up inbound HTTP Webhooks, and utilizing NextGen core action and filter hooks.
1. Executive Summary
Real-world datasets rarely match a destination database structure perfectly:
- A supplier provides prices with a currency sign (
$49.99 USD) that needs to be stripped down to a clean float (49.99). - Phone numbers must be reformatted into E.164 international format (
+1-555-...). - Categories must be dynamically prepended with parent brand names.
Instead of forcing developers to write custom child theme plugins or deploy code via FTP, NextGen Smart Data Importer provides three levels of developer customization:
- In-App Function Editor: Write and test sandboxed PHP transform functions directly inside the browser.
- Inbound REST Webhooks: Trigger automated import pipelines from external systems (Zapier, Make, n8n, CRM).
- Native WordPress Action & Filter Hooks: Deeply intercept every phase of parsing, mapping, and database persistence.
2. Developer Extension Lifecycle Architecture
3. The In-App Function Editor
The In-App Function Editor lives directly inside Step 2 (Field Mapping). It allows you to wrap any field value with a custom PHP snippet before it is written to MySQL:
┌────────────────────────────────────────────────────────────────────────────────────────┐
│ IN-APP FUNCTION EDITOR (PHP) │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ function nextgen_clean_price( $raw_price ) { │
│ // Remove dollar signs, commas, and currency labels │
│ $clean = preg_replace( '/[^0-9.]/', '', $raw_price ); │
│ return (float) $clean; │
│ } │
├────────────────────────────────────────────────────────────────────────────────────────┤
│ [ Test Function with Sample: "$149.99 USD" ] ➔ Returns: 149.99 (Success) │
└────────────────────────────────────────────────────────────────────────────────────────┘Safety & Sandboxing:
- Syntax Linter: Validates PHP code for syntax errors before saving, preventing fatal errors.
- Error Isolation: If a custom function throws a runtime exception, NextGen catches the error, logs it to the session log, and continues importing subsequent rows safely.
4. Inbound HTTP Webhooks
Trigger automated imports from external web applications, ERPs, or webhook automation tools:
Webhook Endpoint:
POST https://yoursite.com/index.php?rest_route=/nextgen-importer/v1/sync-and-run/{import_id}Authentication:
Pass the secure cron token in the HTTP header or query string:
curl -X POST "https://yoursite.com/index.php?rest_route=/nextgen-importer/v1/sync-and-run/imp_6afe8b?token=YOUR_SECRET_TOKEN"Webhook Response (200 OK):
{
"success": true,
"import_id": "imp_6afe8b",
"status": "queued",
"message": "Background sync and import worker successfully initiated."
}5. Core Action & Filter Hook Reference
Filter: nextgen_importer_field_value
Intercept and transform any mapped field value before insertion:
add_filter('nextgen_importer_field_value', function ($value, $field_name, $row, $importer) {
// Automatically uppercase SKU codes
if ($field_name === '_sku') {
return strtoupper(trim($value));
}
return $value;
}, 10, 4);Action: nextgen_importer_after_post_import
Fires immediately after an entity is published or updated:
add_action('nextgen_importer_after_post_import', function ($post_id, $row, $is_update) {
// Trigger external webhook notification to Slack or CRM
if (!$is_update) {
wp_remote_post('https://hooks.slack.com/services/...', array(
'body' => json_encode(array('text' => "New Product #{$post_id} published via NextGen Importer!"))
));
}
}, 10, 3);6. Frequently Asked Questions (FAQ)
Q: Can I define functions in my child theme functions.php and use them in the importer?
Yes. Any public PHP function registered in your active theme or site plugin can be selected directly in the Field Mapping transformation dropdown.
Q: Are webhooks protected against denial-of-service (DoS)?
Yes. NextGen enforces token validation and process locks (nextgen_import_process_lock). Multiple rapid webhook calls are gracefully queued rather than spawning conflicting duplicate processes.