\Groundhogg\Broadcast

📅 Published on

📝 Last updated

Documentation

»

Classes

»

\Groundhogg\Broadcast

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

MethodReturnsDescription
get_id()intReturns the broadcast ID.
get_title()stringReturns the broadcast title.
get_status()stringReturns the current status: 'scheduled''sending''sent''cancelled', or 'pending'.
get_broadcast_type()stringReturns the broadcast type slug (e.g. 'email').
get_object_id()intReturns the ID of the email or SMS template being sent.
get_object()Email|falseReturns the email or other object being broadcast.
get_send_time()intReturns the scheduled send time as a Unix timestamp.
get_date_scheduled()stringReturns the scheduled date as a formatted string.
get_query()arrayReturns the contact query used to determine recipients.
is_email()boolReturns true if this is an email broadcast.
is_sms()boolReturns true if this is an SMS broadcast.
is_scheduled()boolReturns true if the broadcast is scheduled.
is_sending()boolReturns true if the broadcast is currently being processed.
is_sent()boolReturns true if the broadcast has finished sending.
is_cancelled()boolReturns true if the broadcast was cancelled.
is_fully_sent()boolReturns true if all events have been processed.
is_transactional()boolReturns true if the broadcast is transactional.
has_pending_events()boolReturns true if there are still events waiting to process.
count_pending_events()intReturns the number of events still waiting.
cancel()boolCancels the broadcast and all pending events.
get_report_data()arrayReturns send, open, click, and unsubscribe statistics for this broadcast.
get_items_remaining()intReturns 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.