Newsletter Subscription Endpoint
Route
POST /wp-json/extrachill/v1/newsletter/subscribe
Purpose
Centralizes opt-ins from every signup surface (site header, article footers, blocks) and forwards them to the multisite subscription handler so marketing lists stay synchronized across the network.
Request Body
| Field | Type | Required | Notes |
|---|---|---|---|
email |
string | Yes | Validated via is_email and sanitized with sanitize_email. |
context |
string | Yes | Free-form identifier (e.g., homepage, artist-link-page) that downstream systems use for attribution. |
Processing Flow
- REST schema enforces both arguments and rejects malformed emails before the handler runs.
- Ensures the helper
extrachill_multisite_subscribe()exists (provided by the newsletter/multisite plugin family); missing helpers return500 function_missing. - Passes the sanitized payload to the helper, which handles deduplication, tagging, and third-party sync.
- Responds with the helper’s status message so UIs can display the exact confirmation copy.
Response Contract
Successful requests mirror the helper payload:
{
"success": true,
"message": "Thanks for joining the list!"
}
Failures return WP_Error objects, typically with code subscription_failed and a helper-defined message (e.g., duplicate email, provider outage).
Integration Guidance
- Always send JSON and include the
contextstring so marketing funnels can attribute conversions accurately. - Because the endpoint is public, remember to include REST nonces or application passwords when calling from WordPress-rendered pages to satisfy core security checks.
- Surface the returned
messageverbatim; downstream handlers may localize or customize copy per campaign.