Filter uncanny-automator

uap_option_get_all_mailpoet_subscribers

Filters the array of all MailPoet subscribers before they are fetched and displayed.

add_filter( 'uap_option_get_all_mailpoet_subscribers', $callback, 10, 1 );

Description

Filters the options array for Mailpoet subscribers. Allows developers to modify the available subscriber options and their corresponding token labels before they are used in Uncanny Automator. This hook fires after Mailpoet subscriber data has been retrieved.


Usage

add_filter( 'uap_option_get_all_mailpoet_subscribers', 'your_function_name', 10, 1 );

Parameters

$option (mixed)
This parameter contains the default option code for Mailpoet subscribers.

Return Value

The filtered value.


Examples

/**
 * Example callback function for the 'uap_option_get_all_mailpoet_subscribers' filter.
 * This function demonstrates how to potentially modify the data returned by the hook.
 *
 * @param array $option The original array of options and relevant tokens for Mailpoet subscribers.
 * @return array The modified array of options and relevant tokens.
 */
add_filter( 'uap_option_get_all_mailpoet_subscribers', function( $option ) {
	// Let's imagine we want to add an additional token for the subscriber's list ID,
	// if it's available in the original option data.
	// In a real-world scenario, you would need to inspect the structure of $option
	// to determine what data is actually available.

	// For demonstration, we'll assume $option['options'] contains subscriber data
	// and we're looking for a 'list_id' key within each subscriber entry.
	if ( ! empty( $option['options'] ) && is_array( $option['options'] ) ) {
		$first_subscriber_options = reset( $option['options'] ); // Get the first subscriber's data

		// Check if the subscriber data is an array and contains 'list_id'
		if ( is_array( $first_subscriber_options ) && isset( $first_subscriber_options['list_id'] ) ) {
			// If we found a list ID, add a new relevant token for it.
			// The key for the token should correspond to how Uncanny Automator
			// would expect to retrieve this data in an action or condition.
			// We'll use a generic key for demonstration.
			$list_id_token_key = 'mailpoet_subscriber_list_id'; // This key would need to match Uncanny Automator's expectation.

			if ( ! isset( $option['relevant_tokens'][ $list_id_token_key ] ) ) {
				$option['relevant_tokens'][ $list_id_token_key ] = esc_attr_x( 'Subscriber List ID', 'Mailpoet', 'uncanny-automator' );
			}
		}
	}

	// Always return the modified or original $option array.
	return $option;
}, 10, 1 ); // Priority 10, accepts 1 argument.

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/integrations/mailpoet/helpers/mailpoet-helpers.php:134

public function get_all_mailpoet_subscribers( $label = null, $option_code = 'MAILPOETSUBSCRIBERS', $args = array() ) {

		if ( ! $label ) {
			$label = esc_attr_x( 'Subscriber', 'Mailpoet', 'uncanny-automator' );
		}

		$options = array();

		global $wpdb;

		$subscribers = $wpdb->get_results( "SELECT id,email FROM {$wpdb->prefix}mailpoet_subscribers  ORDER BY id DESC", ARRAY_A );

		foreach ( $subscribers as $subscriber ) {
			$options[ $subscriber['id'] ] = $subscriber['email'];
		}

		$option = array(
			'option_code'     => $option_code,
			'label'           => $label,
			'input_type'      => 'select',
			'required'        => true,
			'options'         => $options,
			'relevant_tokens' => array(
				$option_code         => esc_attr_x( 'Subscriber', 'Mailpoet', 'uncanny-automator' ),
				$option_code . '_ID' => esc_attr_x( 'Subscriber ID', 'Mailpoet', 'uncanny-automator' ),
			),
		);

		return apply_filters( 'uap_option_get_all_mailpoet_subscribers', $option );
	}

Scroll to Top