Filter uncanny-automator

uap_option_get_all_codes

Filters all Uncanny Codes options and settings before they are retrieved by the system.

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

Description

Fires after all available Uncanny Codes option codes and their associated labels are gathered. Developers can filter this array to add, remove, or modify option codes and their labels before they are returned. Use this to dynamically manage available codes for integrations.


Usage

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

Parameters

$option (mixed)
This parameter is typically an option code, used to specify which set of codes to retrieve.

Return Value

The filtered value.


Examples

// Example of filtering the 'uap_option_get_all_codes' hook to add a new relevant token.
// This hook is used by Uncanny Automator to retrieve available tokens for code-related options.
add_filter( 'uap_option_get_all_codes', 'my_custom_uap_add_code_token', 10, 1 );

/**
 * Adds a custom token to the 'uap_option_get_all_codes' filter.
 *
 * This function demonstrates how to modify the array of relevant tokens
 * returned by the 'uap_option_get_all_codes' hook to include additional
 * information related to a code.
 *
 * @param array $option The original array of options and relevant tokens.
 * @return array The modified array of options and relevant tokens.
 */
function my_custom_uap_add_code_token( $option ) {
	// Check if the current option being processed is of a specific type we want to modify.
	// For demonstration, let's assume we're targeting an option where $option_code is 'MY_CUSTOM_CODE'.
	// In a real scenario, you would likely check $option['code'] or a similar identifier within $option.
	// Since the provided source context doesn't expose the original $option_code directly here,
	// we'll simulate checking if the 'relevant_tokens' array exists and has a specific structure
	// that implies it's a code-related option we want to augment.
	if ( isset( $option['relevant_tokens'] ) && is_array( $option['relevant_tokens'] ) ) {

		// Let's assume $option_code is available in the scope where the filter is applied.
		// In this example, we'll define a hypothetical $option_code for demonstration.
		// In a real Uncanny Automator integration, this $option_code would likely be dynamically determined.
		$hypothetical_option_code = 'MY_PRODUCT_LICENSE'; // Example: A license code

		// Add a new relevant token for the license expiration date.
		// This assumes that the code option also has an associated expiration date available.
		// In a real integration, you'd fetch this data.
		$option['relevant_tokens'][ $hypothetical_option_code . '_EXPIRATION' ] = esc_attr__( 'License Expiration Date', 'uncanny-automator' );

		// You could also modify existing tokens or add conditional tokens based on the $option data.
		// For example, if the code has a status:
		// $option['relevant_tokens'][ $hypothetical_option_code . '_STATUS' ] = esc_attr__( 'License Status', 'uncanny-automator' );
	}

	// Always return the modified (or original) $option array.
	return $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/uncanny-codes/helpers/uncanny-codes-helpers.php:71

public function get_all_codes( $label = null, $option_code = 'UNCANNYCODES' ) {

		if ( ! $label ) {
			$label = esc_attr__( 'Code', 'uncanny-automator' );
		}

		global $wpdb;

		$options = array();

		$all_codes = $wpdb->get_results( 'SELECT ID,code FROM ' . $wpdb->prefix . 'uncanny_codes_codes', ARRAY_A );

		foreach ( $all_codes as $code ) {
			$options[ $code['ID'] ] = $code['code'];
		}

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

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

Scroll to Top