Skip to main content

PHP API

Functions

These global functions are available in any PHP context after the plugin boots.


wp_tosuto()

Add a toast notification to the render queue.

function wp_tosuto( string $content, array $options = [] ): string

Parameters

NameTypeRequiredDefaultDescription
$contentstringyesHTML displayed inside the toast. Sanitized via wp_kses_post().
$options['variant']stringno'default'Visual style. One of: default, success, error, warning, info.
$options['duration']intno5000Auto-dismiss delay in milliseconds.
$options['dismissable']boolnotrueWhether a dismiss button is shown.

Returns string — UUID of the queued toast. Pass to wp_tosuto_remove() to cancel it.

Example

$id = wp_tosuto( '<strong>Saved!</strong>', [
'variant' => 'success',
'duration' => 3000,
'dismissable' => true,
] );

wp_tosuto_remove()

Remove a previously queued toast before it is rendered.

function wp_tosuto_remove( string $id ): bool

Parameters

NameTypeDescription
$idstringUUID returned by wp_tosuto().

Returns booltrue if the toast was found and removed, false otherwise.

Example

$id = wp_tosuto( 'Processing…' );

if ( $error ) {
wp_tosuto_remove( $id );
wp_tosuto( 'Something went wrong.', [ 'variant' => 'error' ] );
}

Hooks & Filters

Hook: wp-tosuto.api.render-empty

Type: filter (apply_filters)

Controls whether an empty toast container is rendered when no toasts are queued. An empty container allows client-side actions.add() calls to work on pages where the server queued no toasts.

apply_filters( 'wp-tosuto.api.render-empty', true );

Accepted return values

ValueBehaviour
trueRender the empty container (default).
falseRender nothing.
callableCalled with no arguments; return value is used as the boolean. Accepts any WordPress template tag string (e.g. 'is_singular').
otherCoerced to bool.

Examples

// Only render on singular pages
add_filter( 'wp-tosuto.api.render-empty', 'is_singular' );

// Custom condition
add_filter( 'wp-tosuto.api.render-empty', function (): bool {
return is_user_logged_in();
} );

// Disable entirely
add_filter( 'wp-tosuto.api.render-empty', '__return_false' );