Documentation · Technical Documentation
AJAX Actions
This document lists the AJAX endpoints registered by the
ADP Car Market Hub plugin via admin-ajax.php, including the
expected nonce, the WordPress capability that protects each handler
and a brief description of the parameters and response.
When to use this document
Read this document if you need to:
- Understand how the front-end interacts with the plugin without full page reloads (model list, test-drive availability, search agent subscription).
- Trace which admin button triggers which background job.
- Integrate or test against a specific AJAX action.
- Audit the security model (capability + nonce) of an admin AJAX handler.
For HTTP REST endpoints, see REST API Endpoints.
Overview
All actions are registered through WordPress's standard
wp_ajax_<action> (logged-in users) and, where applicable,
wp_ajax_nopriv_<action> (anonymous visitors) hooks, and are
served from wp-admin/admin-ajax.php.
The plugin follows the standard pattern:
- Read the
actionquery/POST parameter. - Verify the request nonce with
check_ajax_referer( '<action>', 'nonce' ). - Verify the user capability (admin actions only).
- Sanitise inputs.
- Return JSON via
wp_send_json_success()orwp_send_json_error().
The capability used for nearly all admin-only handlers is
manage_as24_imports (the Plugin::CAP_MANAGE constant). See
Security And Capabilities for the
full capability map.
Public (front-end) AJAX actions
These actions are registered with both wp_ajax_ and
wp_ajax_nopriv_ so anonymous visitors can call them.
as24ci_get_models
Returns the list of vehicle models for a given make, used by the cascading make/model dropdowns in the search filter.
- Method: GET.
- Nonce:
as24ci_get_models(parameter namenonce). - Parameters:
make(string). - Response:
{ "success": true, "data": { "models": [...], "cached": bool } }. - Caching: Results are cached in transients keyed by the normalised make value for 10 minutes. The cache is purged automatically after imports complete.
as24ci_get_test_drive_slots
Returns the available test-drive time slots for a given calendar date.
- Method: GET.
- Nonce:
as24ci_test_drive_slots(parameter namenonce). - Parameters:
dateinY-m-dformat. - Response:
{ "success": true, "data": { "slots": ["09:00", "09:30", ...] } }. An empty array is returned for invalid dates, blackout days, wrong weekdays or past dates.
as24ci_search_agent_subscribe
Creates a search-agent subscription so the visitor receives email notifications when matching vehicles are imported.
- Method: POST.
- Nonce:
as24ci_search_agent(parameter namenonce). - Parameters:
emailplus the saved-searchcriteriafields. - Response: JSON success/error envelope.
Admin AJAX actions
All admin actions require the capability manage_as24_imports
unless stated otherwise. Calls without the capability return HTTP
403 with wp_send_json_error(). Calls without a valid nonce are
rejected by check_ajax_referer().
Import and queue triggers
| Action | Nonce | Purpose |
|---|---|---|
as24ci_trigger_import_now | as24ci_trigger_import_now | Runs the standard scheduled import on demand. Returns the same success, message and counts payload as the cron import REST endpoint. Returns HTTP 429 when an import is already running. |
as24ci_trigger_image_queue_now | as24ci_trigger_image_queue_now | Processes one batch of pending images from the deferred image queue. |
as24ci_clear_image_queue | as24ci_clear_image_queue | Clears all pending images from the queue without importing them. |
as24ci_trigger_ai_queue_now | as24ci_trigger_ai_queue_now | Processes one batch of pending AI Assistant generations. Returns HTTP 400 when the AI Assistant feature is disabled. |
Batch import wizard
The batch wizard lets administrators import a set of listing IDs in small steps to avoid timeouts.
| Action | Nonce | Purpose |
|---|---|---|
as24ci_batch_preflight | as24ci_batch_wizard (Options::BATCH_NONCE_ACTION) | Validates configuration, fetches listings for the configured sellers and prepares a job. Returns HTTP 404 when no listings are found, 400 when no seller IDs are configured. |
as24ci_batch_step | as24ci_batch_wizard | Processes one step of the active batch job. |
as24ci_batch_abort | as24ci_batch_wizard | Aborts an in-progress batch job. |
as24ci_start_import_job | as24ci_import_job | Starts a per-listing import job for a manually supplied list of listing_ids. |
as24ci_step_import_job | as24ci_import_job | Processes the next step of an active per-listing import job. |
Lead management
| Action | Nonce | Purpose |
|---|---|---|
as24ci_update_lead_status | as24ci_update_lead_status | Updates the workflow status of a lead post (lead_id, status). Returns an error when the parameters are missing or the update fails. |
Analytics
| Action | Nonce | Purpose |
|---|---|---|
as24ci_purge_analytics | as24ci_purge_analytics | Truncates collected analytics data on demand. Logged for audit. |
AI Assistant
| Action | Nonce | Purpose |
|---|---|---|
as24ci_generate_ai_assistant | as24ci_ai_generate | Generates AI-assisted text content for a vehicle post. |
A separate non-AJAX admin action (?as24ci_action=manual_ai_generate)
exposes a one-shot manual generation flow protected by a per-post
nonce (as24ci_manual_ai_generate_<post_id>) and the edit_post
capability for that specific post.
Support tab
The Help & Support admin tab exposes three AJAX actions, each
guarded by manage_as24_imports and a dedicated nonce:
| Action | Nonce |
|---|---|
as24ci_ai_support_chat | as24ci_ai_support_chat |
as24ci_contact_support | as24ci_contact_support |
as24ci_ai_kb_maintenance | as24ci_ai_kb_maintenance |
Competitor watcher (removed)
The Competitor Watcher feature has been removed. There is no active AJAX action for refreshing competitor prices; market price comparison is provided by the Market Hub / Hub API.
Calling an AJAX action
Standard WordPress conventions apply. From the front-end:
POST /wp-admin/admin-ajax.php
Content-Type: application/x-www-form-urlencoded
action=as24ci_get_models&nonce=<wp_create_nonce('as24ci_get_models')>&make=Audi
The plugin's enqueued scripts already receive the correct nonces
through wp_localize_script() / wp_add_inline_script(). When
calling an action from a custom integration, generate the nonce
server-side and pass it to your script.
Operational notes
- All non-public actions return HTTP
403with{ "success": false, "data": { "message": "Permission denied." } }when the capability check fails. - Nonce failures are handled by
check_ajax_referer()and result in a403with the standard WordPress nonce error response. - Long-running admin handlers (imports, queue processing) are designed to return promptly; heavier work runs through the scheduler and queue. See Cron Events And Scheduler and Image Importer And Queue.
- The model-list cache is shared across logged-in and anonymous visitors; a single import-time purge keeps both audiences consistent.
- Front-end actions intentionally avoid using user capabilities so anonymous visitors can use the search filter and test-drive booking. Authentication relies on the action-specific nonce.
Troubleshooting
-1or0response body — classic WordPress AJAX failure modes. Check the browser network tab for the response code:-1typically means an invalid nonce,0typically means an unregistered action name (capitalisation matters).Permission denied.(HTTP 403) — the current user lacks the required capability. Verify the user has themanage_as24_importscapability or a role that includes it.- Empty model list when calling
as24ci_get_models— either no models are imported for the supplied make, or the make parameter is empty / not a known taxonomy term. No seller IDs configured.from the batch wizard — open the API tab and add at least one seller ID before re-running.- Stale model list after an import — call
Ajax::clear_models_cache()(the importer already does this on every successful run); check transient storage if your object cache plugin overrides transients.