Developer overview
This page describes how Stacko Forms is put together, so you can extend it safely. The plugin is pre-release; internal details may change before 1.0.
Requirements
Section titled “Requirements”| Minimum | |
|---|---|
| WordPress | 7.0 |
| PHP | 8.1 |
| Multisite | Supported (per-site tables) |
Composer is only used for development tooling. The plugin runs without a vendor/ directory.
Architecture
Section titled “Architecture”| Part | Technology | Location |
|---|---|---|
| PHP core | PSR-4 classes in the Stacko\Forms namespace, autoloaded from includes/ |
includes/ |
| Admin app | Vue 3 + TypeScript + Pinia + Tailwind CSS v4, built with Vite | admin/src → build/admin |
| Visitor runtime | Vanilla TypeScript and plain CSS, no jQuery | frontend/src → build/frontend |
| Block | Plain JavaScript using WordPress globals, no build step | blocks/form |
| Form schema | JSON Schema for form definitions | schema/form.schema.json |
The admin is a single page (admin.php?page=stacko-forms) that mounts the Vue app. It talks to the server only through the REST API. Vue and Tailwind are never loaded on the visitor’s site.
Main modules in includes/
Section titled “Main modules in includes/”| Namespace | Responsibility |
|---|---|
Core |
Bootstrapping (Plugin), activation/deactivation, global Settings, Logger, admin asset loading |
Database |
Installer (tables, migrations) and repositories for forms, entries and the email log |
Forms |
FieldRegistry, field type classes in Fields/, SchemaValidator, server-side conditional Logic, built-in Templates |
Frontend |
Renderer, Shortcode, Block, FormPage (standalone form URL), Preview, front-end Assets |
Submission |
SubmissionHandler, SpamProtection, signed Token, no-JS handler |
Notifications |
Mailer (wp_mail() + email log) and MergeTags |
Privacy |
IpHasher, GDPR exporter/eraser, retention cleanup, privacy policy text |
Import |
ContactForm7Importer |
Tools |
CsvExporter, SystemInfo |
REST |
Controllers for stacko-forms/v1 |
Admin |
AdminPage (menu + Vue mount point) |
Boot sequence
Section titled “Boot sequence”stacko-forms.php defines the constants, registers the autoloader and activation/deactivation hooks, and calls Plugin::boot() on plugins_loaded. boot():
- Runs DB migrations if
stacko_forms_db_versionis behindSTACKO_FORMS_DB_VERSION(activation hooks don’t run on updates). - Registers the shortcode, no-JS submit handler, CSV export handler, preview page, form page and privacy tools.
- Registers the block on
initand REST routes onrest_api_init. - In the admin, registers the menu and admin assets.
Submission flow
Section titled “Submission flow”Both the AJAX path (POST /stacko-forms/v1/submit/{id}) and the no-JS path (admin-post.php?action=stacko_forms_submit) go through SubmissionHandler::handle():
- Load the published form. Drafts and trashed forms can’t receive submissions.
- Sanitize every input field with its field type’s
sanitize_value(). - Run spam checks: honeypot → signed token (signature, minimum fill time, 2-day maximum age) → rate limit → Turnstile (if enabled). Honeypot hits and invalid tokens return a fake success and store nothing.
- Drop values of fields hidden by conditional logic.
- Validate: maximum length (filter
stacko_forms_max_value_length), then each field type’svalidate_value(), then thestacko_forms_validation_errorsfilter. - Store the entry (if the form’s
store_entriessetting is on), in a DB transaction. - Fire
stacko_forms_entry_created. - Send each enabled notification. Every attempt is written to the email log; failures are also written to the plugin log.
- Return the confirmation message, or a redirect URL for the “page” and “URL” confirmation types.
See Hooks for the extension points along the way.
Data storage
Section titled “Data storage”Tables
Section titled “Tables”All tables use the site prefix plus stacko_forms_, for example wp_stacko_forms_entries. On multisite each site has its own set.
| Table | Contents |
|---|---|
stacko_forms_forms |
id, title, definition (published JSON), draft_definition (unpublished edits, nullable), definition_version, status (draft, published, trash), created_by, created_at, updated_at |
stacko_forms_form_revisions |
A copy of the definition each time a form is published. The last 10 per form are kept. |
stacko_forms_entries |
id, form_id, status (active, spam, trash), is_read, is_starred, user_id, ip_hash, user_agent, source_url, created_at, updated_at. Indexed on (form_id, status, created_at). |
stacko_forms_entry_values |
One row per field per entry: entry_id, field_id, value. Values are stored JSON-encoded (strings, arrays for checkboxes, {"first","last"} for split name fields). |
stacko_forms_email_log |
One row per email attempt: entry_id, notification_id, recipient, subject, status (sent/failed), error, created_at. |
stacko_forms_logs |
Plugin events and errors (e.g. spam_blocked, email_failed, entry_save_failed). Trimmed to about the latest 1,000 rows. |
All dates are stored in UTC.
Form definitions
Section titled “Form definitions”A form definition is a JSON document with version, fields, layout (rows of field IDs, up to 4 per row) and settings. Every definition is validated and normalised by Forms\SchemaValidator::sanitize() before it is saved; see schema/form.schema.json for the full shape. Key limits:
| Limit | Value |
|---|---|
| Fields per form | 200 |
| Fields per row | 4 |
| Logic rules per field | 20 |
| Options per choice field | 500 |
| Notifications per form | 10 |
| Recipients per notification | 10 |
| Characters per submitted value | 20,000 (filterable) |
Field IDs must match ^[a-z][a-z0-9_]{0,63}$.
While a form is published, edits go to draft_definition; the live definition changes only when the form is published again.
Options
Section titled “Options”| Option | Contents |
|---|---|
stacko_forms_settings |
Global settings array (see below) |
stacko_forms_db_version |
Installed schema version |
stacko_forms_cf7_map |
Map of imported Contact Form 7 post IDs to Stacko form IDs |
Keys in stacko_forms_settings:
| Key | Type | Default |
|---|---|---|
from_name |
string | '' |
from_email |
string | '' |
ip_mode |
'hashed' | 'none' |
'hashed' |
store_user_agent |
bool | true |
default_retention_days |
int (0–3650) | 0 |
rate_limit |
int (0–1000), per visitor per form per 10 minutes | 10 |
turnstile_site_key |
string | '' |
turnstile_secret_key |
string | '' |
load_css |
bool | true |
delete_data_on_uninstall |
bool | false |
onboarding_done |
bool | false |
Rate-limit counters are stored as transients named stacko_forms_rl_*.
stacko_forms_retention_cleanup runs daily and deletes entries older than each form’s retention_days, falling back to default_retention_days. 0 means keep forever. The event is cleared on deactivation.
Constants
Section titled “Constants”| Constant | Value |
|---|---|
STACKO_FORMS_VERSION |
Plugin version, e.g. '0.1.0' |
STACKO_FORMS_DB_VERSION |
Database schema version (int) |
STACKO_FORMS_FILE |
Absolute path to stacko-forms.php |
STACKO_FORMS_DIR |
Plugin directory path, with trailing slash |
STACKO_FORMS_URL |
Plugin directory URL, with trailing slash |
Capability
Section titled “Capability”Every admin screen, admin REST route, CSV export and preview checks the custom capability stacko_forms_manage. It is granted to the administrator role on activation. To let another role manage forms and entries:
// Run once, e.g. on your plugin's activation.$role = get_role( 'editor' );if ( $role ) { $role->add_cap( 'stacko_forms_manage' );}Privacy internals
Section titled “Privacy internals”- IP hashing:
HMAC-SHA256(ip, key)where the key is derived fromwp_hash()and the current UTC date, so hashes rotate daily and can’t be linked across days. OnlyREMOTE_ADDRis trusted; use thestacko_forms_client_ipfilter behind a proxy. Withip_modeset tonone,ip_hashis stored asNULL. - Exporter/eraser: registered as
stacko-formswith WordPress’s personal data tools. They match entries that have a value exactly equal to the requested email address, in batches of 50. The eraser deletes matching entries.
Activation, deactivation and uninstall
Section titled “Activation, deactivation and uninstall”- Activation creates the tables with
dbDelta()and adds the capability. On a network-wide activation every site is set up, and sites created later are set up automatically. - Deactivation only clears the cron event. No data is removed.
- Uninstall removes the tables,
stacko_forms_settings,stacko_forms_db_versionand the capability, but only ifdelete_data_on_uninstallis on. On multisite this runs for every site.
Outgoing requests
Section titled “Outgoing requests”None by default. If Turnstile is configured and turned on for a form, the browser loads https://challenges.cloudflare.com/turnstile/v0/api.js and the server posts to https://challenges.cloudflare.com/turnstile/v0/siteverify.
Development
Section titled “Development”composer installnpm installnpm run dev # Vite dev server with HMRnpm run build # production buildcomposer run lint # PHPCS (WordPress Coding Standards)npm run lint # ESLint, Stylelint, vue-tscnpm test # Vitestcomposer run test # PHPUnit + WordPress test suitenpm run test:e2e # Playwright + axeWith WP_DEBUG on and npm run dev running, the admin loads assets from the Vite dev server.