Skip to content
Contact

For developers

For developers: hooks, shortcode and data

Kubo Forms is extended with WordPress actions and filters prefixed kubo_forms_, without touching its code. Here are all of them, with their parameters and an example, plus the shortcode, the JavaScript event, the REST routes and where data is stored.

Where to put your code

In your own plugin or an mu-plugin (wp-content/mu-plugins/), rather than your theme’s functions.php: that way it keeps working if you switch themes. Every hook except kubo_forms_loaded fires long after plugins and the theme have loaded, so adding them when your code loads is enough; kubo_forms_loaded fires on plugins_loaded.

If your code uses Kubo Forms classes, check first that it is active: class_exists( 'Kubo_Forms_Plugin' ).

A submission’s values

Several hooks receive $values: the list of validated fields, in the form’s order. Each one is an array with:

  • name: the field name ([a-z0-9_], up to 40 characters).
  • label: the label, without HTML.
  • type: text, email, tel, number, url, date, textarea, select, radio, checkbox, consent, newsletter or file.
  • value: the text; for checkbox, a list of the ticked options; for consent and newsletter, '1' if ticked and '' if not; for file, the name the visitor gave it.

Fields hidden by their conditional logic are not included, nor is the spam honeypot.

kubo_forms_entry_saved

Action. A valid submission has just been saved and its emails sent. Kubo Mail (priority 20) and Kubo CRM (30) hook in here. It does not fire for spam or for a repeated submission.

Parameters: $entry_id (int), $form (the form’s WP_Post) and $values. It runs during the visitor’s request: do not keep them waiting.

add_action(
	'kubo_forms_entry_saved',
	function ( $entry_id, $form, $values ) {
		// Only the quote form (its ID is in the "Shortcode" column).
		if ( 123 !== $form->ID ) {
			return;
		}
		$data = array( 'entry_id' => $entry_id );
		foreach ( $values as $value ) {
			// A file only arrives as its name: the file never leaves the site.
			if ( 'file' === $value['type'] ) {
				continue;
			}
			$data[ $value['name'] ] = $value['value'];
		}
		// Without waiting for the answer: the visitor is waiting for theirs.
		wp_remote_post(
			'https://example.com/webhook',
			array(
				'blocking' => false,
				'timeout'  => 2,
				'headers'  => array( 'Content-Type' => 'application/json' ),
				'body'     => wp_json_encode( $data ),
			)
		);
	},
	10,
	3
);

kubo_forms_entry_status_changed

Action. A submission’s status (new, read or spam) has changed: the owner marked it, and also when a new submission is opened and becomes read.

Parameters: $entry_id (int), $status (the new one), $old (the previous one) and $entry (the submission as it was before the change, with fields, consent, meta and page_url already decoded).

add_action(
	'kubo_forms_entry_status_changed',
	function ( $entry_id, $status, $old, $entry ) {
		// Opening a new submission also lands here ("new" to "read"): only spam matters.
		if ( 'spam' === $status || 'spam' === $old ) {
			error_log( sprintf( 'Kubo Forms: submission %d, from %s to %s', $entry_id, $old, $status ) );
		}
	},
	10,
	4
);

kubo_forms_spam_check

Filter. The entry point for an external spam filter. It receives what the local protection decided and returns the same array: reason ('' if it is not spam, or a short reason) and meta (an array saved with the submission).

Parameters: $check, $values and $form. It fires for valid submissions and for those the local protection already stopped (then reason carries its reason: honeypot, time or stamp), not for those sent back with errors. The reason is saved through sanitize_key(), up to 20 characters, and it is what the submissions list shows. The files key of meta is reserved.

To read what you saved later: Kubo_Forms_Entries::meta( $entry_id, 'my_spam_filter' ); to change it, Kubo_Forms_Entries::update_meta( $entry_id, 'my_spam_filter', $array ), up to 2 KB per key. kubo_forms_entry_status_changed tells you when the owner corrects it.

add_filter(
	'kubo_forms_spam_check',
	function ( $check, $values, $form ) {
		// If the local protection already stopped it, there is nothing more to check.
		if ( '' !== $check['reason'] ) {
			return $check;
		}
		$links = 0;
		foreach ( $values as $value ) {
			if ( is_string( $value['value'] ) ) {
				$links += preg_match_all( '#https?://#i', $value['value'] );
			}
		}
		if ( $links > 3 ) {
			// A short reason: it is what the owner will see in the submissions list.
			$check['reason']                 = 'links';
			$check['meta']['my_spam_filter'] = array( 'links' => $links );
		}
		return $check;
	},
	10,
	3
);

kubo_forms_notification_to

Filter. Who a form’s notification email goes to. Parameters: $to (the list of addresses: the form’s, or the general ones if it has none) and $form. Invalid ones are dropped afterwards. It does not change who the automatic reply goes to.

add_filter(
	'kubo_forms_notification_to',
	function ( $to, $form ) {
		// Quote requests also go to sales.
		if ( 123 === $form->ID ) {
			$to[] = 'sales@example.com';
		}
		return $to;
	},
	10,
	2
);

kubo_forms_message

Filter. The message for the sender. Parameters: $message, $status (ok, invalid, expired or rate_limited) and $form (the WP_Post, or null). It is shown as text, without HTML. Spam also gets the ok one, so it cannot tell the difference.

add_filter(
	'kubo_forms_message',
	function ( $message, $status, $form ) {
		if ( 'rate_limited' === $status ) {
			return 'You have sent several messages in a row. Try again in ten minutes or give us a call.';
		}
		return $message;
	},
	10,
	3
);

kubo_forms_submit_label

Filter. The submit button’s text. Parameters: $label (the one in the form’s settings, or “Send”) and $form.

add_filter(
	'kubo_forms_submit_label',
	function ( $label, $form ) {
		return 123 === $form->ID ? 'Request a quote' : $label;
	},
	10,
	2
);

kubo_forms_redirect_url

Filter. Where the sender goes. Parameters: $url (the page or address from After sending, or '' to stay with the message) and $form. What you return must be an http(s) address with a domain; otherwise the message is shown. It applies with and without JavaScript.

add_filter(
	'kubo_forms_redirect_url',
	function ( $url, $form ) {
		// Only if the form already sends people to a page: '' keeps the message.
		if ( '' === $url ) {
			return $url;
		}
		// The thank-you page knows which form it came from.
		return add_query_arg( 'form', $form->ID, $url );
	},
	10,
	2
);

Do not build the address from anything in the request ($_GET, $_POST): you would turn the form into an open redirect.

kubo_forms_client_ip

Filter. The IP used to count the submission limit (it is never stored). Parameter: $ip, the one from REMOTE_ADDR. What you return must be a valid IP; otherwise the limit does not apply to that submission.

add_filter(
	'kubo_forms_client_ip',
	function ( $ip ) {
		// Behind Cloudflare, the visitor's IP comes in its header.
		if ( isset( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) {
			return sanitize_text_field( wp_unslash( $_SERVER['HTTP_CF_CONNECTING_IP'] ) );
		}
		return $ip;
	}
);

Only do this if all traffic goes through that proxy: if your server can be reached without it, anyone can write that header and skip the limit.

kubo_forms_rate_limit

Filter. How many submissions are accepted from one IP every 10 minutes. Parameter: $limit (10 by default).

add_filter(
	'kubo_forms_rate_limit',
	function ( $limit ) {
		// A conference: many attendees sending from the same wifi.
		return 30;
	}
);

kubo_forms_file_types

Filter. The file type groups: group => array( extensions => MIME type ), with extensions written as in upload_mimes ('jpg|jpeg'). The groups are documents, images and spreadsheets. Anything added is checked the same way, by content, and anything a browser could run (HTML, SVG, JavaScript, PHP…) is removed even if you add it.

The editor only offers those three groups: add to one of them rather than creating another. The line under the field on your site shows the extensions that really apply; the group’s label in the editor does not change.

add_filter(
	'kubo_forms_file_types',
	function ( $groups ) {
		// No old Word formats or rich text.
		unset( $groups['documents']['doc'], $groups['documents']['rtf'] );
		// ZIP among the documents: checked the same way, by its content.
		$groups['documents']['zip'] = 'application/zip';
		return $groups;
	}
);

kubo_forms_loaded

Action. Kubo Forms has registered its hooks. Parameter: $plugin, the Kubo_Forms_Plugin instance.

It fires on plugins_loaded (priority 20), once the other plugins have loaded: any plugin can hook it. Your theme’s functions.php loads later: from a theme, use after_setup_theme with class_exists( 'Kubo_Forms_Plugin' ).

<?php
// In your own plugin: kubo_forms_loaded fires on plugins_loaded.
add_action(
	'kubo_forms_loaded',
	function ( $plugin ) {
		// Here Kubo Forms is active and its classes exist.
		add_filter(
			'kubo_forms_rate_limit',
			function () {
				return 20;
			}
		);
	}
);

The JavaScript event

When it sends successfully with JavaScript, the form fires kubo-forms:sent, which bubbles up to document. event.detail.formId is the form’s number and, if it is going to a thank-you page, event.detail.redirect is the address (it fires before leaving). A submission without JavaScript fires nothing.

document.addEventListener( 'kubo-forms:sent', function ( event ) {
	// Only once the server has accepted the submission.
	if ( typeof window.gtag === 'function' ) {
		window.gtag( 'event', 'generate_lead', { form_id: event.detail.formId } );
	}
} );

The shortcode

[kubo_form id="123"] shows the published form with that ID; it takes no other attributes. A form that does not exist or is not published shows nothing (people who can edit pages see a notice). In PHP:

echo do_shortcode( '[kubo_form id="123"]' );

REST routes

The form’s script uses two public routes:

  • POST /wp-json/kubo-forms/v1/forms/{id}/submissions: the submission. As JSON (fields, stamp, page) or, with files, as multipart with the form’s field names (kubo_forms_fields[…], kubo_forms_stamp, kubo_forms_files[…]). It answers 200 if saved (spam included), 422 with errors per field, 409 with a new token if its token expired, 429 if the limit is passed and 404 if the form does not exist or is not published. If it is going to a thank-you page, the answer includes redirect.
  • GET /wp-json/kubo-forms/v1/forms/{id}/stamp: a new token, not cached.

They are meant for the form your site renders, not as an API for other applications: a submission must carry the honeypot field empty, whose name only appears in that HTML, and arrive at least three seconds after its token. Otherwise it is saved as spam.

Where data is stored

Read a submission with Kubo_Forms_Entries::get( $id ), which returns it with its JSON already decoded, rather than with direct SQL. Values are never stored PHP-serialised.

  • Forms: posts of the kubo_form type, with fields as blocks in post_content and their settings in the kubo_forms_settings meta.
  • Submissions: the kubo_forms_entries table (with the site’s prefix): form_id, created_at (UTC), status (new, read or spam), spam_reason, page_url and, as JSON, fields (the values), consent (the proof for each checkbox) and meta (integrators’ data and files).
  • Deliveries: the kubo_forms_deliveries table, one row per submission and channel (email, autoreply, kubo_mail or kubo_crm) with status, attempts, last_error and next_at. It is also the Kubo CRM queue.
  • Options: kubo_forms_options (general settings), kubo_forms_crm (the Kubo CRM connection) and kubo_forms_db_version.
  • Scheduled events: kubo_forms_daily (the daily deletion) and kubo_forms_crm_queue (Kubo CRM retries).
  • Files: the kubo-forms folder inside the uploads folder, with random names.

Capabilities

kubo_forms_view_entries, kubo_forms_manage_entries and kubo_forms_export_entries, given to administrators when the plugin is activated. Forms use page capabilities (edit_pages and the rest), and the settings screen uses manage_options.