Filter uncanny-automator

uap_option_get_all_jetpack_companies

Filters all Jetpack companies before they are retrieved for use within the CRM.

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

Description

Filter all Jetpack companies retrieved for Jet CRM integration. Developers can modify the array of companies before they are used in Jet CRM settings, allowing for custom filtering or manipulation of available company options.


Usage

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

Parameters

$option (mixed)
This parameter represents the option code being requested for Jetpack companies.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of filtering the 'uap_option_get_all_jetpack_companies' hook.
 *
 * This example demonstrates how to modify the list of Jetpack companies
 * returned by the `uap_option_get_all_jetpack_companies` filter.
 * In this specific scenario, we're adding a custom company to the list
 * and also modifying the 'supports_custom_value' flag for an existing one.
 *
 * @param array $option The original array of Jetpack company options.
 * @return array The modified array of Jetpack company options.
 */
function my_custom_jetpack_companies_filter( $option ) {
	// Check if the 'options' key exists and is an array.
	if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {

		// Add a custom company to the list.
		$option['options']['custom_company_id'] = array(
			'id'   => 'custom_company_id',
			'name' => 'My Awesome Custom Company',
		);

		// Example: Find a specific company and modify its properties.
		// Let's assume 'jetpack_partner_company' is a known ID.
		if ( isset( $option['options']['jetpack_partner_company'] ) ) {
			// For instance, if we want to ensure this company always supports custom values.
			// Note: The original code passes $supports_custom_value directly to the option.
			// Here we're conceptually showing how you might modify it *within* the company data itself if structured differently.
			// For the purpose of this example, let's assume 'supports_custom_value' could be part of each company's data.
			// However, based on the source context, it's a top-level key.
			// So, let's illustrate modifying a different aspect if needed, or ensuring a custom value is supported.
			// Since 'supports_custom_value' is a top-level option in the provided snippet,
			// we'll focus on adding/modifying the 'options' array itself.

			// If 'supports_custom_value' was intended to be per company, you'd structure it like:
			// $option['options']['jetpack_partner_company']['supports_custom_value'] = true;
			// But given the source, we'll assume it's a global setting for the entire option.
			// For demonstration, let's add a new property to a company if it doesn't exist.
			$option['options']['jetpack_partner_company']['additional_info'] = 'This is special partner info.';
		}

		// You could also remove companies:
		// unset( $option['options']['some_old_company_id'] );
	}

	return $option;
}
add_filter( 'uap_option_get_all_jetpack_companies', 'my_custom_jetpack_companies_filter', 10, 1 );

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:136

public function get_all_jetpack_companies( $option_code, $is_any = false, $supports_custom_value = false, $empty_val = false ) {

		global $wpdb;
		$all_companies = $wpdb->get_results( "SELECT `ID`,`zbsco_name` FROM `{$wpdb->prefix}zbs_companies`" );
		$companies     = array();

		if ( ! empty( $all_companies ) ) {
			foreach ( $all_companies as $company ) {
				$companies[ $company->ID ] = $company->zbsco_name;
			}
		}

		if ( true === $is_any ) {
			$companies = array( '-1' => esc_html__( 'Any company', 'uncanny-automator' ) ) + $companies;
		}

		if ( true === $empty_val ) {
			$companies = array( '0' => esc_html__( 'Select a company', 'uncanny-automator' ) ) + $companies;
		}

		$option = array(
			'option_code'           => $option_code,
			'label'                 => esc_attr__( 'Company', 'uncanny-automator' ),
			'input_type'            => 'select',
			'required'              => false,
			'options_show_id'       => false,
			'relevant_tokens'       => array(),
			'options'               => $companies,
			'supports_custom_value' => $supports_custom_value,
		);

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

Scroll to Top