Skip to content

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.

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.

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.

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)

stacko-forms.php defines the constants, registers the autoloader and activation/deactivation hooks, and calls Plugin::boot() on plugins_loaded. boot():

  1. Runs DB migrations if stacko_forms_db_version is behind STACKO_FORMS_DB_VERSION (activation hooks don’t run on updates).
  2. Registers the shortcode, no-JS submit handler, CSV export handler, preview page, form page and privacy tools.
  3. Registers the block on init and REST routes on rest_api_init.
  4. In the admin, registers the menu and admin assets.

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():

  1. Load the published form. Drafts and trashed forms can’t receive submissions.
  2. Sanitize every input field with its field type’s sanitize_value().
  3. 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.
  4. Drop values of fields hidden by conditional logic.
  5. Validate: maximum length (filter stacko_forms_max_value_length), then each field type’s validate_value(), then the stacko_forms_validation_errors filter.
  6. Store the entry (if the form’s store_entries setting is on), in a DB transaction.
  7. Fire stacko_forms_entry_created.
  8. Send each enabled notification. Every attempt is written to the email log; failures are also written to the plugin log.
  9. Return the confirmation message, or a redirect URL for the “page” and “URL” confirmation types.

See Hooks for the extension points along the way.

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.

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.

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.

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

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' );
}
  • IP hashing: HMAC-SHA256(ip, key) where the key is derived from wp_hash() and the current UTC date, so hashes rotate daily and can’t be linked across days. Only REMOTE_ADDR is trusted; use the stacko_forms_client_ip filter behind a proxy. With ip_mode set to none, ip_hash is stored as NULL.
  • Exporter/eraser: registered as stacko-forms with 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 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_version and the capability, but only if delete_data_on_uninstall is on. On multisite this runs for every site.

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.

Terminal window
composer install
npm install
npm run dev # Vite dev server with HMR
npm run build # production build
composer run lint # PHPCS (WordPress Coding Standards)
npm run lint # ESLint, Stylelint, vue-tsc
npm test # Vitest
composer run test # PHPUnit + WordPress test suite
npm run test:e2e # Playwright + axe

With WP_DEBUG on and npm run dev running, the admin loads assets from the Vite dev server.