AJAX Endpoints
The ID Payment Link Generator uses WordPress AJAX endpoints for all dynamic operations. This page documents every registered endpoint, including required parameters, authentication, and response formats. All endpoints are admin-only (no wp_ajax_nopriv_ variants) since the plugin operates entirely within the WordPress dashboard.
Authentication & Security
Every AJAX request must include:
- A valid nonce for CSRF protection (verified via
check_ajax_referer()). - An authenticated WordPress admin session (all endpoints are registered with
wp_ajax_which requires a logged-in user). - The appropriate capability (typically
manage_options).
Requests that fail nonce or capability checks receive a 403 response with {"success": false, "data": {"message": "Security check failed."}}.
Free Version Endpoints
wp_ajax_idplg_send_email
Sends a payment link email to a specified recipient.
| Property | Value |
|---|---|
| Method | POST |
| Nonce | idplg_nonce (passed as nonce parameter) |
| Capability | manage_options |
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
first_name |
string | Yes | Recipient’s first name |
last_name |
string | Yes | Recipient’s last name |
email |
string | Yes | Recipient’s email address (validated) |
amount |
string | No | Payment amount (numeric string) |
template_id |
int | No | Email template ID to use (Pro) |
customer_id |
int | No | Customer ID to associate (Pro) |
auto_save_customer |
bool | No | Whether to auto-save as customer (Pro) |
Success Response:
{
"success": true,
"data": {
"message": "Email sent successfully!"
}
}
Error Response:
{
"success": false,
"data": {
"message": "Failed to send email. Please check your server mail configuration."
}
}
Pro Version Endpoints
wp_ajax_idplg_search_customers
Searches the customer database by name, email, or company. Used by the customer autocomplete dropdown on the generator page.
| Property | Value |
|---|---|
| Method | POST |
| Nonce | idplg_pro_nonce |
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
term |
string | Yes | Search term (minimum 2 characters) |
Success Response:
[
{
"id": 1,
"first_name": "John",
"last_name": "Doe",
"email": "john@example.com",
"company": "Acme Corp",
"label": "John Doe (john@example.com)"
},
{
"id": 2,
"first_name": "Jane",
"last_name": "Doe",
"email": "jane@example.com",
"company": "",
"label": "Jane Doe (jane@example.com)"
}
]
wp_ajax_idplg_save_customer
Creates a new customer or updates an existing one.
| Property | Value |
|---|---|
| Method | POST |
| Nonce | idplg_pro_nonce |
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
id |
int | Yes | Customer ID (use 0 to create new) |
first_name |
string | Yes | Customer’s first name |
last_name |
string | Yes | Customer’s last name |
email |
string | Yes | Customer’s email address |
company |
string | No | Company name |
phone |
string | No | Phone number |
notes |
string | No | Internal notes |
Success Response:
{
"success": true,
"data": {
"id": 15
}
}
wp_ajax_idplg_delete_customer
Deletes a customer record. Associated log entries are preserved but their customer_id is not removed.
| Property | Value |
|---|---|
| Method | POST |
| Nonce | idplg_pro_nonce |
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
id |
int | Yes | Customer ID to delete |
Success Response:
{
"success": true
}
wp_ajax_idplg_get_template
Retrieves a single email template by ID. Used when selecting a template on the generator page.
| Property | Value |
|---|---|
| Method | POST |
| Nonce | idplg_pro_nonce |
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
id |
int | Yes | Template ID |
Success Response:
{
"success": true,
"data": {
"id": 3,
"name": "Standard Invoice",
"subject": "Your Payment Link from {{site_name}}",
"body": "<p>Hello {{first_name}},</p><p>Please click the link below...</p>"
}
}
wp_ajax_idplg_save_template
Creates or updates an email template.
| Property | Value |
|---|---|
| Method | POST |
| Nonce | idplg_pro_nonce |
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
id |
int | Yes | Template ID (use 0 to create new) |
name |
string | Yes | Template display name |
subject |
string | Yes | Email subject line (supports placeholders) |
body |
string | Yes | Email body HTML (supports placeholders) |
is_default |
int | No | Set to 1 to make this the default template |
Success Response:
{
"success": true,
"data": {
"id": 3
}
}
wp_ajax_idplg_delete_template
Deletes an email template. The default template cannot be deleted if it’s the only one remaining.
| Property | Value |
|---|---|
| Method | POST |
| Nonce | idplg_pro_nonce |
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
id |
int | Yes | Template ID to delete |
Success Response:
{
"success": true
}
wp_ajax_idplg_resend_email
Resends an email based on an existing log entry. Reconstructs the email using the original log data and current email settings.
| Property | Value |
|---|---|
| Method | POST |
| Nonce | idplg_pro_nonce |
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
id |
int | Yes | Log entry ID to resend |
Success Response:
{
"success": true,
"data": {
"message": "Email resent successfully!"
}
}
admin_post_idplg_export_csv
Exports email log data as a CSV file download. Unlike the other endpoints, this uses the admin_post_ hook and responds with a file download rather than JSON.
| Property | Value |
|---|---|
| Method | GET |
| Nonce | idplg_export_csv (passed as _wpnonce parameter) |
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
status_filter |
string | No | Filter by status: sent or failed |
date_from |
string | No | Start date (YYYY-MM-DD format) |
date_to |
string | No | End date (YYYY-MM-DD format) |
s |
string | No | Search term (searches name, email, subject) |
Response: CSV file download with headers Content-Type: text/csv and Content-Disposition: attachment; filename="payment-links-log-YYYY-MM-DD.csv".
JavaScript Example
Here’s how to call the idplg_send_email endpoint programmatically using the Fetch API:
/**
* Send a payment link email via the IDPLG AJAX endpoint.
*
* Requires the idplg_data object to be available (localized by the plugin).
* This function should be called from an admin page where the plugin's
* scripts are loaded.
*/
async function sendPaymentLinkEmail( firstName, lastName, email, amount ) {
// Build the form data.
const formData = new FormData();
formData.append( 'action', 'idplg_send_email' );
formData.append( 'nonce', idplg_data.nonce );
formData.append( 'first_name', firstName );
formData.append( 'last_name', lastName );
formData.append( 'email', email );
if ( amount ) {
formData.append( 'amount', amount );
}
try {
const response = await fetch( idplg_data.ajaxUrl, {
method: 'POST',
credentials: 'same-origin',
body: formData,
} );
const result = await response.json();
if ( result.success ) {
console.log( 'Email sent:', result.data.message );
return result.data;
} else {
console.error( 'Send failed:', result.data.message );
throw new Error( result.data.message );
}
} catch ( error ) {
console.error( 'Request error:', error );
throw error;
}
}
// Usage:
sendPaymentLinkEmail( 'John', 'Doe', 'john@example.com', '99.99' )
.then( data => alert( data.message ) )
.catch( err => alert( 'Error: ' + err.message ) );
Note: The
idplg_dataobject is only available on admin pages where the plugin’s scripts are enqueued. If you need to call these endpoints from a custom admin page, use theidplg_admin_page_hooksfilter to include your page, or manually localize the nonce and AJAX URL.
