Filter Since 4.4 uncanny-automator

automator_fluentcrm_subscriber_pivot_tags

SubscriberPivot::whereIn is causing the list ids to return an empty array. Filters the attached tag IDs for FluentCRM subscribers before they are used in a pivot query, preventing empty arrays.

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

Description

Allows developers to control whether FluentCRM's subscriber pivot check is bypassed. By default, this filter returns `true`, disabling the check and preventing potential issues where `SubscriberPivot::whereIn` might incorrectly return an empty array of tag IDs. This hook fires within the `get_attached_tag_ids` helper function.


Usage

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

Parameters

$attached_tag_ids (mixed)

Return Value

The filtered value.


Examples

// Example of how to use the 'automator_fluentcrm_subscriber_pivot_tags' filter.
// This filter allows you to modify the behavior of how FluentCRM tags are checked
// for a subscriber. By default, the plugin might perform a check using SubscriberPivot::whereIn.
// This example demonstrates how you could potentially disable that check entirely
// or conditionally modify the tag IDs based on certain criteria.
add_filter( 'automator_fluentcrm_subscriber_pivot_tags', 'my_custom_automator_fluentcrm_tag_logic', 10, 2 );

/**
 * Custom logic to conditionally disable or modify FluentCRM tag checks for Automator.
 *
 * @param mixed $disable_pivot_check  The current value of the filter, typically 'true' to disable the pivot check.
 * @param array $attached_tag_ids   An array of tag IDs attached to the subscriber.
 *
 * @return mixed The modified value to control the pivot check.
 */
function my_custom_automator_fluentcrm_tag_logic( $disable_pivot_check, $attached_tag_ids ) {

	// Example: If the subscriber has a specific tag (e.g., tag ID 123),
	// we might want to *force* the pivot check by returning false.
	// This assumes that if the tag ID is not found in $attached_tag_ids,
	// the original check would have failed anyway.
	$specific_tag_to_force_check = 123;

	if ( in_array( $specific_tag_to_force_check, $attached_tag_ids, true ) ) {
		// If the specific tag is present, we want to ensure the pivot check runs.
		// Returning 'false' here will bypass the 'if ($disable_pivot_check)' block
		// in the original function, causing the pivot check to be executed.
		return false;
	}

	// Example: If we want to always disable the pivot check, regardless of tags,
	// we would simply return true.
	// return true;

	// In this example, we'll keep the default behavior if the specific tag isn't found.
	// If $disable_pivot_check is true (the default), the pivot check is bypassed.
	// If it's false, the pivot check will proceed.
	return $disable_pivot_check;
}

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/fluent-crm/helpers/fluent-crm-helpers.php:384

public function get_attached_tag_ids( $attached_tag_ids ) {

		/**
		 * SubscriberPivot::whereIn is causing the list ids to return an empty array.
		 *
		 * @since 4.4
		 */
		$disable_pivot_check = apply_filters( 'automator_fluentcrm_subscriber_pivot_tags', true, $attached_tag_ids );

		// Disable the pivot check by default since $attached_list_ids already returns the ids.
		if ( $disable_pivot_check ) {

			return $attached_tag_ids;

		}

		/*
		 * This action is triggered by three different processes and returns either list ids
		 * or pivot ids(table: wp_fc_subscriber_pivot)
		 */
		$list_ids = array();

		// Just check to see if the user is logged in or not.
		if ( ! is_user_logged_in() ) {
			$list_ids = $attached_tag_ids;
		}

		$request_type = automator_filter_input( 'type', INPUT_POST );

		if ( ! empty( $request_type ) ) {
			// the $attached_list_ids are actually pivot IDs
			$pivots = SubscriberPivot::whereIn( 'id', $attached_tag_ids )->get();
			if ( ! empty( $pivots ) ) {
				foreach ( $pivots as $pivot ) {
					$list_ids[] = $pivot->object_id;
				}
			}
		} else {
			$list_ids = $attached_tag_ids;
		}

		return $list_ids;
	}

Scroll to Top