get_current_contact

📅 Published on

📝 Last updated

Documentation

»

Functions

»

get_current_contact

Alias for get_contactdata() called with no arguments. Returns the current contact detected from the active event queue or tracking cookie. Useful as a semantic shorthand when you know you are in a request context where a current contact should exist.

Parameters

This function has no parameters.

Return value

Contact|false — The current contact, or false if none is detected.

Usage

$contact = \Groundhogg\get_current_contact();

if ( $contact ) {
    $contact->apply_tag( 'visited-dashboard' );
}

Example

Here’s a pseudo code example for a custom managed page extension.

add_action( 'groundhogg/preferences/profile_form', 'my_plugin_add_profile_field' );

/**
 * Add a custom field to the preferences profile form for the current contact.
 *
 * @return void
 */
function my_plugin_add_profile_field() {

    $contact = \Groundhogg\get_current_contact();

    if ( ! $contact ) {
        return;
    }

    $value = esc_attr( $contact->get_meta( 'company_size' ) );

    echo 'Company size ' . $value . '';
}

Was this helpful?

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