WP Signal is an independent service and is not affiliated with or endorsed by the WordPress project.

Reference

PHP API Reference

The WPS facade, trigger builder, and WordPress filters exposed by the WordSocket plugin.

WPS Facade

The WPS class is the main entry point. All methods are static. The class is a singleton; use WPS::instance() only when you need to access internal components directly.

WPS::instance( )

WPSignal\WPS - main singleton facade. Central entry point for the plugin. Provides static convenience methods for the two most common operations (registering triggers and publishing events) and wires all internal components during boot().

Returns: WPS

wp-content/plugins/{plugin}/plugin.php
add_action( 'wpsignal_loaded', function () {
    WPS::trigger( 'comment.created' )
        ->on( 'wp_insert_comment', 10, 2 )
        ->data( function ( $comment_id, $comment ) {
            return [
                'comment_id' => $comment_id,
                'post_id'    => $comment->comment_post_ID,
                'author'     => $comment->comment_author,
            ];
        } )
        ->when( function ( $comment_id, $comment ) {
            return (int) $comment->comment_approved === 1;
        } )
        ->register();
} );
wp-content/plugins/{plugin}/plugin.php
WPS::publish( 'events', 'custom.event', [ 'key' => 'value' ] );
wp-content/plugins/{plugin}/plugin.php
$config = WPSignal::instance()->config();

WPS::trigger( $event )

Create a new trigger builder. Returns a fluent builder: chain ->on(), ->channel(), ->data(), ->when(), then call ->register() to wire it up.

Parameter Type Description
$event string Event name (e.g. "post.updated", "comment.created").

Returns: Trigger A new trigger builder instance.

wp-content/plugins/{plugin}/plugin.php
WPS::trigger( 'user.login' )
    ->on( 'wp_login', 10, 2 )
    ->data( function ( $user_login, $user ) {
        return [ 'user_id' => $user->ID, 'login' => $user_login ];
    } )
    ->register();

WPS::publish( $channel, $event, $data )

Publish an event directly (no hook needed). Sends an HMAC-signed POST to the WPSignal server. The plugin must be configured (site_key, site_secret, base_url) or this returns a WP_Error.

Parameter Type Description
$channel string Channel name (e.g. "events"). Scoped server-side.
$event string Event name (e.g. "post.updated").
$data mixed Arbitrary data (will be JSON-encoded).

Returns: array|WP_Error wp_remote_post response array on success, WP_Error on failure.

wp-content/plugins/{plugin}/plugin.php
WPS::publish( 'events', 'custom.event', [ 'key' => 'value' ] );

Trigger Builder

WPS::trigger($event) returns a fluent builder. Chain the methods below and call register() to wire the WordPress hook.

Register triggers inside an add_action('wpsignal_loaded', ...) callback (in a plugin) or add_action('init', ...) (in a theme's functions.php).

->on( $hook, $priority, $accepted_args )

Set the WordPress action hook to listen on.

Parameter Type Description
$hook string WordPress action hook name.
$priority int Optional. Hook priority. Default 10.
$accepted_args int Optional. Number of hook arguments. Default 1.

Returns: $this

wp-content/plugins/{plugin}/plugin.php
->on( 'save_post', 20, 3 )    // priority 20, 3 args
->on( 'wp_login' )            // defaults: priority 10, 1 arg

->channel( $channel )

Set the channel to publish on. Defaults to "events" if not called. The server normalizes this to the full tenant-scoped channel name.

Parameter Type Description
$channel string Channel name.

Returns: $this

wp-content/plugins/{plugin}/plugin.php
->channel( 'orders' )

->data( $callback )

Set the data builder callback. The callback receives the same arguments as the WordPress hook and should return an associative array. This array becomes the `data` field in the published event payload.

Parameter Type Description
$callback callable Data builder. Receives hook args, returns array.

Returns: $this

wp-content/plugins/{plugin}/plugin.php
->data( function ( $post_id, $post, $update ) {
    return [
        'post_id'    => $post_id,
        'post_title' => $post->post_title,
    ];
} )

->when( $callback )

Set a condition callback. The callback receives the same arguments as the WordPress hook. Return false to skip publishing for this hook invocation. If not set, the trigger always fires.

Parameter Type Description
$callback callable Condition check. Receives hook args, returns bool.

Returns: $this

wp-content/plugins/{plugin}/plugin.php
->when( function ( $post_id, $post ) {
    return 'publish' === $post->post_status;
} )

->register( )

Register this trigger with the global trigger registry. This wires the WordPress hook so the trigger fires automatically. Must be called after configuring the builder.

wp-content/plugins/{plugin}/plugin.php
WPS::trigger( 'post.updated' )
    ->on( 'save_post', 20, 3 )
    ->channel( 'events' )
    ->data( function ( $post_id, $post, $update ) {
        return array(
            'post_id'    => $post_id,
            'post_type'  => $post->post_type,
    ->register();

WordPress Filters

Use add_filter() to hook into these.

wpsignal_token_channels

Filters the channels the client auto-subscribes to on connect. Plugins can append their own channels so they are included in the initial WebSocket/SSE subscription without a separate subscribe call.

Parameter Type Description
$channels string[] Default channels for this site.
$user_id int Current user ID.
$site_id string Hashed site identifier from the JWT.
wp-content/plugins/{plugin}/plugin.php
add_filter( 'wpsignal_token_channels', function ( $value ) {
    // modify $value and return it
    return $value;
} );

wpsignal_token_channel_prefixes

Filters the channel prefixes the JWT allows the client to subscribe to. The WPSignal server rejects subscribe/publish frames whose channel does not start with one of these prefixes. Add a prefix here whenever you add channels via the `wpsignal_token_channels` filter that fall outside the default `site:{site_id}:` namespace.

Parameter Type Description
$prefixes string[] Default allowed prefixes.
$user_id int Current user ID.
$site_id string Hashed site identifier from the JWT.
wp-content/plugins/{plugin}/plugin.php
add_filter( 'wpsignal_token_channel_prefixes', function ( $value ) {
    // modify $value and return it
    return $value;
} );

wpsignal_allow_client

Controls whether the WordSocket client script is enqueued for the current request. Return `false` to prevent the script from loading (e.g. on specific post types or for guest users). Return `true` to force-load it regardless of login state.

Parameter Type Description
$allow bool Default: `is_user_logged_in()`.
wp-content/plugins/{plugin}/plugin.php
add_filter( 'wpsignal_allow_client', '__return_true' );

wpsignal_force_sse

Forces the client to use SSE instead of WebSocket. Return `true` to disable WebSocket and fall back to Server-Sent Events. Useful in environments where WebSocket connections are blocked.

Parameter Type Description
$force bool Default: `false`.
wp-content/plugins/{plugin}/plugin.php
add_filter( 'wpsignal_force_sse', '__return_true' );

wpsignal_encryption_seed

Filters the seed used to derive the AES-256-GCM encryption key. The default seed is `AUTH_KEY . SECURE_AUTH_KEY`. Override this to supply your own key material without modifying WordPress salts.

Parameter Type Description
$seed string The default seed string.
wp-content/plugins/{plugin}/plugin.php
add_filter( 'wpsignal_encryption_seed', function ( $seed ) {
    return 'my-application-specific-secret';
} );

WordPress Actions

Use add_action() to hook into these.

wpsignal_loaded

Fires when WPSignal is fully loaded and ready for trigger registration. Third-party plugins should hook here to register custom triggers:

wp-content/plugins/{plugin}/plugin.php
add_action( 'wpsignal_loaded', function () {
    WPS::trigger( 'order.completed' )
        ->on( 'woocommerce_order_status_completed' )
        ->channel( 'orders' )
        ->data( function ( $order_id ) {
            $order = wc_get_order( $order_id );
            return [ 'order_id' => $order_id, 'total' => $order->get_total() ];
        } )
        ->register();
} );

Constants

Define these in wp-config.php to override default plugin behaviour.

WPSignal\BASE_URL

Define in wp-config.php to point the plugin at a self-hosted WPSignal server. When defined, overrides the default `https://api.wpsignal.io` endpoint for all publish, registration, and token requests.

wp-content/plugins/{plugin}/plugin.php
define( 'WPSignal\BASE_URL', 'https://signal.example.com' );

WPSIGNAL_JWT_SECRET

Legacy override: define in wp-config.php to supply the JWT signing secret. Superseded by the secret returned during site registration (stored in wp_options as `wpsignal_jwt_secret`). Only needed for sites that were configured before the auto-registration flow existed.

wp-content/plugins/{plugin}/plugin.php
define( 'WPSIGNAL_JWT_SECRET', 'your-64-char-hex-secret' );

9 Next steps