send_realtime_event
Sends custom realtime event directly to user browser using WebSocket servers
To receive events use this better_messages_realtime_event JavaScript Hook
REQUIREMENTS
To be able to implement this guide, you need to learn how to insert PHP snippets to your website.
You can find guide here: WP Beginner
Compatibility
This function compatible with Better Messages 2.0.62 or higher
WebSocket Version Guide
This functionality available only with WebSocket Version
<?php
// User IDs to send events to
$user_ids = [
1,
2,
3
];
// Checking if better messages websocket class exists to avoid fatal errors
if( class_exists('Better_Messages_WebSocket') ){
// Send simple string
Better_Messages_WebSocket()->send_realtime_event( [1,2,3], 'custom string' );
// Send more complex data sets
Better_Messages_WebSocket()->send_realtime_event( [1,2,3], [
'custom data' => 'test'
] );
}