Filter uncanny-automator

uap_option_contact_statuses

Filters the available contact status options before they are displayed, allowing for customization of these statuses.

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

Description

Fires after Jet CRM contact statuses are fetched. Developers can filter these statuses to modify the available options in select fields within Jet CRM integrations, such as altering labels or excluding specific statuses.


Usage

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

Parameters

$option (mixed)
This parameter contains the current value of the `$option_code` which represents the contact status option.

Return Value

The filtered value.


Examples

// Add a new contact status option to the list for UAP integrations.
add_filter(
	'uap_option_contact_statuses',
	function ( $option ) {
		// Assume $option is an array of existing contact status options.
		// We want to add a new status called 'Pending Verification'.

		// In a real scenario, you might fetch this from a custom database table
		// or define it based on other plugin settings.
		$new_status_id   = 99; // A unique ID for the new status.
		$new_status_name = 'Pending Verification';

		// Ensure the 'options' key exists and is an array before adding.
		if ( ! isset( $option['options'] ) || ! is_array( $option['options'] ) ) {
			$option['options'] = array();
		}

		// Add the new option to the 'options' array.
		// The key is the status ID, and the value is the status name.
		$option['options'][ $new_status_id ] = $new_status_name;

		// You might also want to ensure other required keys like 'input_type',
		// 'required', etc., are correctly set if you are modifying the entire $option structure.
		// For this example, we're only adding to the 'options'.

		return $option;
	},
	10, // Priority: 10 is the default, adjust as needed.
	1   // Accepted args: The filter passes only one argument ($option).
);

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/jet-crm/helpers/jet-crm-helpers.php:54

public function contact_statuses( $option_code, $is_any = false, $tokens = array() ) {

		global $zbsCustomerFields;
		$customer_fields = is_array( $zbsCustomerFields ) && isset( $zbsCustomerFields['status'] ) ? $zbsCustomerFields['status'] : array();
		$statuses        = is_array( $customer_fields ) && isset( $customer_fields[3] ) ? $customer_fields[3] : array();
		$options         = ! empty( $statuses ) ? array_combine( $statuses, $statuses ) : array();

		// Load defaults if empty.
		if ( empty( $options ) ) {
			$options = array(
				'Lead'                         => esc_html__( 'Lead', 'uncanny-automator' ),
				'Customer'                     => esc_html__( 'Customer', 'uncanny-automator' ),
				'Blacklisted'                  => esc_html__( 'Blacklisted', 'uncanny-automator' ),
				'Cancelled by Customer'        => esc_html__( 'Cancelled by Customer', 'uncanny-automator' ),
				'Cancelled by Us (Post-Quote)' => esc_html__( 'Cancelled by Us (Post-Quote)', 'uncanny-automator' ),
				'Cancelled by Us (Pre-Quote)'  => esc_html__( 'Cancelled by Us (Pre-Quote)', 'uncanny-automator' ),
				'Refused'                      => esc_html__( 'Refused', 'uncanny-automator' ),
			);
		}

		// Add Any Option.
		if ( true === $is_any ) {
			$options = array( '-1' => esc_html__( 'Any status', 'uncanny-automator' ) ) + $options;
		}

		$option = array(
			'option_code'     => $option_code,
			'label'           => esc_attr__( 'Status', 'uncanny-automator' ),
			'input_type'      => 'select',
			'required'        => true,
			'options_show_id' => false,
			'relevant_tokens' => $tokens,
			'options'         => $options,
		);

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

Scroll to Top