extends Base_Object_With_Meta implements Event_Process
Represents a one-time bulk send to a list of contacts — either an email or an SMS broadcast. A broadcast targets a saved contact query and is processed through the event queue. Use this class to inspect broadcast status, scheduling, and report data.
Methods
| Method | Returns | Description |
|---|---|---|
get_id() | int | Returns the broadcast ID. |
get_title() | string | Returns the broadcast title. |
get_status() | string | Returns the current status: 'scheduled', 'sending', 'sent', 'cancelled', or 'pending'. |
get_broadcast_type() | string | Returns the broadcast type slug (e.g. 'email'). |
get_object_id() | int | Returns the ID of the email or SMS template being sent. |
get_object() | Email|false | Returns the email or other object being broadcast. |
get_send_time() | int | Returns the scheduled send time as a Unix timestamp. |
get_date_scheduled() | string | Returns the scheduled date as a formatted string. |
get_query() | array | Returns the contact query used to determine recipients. |
is_email() | bool | Returns true if this is an email broadcast. |
is_sms() | bool | Returns true if this is an SMS broadcast. |
is_scheduled() | bool | Returns true if the broadcast is scheduled. |
is_sending() | bool | Returns true if the broadcast is currently being processed. |
is_sent() | bool | Returns true if the broadcast has finished sending. |
is_cancelled() | bool | Returns true if the broadcast was cancelled. |
is_fully_sent() | bool | Returns true if all events have been processed. |
is_transactional() | bool | Returns true if the broadcast is transactional. |
has_pending_events() | bool | Returns true if there are still events waiting to process. |
count_pending_events() | int | Returns the number of events still waiting. |
cancel() | bool | Cancels the broadcast and all pending events. |
get_report_data() | array | Returns send, open, click, and unsubscribe statistics for this broadcast. |
get_items_remaining() | int | Returns the number of contacts yet to receive the broadcast. |
Usage
Here’s a pseudo code example for a hypothetical broadcast reporting integration.
<?php
add_action( 'groundhogg/broadcast/after', 'my_plugin_track_broadcast_completion', 10, 3 );
/**
* Check if a broadcast has fully sent and push stats to an external dashboard.
*
* @param \Groundhogg\Broadcast $broadcast
* @param \Groundhogg\Contact $contact
* @param \Groundhogg\Event $event
*
* @return void
*/
function my_plugin_track_broadcast_completion( $broadcast, $contact, $event ) {
if ( ! $broadcast->is_fully_sent() ) {
return;
}
$stats = $broadcast->get_report_data();
my_plugin_push_to_dashboard( [
'broadcast_id' => $broadcast->get_id(),
'title' => $broadcast->get_title(),
'sends' => $stats['sends'] ?? 0,
'opens' => $stats['opens'] ?? 0,
'clicks' => $stats['clicks'] ?? 0,
] );
}
Was this helpful?
Let us know if this document answered your question. That’s the only way we can improve.
