Hooks
All Stacko Forms hooks use the stacko_forms_ prefix. This page lists every action and filter in the current code.
In the parameters below, a form array has this shape (the published form):
array( 'id' => 123, // int 'title' => 'Contact form', // string 'definition' => array( // array: version, fields, layout, settings 'version' => 1, 'fields' => array( /* field definitions */ ), 'layout' => array( array( 'name', 'email' ), array( 'message' ) ), 'settings' => array( /* submit_label, notifications, confirmation, spam, style, ... */ ), ),)Values are keyed by field ID. Most values are strings; checkboxes are a list of option values; a Name field set to first/last is array( 'first' => '', 'last' => '' ); a consent field is '1' or ''.
Actions
Section titled “Actions”stacko_forms_entry_created
Section titled “stacko_forms_entry_created”Fires after a submission passes spam checks and validation and the entry is saved, before notifications are sent. It also fires when the form’s “Save entries on this site” setting is off; then $entry_id is 0.
| Parameter | Type | Description |
|---|---|---|
$entry_id |
int |
New entry ID, or 0 if entries aren’t stored for this form |
$values |
array<string, mixed> |
Sanitized values keyed by field ID (fields hidden by logic are not included) |
$form |
array |
The form array |
add_action( 'stacko_forms_entry_created', function ( int $entry_id, array $values, array $form ): void { if ( 123 !== $form['id'] || empty( $values['email'] ) ) { return; } // Example: pass the address to your own newsletter code. my_newsletter_subscribe( $values['email'] );}, 10, 3 );stacko_forms_form_published
Section titled “stacko_forms_form_published”Fires after a form is published (or updated) from the builder.
| Parameter | Type | Description |
|---|---|---|
$id |
int |
Form ID |
add_action( 'stacko_forms_form_published', function ( int $id ): void { // Example: clear your page cache so the new version shows right away. if ( function_exists( 'my_cache_flush' ) ) { my_cache_flush(); }} );stacko_forms_retention_cleanup
Section titled “stacko_forms_retention_cleanup”The daily WP-Cron event that deletes entries past their retention period. It takes no parameters. You normally don’t hook into it; you can trigger it manually:
do_action( 'stacko_forms_retention_cleanup' );Filters
Section titled “Filters”stacko_forms_validation_errors
Section titled “stacko_forms_validation_errors”Add your own server-side validation. Runs after the built-in checks, before anything is stored.
| Parameter | Type | Description |
|---|---|---|
$errors |
array<string, string> |
Field ID → error message. Return an empty array to accept the submission. |
$values |
array<string, mixed> |
Sanitized values keyed by field ID |
$form |
array |
The form array |
Returns array<string, string>. Any non-empty array stops the submission and shows the messages to the visitor. Use a field ID as the key so the message appears next to that field and in the error summary.
add_filter( 'stacko_forms_validation_errors', function ( array $errors, array $values, array $form ): array { if ( 123 === $form['id'] && isset( $values['email'] ) && str_ends_with( $values['email'], '@example.com' ) ) { $errors['email'] = __( 'Please use your work email address.', 'my-plugin' ); } return $errors;}, 10, 3 );stacko_forms_email
Section titled “stacko_forms_email”Filter each notification email right before it is passed to wp_mail(). Also runs for resends.
| Parameter | Type | Description |
|---|---|---|
$email |
array |
to (string[]), subject (string), body (string, HTML), headers (string[]) |
$notification |
array |
The notification settings: id, name, enabled, to, subject, message, reply_to |
$form |
array |
The form array |
$entry_id |
int |
Entry ID (0 if entries aren’t stored) |
Returns the $email array.
add_filter( 'stacko_forms_email', function ( array $email, array $notification, array $form, int $entry_id ): array { if ( 'admin' === $notification['id'] ) { $email['headers'][] = 'Cc: sales@example.com'; } return $email;}, 10, 4 );stacko_forms_max_value_length
Section titled “stacko_forms_max_value_length”Maximum number of characters allowed per submitted value. For multi-value fields, the joined length counts.
| Parameter | Type | Description |
|---|---|---|
$max |
int |
Default 20000 |
add_filter( 'stacko_forms_max_value_length', fn( int $max ): int => 50000 );stacko_forms_client_ip
Section titled “stacko_forms_client_ip”Filter the client IP used for rate limiting and the daily IP hash. By default only $_SERVER['REMOTE_ADDR'] is used. The returned value must be a valid IP address, otherwise it’s treated as empty.
| Parameter | Type | Description |
|---|---|---|
$ip |
string |
IP address from REMOTE_ADDR |
// Behind Cloudflare: trust its header only when the request really comes from your proxy.add_filter( 'stacko_forms_client_ip', function ( string $ip ): string { if ( ! empty( $_SERVER['HTTP_CF_CONNECTING_IP'] ) && my_is_trusted_proxy( $ip ) ) { return sanitize_text_field( wp_unslash( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ); } return $ip;} );stacko_forms_form_html
Section titled “stacko_forms_form_html”Filter the complete HTML of a rendered form (not the success message).
| Parameter | Type | Description |
|---|---|---|
$html |
string |
Form markup, starting with <div class="sf-wrap …"> |
$form |
array |
The form array (the draft definition when rendered as an admin preview) |
Returns string. You are responsible for escaping anything you add.
add_filter( 'stacko_forms_form_html', function ( string $html, array $form ): string { $note = '<p class="my-form-note">' . esc_html__( 'We reply within one working day.', 'my-plugin' ) . '</p>'; return $note . $html;}, 10, 2 );stacko_forms_index_form_page
Section titled “stacko_forms_index_form_page”Whether search engines may index a form’s standalone page (/?stacko_form=ID). By default the page sends a noindex robots directive.
| Parameter | Type | Description |
|---|---|---|
$index |
bool |
Default false |
$form_id |
int |
Form ID |
add_filter( 'stacko_forms_index_form_page', fn( bool $index, int $form_id ): bool => 42 === $form_id, 10, 2 );stacko_forms_templates
Section titled “stacko_forms_templates”Filter the templates offered when creating a new form.
| Parameter | Type | Description |
|---|---|---|
$templates |
array |
List of templates. Each has slug, title, description, category and definition. |
Built-in categories are general, business, feedback, marketing, events and nonprofit. The definition is sanitized again when a form is created from it, so it must be valid (see schema/form.schema.json).
add_filter( 'stacko_forms_templates', function ( array $templates ): array { $templates[] = array( 'slug' => 'callback-request', 'title' => __( 'Callback request', 'my-plugin' ), 'description' => __( 'Ask for a phone number and a good time to call.', 'my-plugin' ), 'category' => 'business', 'definition' => array( 'version' => 1, 'fields' => array( array( 'id' => 'name', 'type' => 'name', 'label' => __( 'Name', 'my-plugin' ), 'required' => true ), array( 'id' => 'phone', 'type' => 'phone', 'label' => __( 'Phone', 'my-plugin' ), 'required' => true ), array( 'id' => 'time', 'type' => 'text', 'label' => __( 'Best time to call', 'my-plugin' ) ), ), 'layout' => array( array( 'name', 'phone' ), array( 'time' ) ), 'settings' => array(), // Missing settings are filled with defaults. ), ); return $templates;} );stacko_forms_field_types
Section titled “stacko_forms_field_types”Register additional field types, or remove built-in ones. Runs once per request, the first time the field registry is used.
| Parameter | Type | Description |
|---|---|---|
$types |
array |
Instances of Stacko\Forms\Forms\Fields\AbstractField. Anything else is ignored. |
A field type extends AbstractField and implements at least type() and label(). Override group() (basic, choice, layout, advanced), props() (allowed settings and how to sanitize them: text, int, number, bool, textarea, html, options, or enum:a|b), sanitize_value(), validate_value(), render() and to_text() as needed.
use Stacko\Forms\Forms\Fields\AbstractField;
add_filter( 'stacko_forms_field_types', function ( array $types ): array { if ( ! class_exists( AbstractField::class ) ) { return $types; }
$types[] = new class() extends AbstractField { public function type(): string { return 'postcode'; }
public function label(): string { return __( 'Postcode', 'my-plugin' ); }
public function props(): array { return array( 'placeholder' => 'text' ); }
public function validate_value( mixed $value, array $field ): ?string { $error = parent::validate_value( $value, $field ); if ( null === $error && '' !== $value && ! preg_match( '/^\d{4}\s?[A-Z]{2}$/i', (string) $value ) ) { return __( 'Enter a postcode like 1234 AB.', 'my-plugin' ); } return $error; } };
return $types;} );stacko_forms_use_transactions
Section titled “stacko_forms_use_transactions”Whether entry inserts are wrapped in a START TRANSACTION / COMMIT. Turn it off only if your database setup doesn’t support transactions or you already run inside one (as the test suite does).
| Parameter | Type | Description |
|---|---|---|
$use |
bool |
Default true |
add_filter( 'stacko_forms_use_transactions', '__return_false' );WordPress hooks the plugin uses
Section titled “WordPress hooks the plugin uses”These are standard WordPress hooks, not Stacko Forms hooks, but they’re useful to know:
| Hook | Purpose |
|---|---|
shortcode_atts_stacko_form |
Core filter for the [stacko_form] shortcode’s attributes (id, class). |
admin_post_stacko_forms_submit, admin_post_nopriv_stacko_forms_submit |
No-JS form submissions. |
admin_post_stacko_forms_export |
CSV download (requires stacko_forms_manage and a nonce). |
wp_privacy_personal_data_exporters, wp_privacy_personal_data_erasers |
Registers the stacko-forms exporter and eraser. |