Skip to main content

Actions

This page documents all PHP actions fired by Unblock.

Actions allow you to execute code at specific points in the plugin lifecycle.

Summary

ActionDescription
unblock/loadedPlugin loaded, before services registered
unblock/initPlugin fully initialized
unblock/form/processedForm submission passed validation, before email
unblock/form/spam_detectedForm submission detected as spam

loaded

Fired when the UnBlock plugin file has been loaded, before services are registered and initialized.

Parameters

None.

Usage

add_action( 'unblock/loaded', function () {

// Plugin is loaded but not fully initialized.
// Use this for very early setup.

} );

Example: Early Configuration

add_action( 'unblock/loaded', function () {

// Define constants before plugin initializes.
if ( ! defined( 'MY_UNBLOCK_DEBUG' ) ) {
define( 'MY_UNBLOCK_DEBUG', true );
}

} );

init

Fired after the plugin's helpers, services, and hooks have been registered. This is the recommended hook for most integrations.

Parameters

None.

Usage

add_action( 'unblock/init', function () {

// Plugin is fully initialized.
// Safe to interact with all plugin features.

} );

Example: Initialize Custom Integration

add_action( 'unblock/init', function () {

// Register custom functionality after UnBlock is ready.
if ( class_exists( 'My_Custom_Integration' ) ) {
My_Custom_Integration::instance()->init();
}

} );

Example: Conditional Feature Loading

add_action( 'unblock/init', function () {

// Load additional features based on environment.
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {

add_filter( 'unblock/data/providers', function ( $providers ) {

$providers['debug'] = [
'class' => My_Debug_Provider::class,
];

return $providers;

} );

}

} );

form/processed

Fires after a form submission passes all validation (honeypot, timestamp, rate limit, sanitization, attachments) and before the email is sent.

do_action( 'unblock/form/processed', Context $context );
ParameterTypeDescription
$context\Unblock\Form\ContextForm context with sanitized fields, attachments, referer, and client IP

Example: Save Form Entry

add_action( 'unblock/form/processed', function ( $context ) {

wp_insert_post( [
'post_type' => 'form_entry',
'post_title' => 'Submission from ' . $context->referer(),
'post_content' => wp_json_encode( $context->fields() ),
'post_status' => 'private',
] );

} );

form/spam_detected

Fires when a form submission is detected as spam via honeypot or timestamp checks.

do_action( 'unblock/form/spam_detected', Context $context );
ParameterTypeDescription
$context\Unblock\Form\ContextForm context with error details

Example: Log Spam Attempts

add_action( 'unblock/form/spam_detected', function ( $context ) {

error_log( 'Spam detected from IP: ' . $context->client_ip() );

} );

Next steps