get_event_arg

πŸ“… Published on

πŸ“ Last updated

Documentation

Β»

Functions

Β»

get_event_arg

Retrieves a named argument from the currently executing event during queue processing. Use this to read data attached by an earlier step in the same funnel run via add_event_args(). Returns the $default value if the queue is not processing, the event doesn’t exist, or the argument is not set.

Parameters

ParameterTypeDescription
$argstringThe argument key to retrieve.
$defaultmixedValue to return if the arg is not found. Default false.

Return value

mixed β€” The argument value, or $default if not found.

Usage

// Inside a custom step's run() method
$order_id = \Groundhogg\get_event_arg( 'order_id', 0 );

Example

Here’s a pseudo code example for a hypothetical funnel step that reads data set by a previous step.

class My_Plugin_Send_Receipt_Step extends \Groundhogg\Step {

    /**
     * Send a receipt using the order ID stored by an earlier step.
     *
     * @param \Groundhogg\Contact $contact
     * @param \Groundhogg\Event   $event
     *
     * @return true|\WP_Error
     */
    public function run( $contact, $event ) {

        $order_id = \Groundhogg\get_event_arg( 'order_id' );

        if ( ! $order_id ) {
            return new \WP_Error( 'no_order', 'No order ID was passed from the previous step.' );
        }

        \Groundhogg\gh_mail(
            $contact->get_email(),
            'Your receipt',
            my_plugin_generate_receipt( $order_id ),
            [ 'Content-Type: text/html; charset=UTF-8' ]
        );

        return true;
    }
}

Was this helpful?

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