Filter
Since 4.4
uncanny-automator
automator_fluentcrm_subscriber_pivot_list
SubscriberPivot::whereIn is causing the list ids to return an empty array. Filters subscriber attached list IDs when FluentCRM subscriber pivot is processed to prevent empty arrays.
add_filter( 'automator_fluentcrm_subscriber_pivot_list', $callback, 10, 1 );
Description
Filters whether FluentCRM subscriber pivot checks are enabled. By default, this filter returns true, disabling the pivot check as subscriber IDs are often directly available. Developers can return false to enforce the pivot check if needed, though it may lead to empty results in certain scenarios.
Usage
add_filter( 'automator_fluentcrm_subscriber_pivot_list', 'your_function_name', 10, 1 );
Parameters
-
$attached_list_ids(mixed)
Return Value
The filtered value.
Examples
add_filter( 'automator_fluentcrm_subscriber_pivot_list', 'my_custom_automator_fluentcrm_subscriber_pivot_list', 10, 2 );
/**
* Example filter to conditionally disable the FluentCRM subscriber pivot check.
*
* This function demonstrates how to conditionally modify the behavior of the
* 'automator_fluentcrm_subscriber_pivot_list' hook. By default, the pivot
* check is disabled. This example shows how you might enable it under
* specific conditions, for instance, if the `$attached_list_ids` parameter
* is an empty array and you want to force a pivot check to ensure no lists
* are erroneously assigned.
*
* @param bool $disable_pivot_check The current value of the filter, defaults to true.
* @param array|string|int $attached_list_ids The list IDs being processed.
* @return bool The modified value to control the pivot check.
*/
function my_custom_automator_fluentcrm_subscriber_pivot_list( $disable_pivot_check, $attached_list_ids ) {
// If $attached_list_ids is empty, and we want to ensure a proper check
// is performed, we might want to disable the default behavior of skipping the check.
if ( empty( $attached_list_ids ) ) {
// For demonstration purposes, let's say we want to *enable* the pivot check
// specifically when there are no list IDs provided, to potentially fetch
// a broader set or log an anomaly.
return false; // Disable the default disabling of the pivot check
}
// Otherwise, keep the default behavior or add other custom logic.
// For this example, we'll stick to the default if lists are provided.
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:340
public function get_attached_list_ids( $attached_list_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_list', true, $attached_list_ids );
// Disable the pivot check by default since $attached_list_ids already returns the ids.
if ( $disable_pivot_check ) {
return $attached_list_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();
$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_list_ids )->get();
if ( ! empty( $pivots ) ) {
foreach ( $pivots as $pivot ) {
$list_ids[] = $pivot->object_id;
}
}
} else {
$list_ids = $attached_list_ids;
}
return $list_ids;
}