gform_mailerlite_subscriber

Description

Allows the subscriber properties to be overridden before the update request is made. Refer to the MailerLite API docs for more information about available subscriber properties

Usage

Applies to all forms:

add_filter( 'gform_mailerlite_subscriber', 'your_function_name', 10, 5 );

To target a specific form, append the form id to the hook name. (format: gform_mailerlite_subscriber_FORMID)

add_filter( 'gform_mailerlite_subscriber_123', 'your_function_name', 10, 5 );

Parameters

  • $subscriber array
    The subscriber properties.
  • $existing_subscriber array
    The existing properties of the subscriber or an empty array if no subscriber exists with the given email address.
  • $feed Feed Object
    The feed currently being processed.
  • $form Form Object
    The form currently being processed.
  • $entry Entry Object
    The entry currently being processed.

Examples

Unsubscribe a contact based on the feed name being processed.

// Unsubscribe a contact based on feed name being processed
add_filter( 'gform_mailerlite_subscriber', function( $subscriber, $existing_subscriber, $feed, $form, $entry ) {
     
    if ( rgars( $feed, 'meta/feedName' ) == 'Unsubscribe the Contact' ) { // Replace 'Unsubscribe the Contact' with your feed name.
        gf_mailerlite()->log_debug( 'Sending unsubscribe request');
        $subscriber['status'] = 'unsubscribed';
    }
 
    return $subscriber;
    
}, 10, 5 );

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

This filter is located in includes/addons/class-gf-mailerlite.php

Since

The filter was added in MailerLite 1.0