\Groundhogg\Email

📅 Published on

📝 Last updated

Documentation

»

Classes

»

\Groundhogg\Email

extends Base_Object_With_Meta

Represents an email template stored in Groundhogg. This is not a record of a sent message — it is the reusable template that gets merged and dispatched when a funnel step or broadcast runs. Instantiate it with an email ID to access its content, settings, and send it manually.

Methods

MethodReturnsDescription
get_subject_line()stringReturns the raw subject line (may contain merge tags).
get_merged_subject_line()stringReturns the subject line with merge tags replaced for the current contact.
get_title()stringReturns the internal admin title of the email.
get_pre_header()stringReturns the pre-header text shown in email client previews.
get_content()stringReturns the raw email body content (block JSON or HTML).
get_alt_body()stringReturns the plain-text alternative body.
get_from_user()WP_User|falseReturns the WordPress user set as the from address.
get_status()stringReturns the email status: 'draft''ready', or 'archived'.
is_draft()boolReturns true if the email is in draft status.
is_ready()boolReturns true if the email is ready to send.
is_transactional()boolReturns true if the email is flagged as transactional (bypasses marketability check).
is_marketing()boolReturns true if the email is a marketing email.
is_confirmation_email()boolReturns true if the email is an opt-in confirmation email.
get_template()stringReturns the template slug used to render the email (e.g. 'boxed''full-width').
get_css()stringReturns the compiled inline CSS for the email.
get_alignment()stringReturns the email content alignment ('left' or 'center').
get_width()intReturns the email template width in pixels.
get_contact()Contact|falseReturns the contact currently set as the recipient (used during send/merge).
get_event()Event|falseReturns the event currently associated with this send.
get_click_tracking_link( $url )stringWraps a URL in a click-tracking redirect link.
get_open_tracking_src()stringReturns the URL of the open-tracking pixel.
send( $contact_id_or_email, $event = null )bool|WP_ErrorSends the email to a contact immediately. Returns true on success, false or WP_Error on failure.
enable_test_mode()voidPuts the email into test mode so it sends regardless of the contact’s marketability.
build()stringRenders and returns the full HTML email string ready for sending.

Usage

Here’s a pseudo code example for a hypothetical transactional email integration.

<?php

add_action( 'my_plugin_appointment_confirmed', 'my_plugin_send_confirmation_email', 10, 2 );

/**
 * Send a personalised confirmation email when an appointment is booked.
 *
 * @param int    $email_id
 * @param string $contact_email
 *
 * @return void
 */
function my_plugin_send_confirmation_email( $email_id, $contact_email ) {

    $email   = new \Groundhogg\Email( $email_id );
    $contact = \Groundhogg\get_contactdata( $contact_email );

    if ( ! $email->exists() || ! $contact ) {
        return;
    }

    // Send transactional emails regardless of opt-in status
    if ( ! $email->is_transactional() ) {
        $email->enable_test_mode();
    }

    $result = $email->send( $contact );

    if ( is_wp_error( $result ) ) {
        my_plugin_log_error( $result->get_error_message() );
    }
}

Was this helpful?

Let us know if this document answered your question. That’s the only way we can improve.