Filter uncanny-automator

uap_option_get_all_affiliates

Filters all affiliate data before it's retrieved, allowing modification of the entire affiliate list.

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

Description

Filters the options array for the "All Affiliates" dropdown. Developers can modify the displayed affiliates or their properties before they are presented in automations or settings, offering fine-grained control over affiliate selection.


Usage

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

Parameters

$option (mixed)
This parameter contains the option code that determines which affiliate options will be retrieved.

Return Value

The filtered value.


Examples

/**
 * Example of using the 'uap_option_get_all_affiliates' filter.
 *
 * This example demonstrates how to modify the list of affiliates returned by the hook.
 * It might be used to filter out inactive affiliates or to add custom affiliate data.
 *
 * @param array $option The original array of affiliate options.
 * @return array The modified array of affiliate options.
 */
add_filter( 'uap_option_get_all_affiliates', 'my_custom_affiliate_filter', 10, 1 );

function my_custom_affiliate_filter( $option ) {

	// In a real-world scenario, you might fetch affiliate data from your own plugin
	// or the WordPress database, and then merge it or filter the existing $option.
	// For this example, we'll simulate modifying the existing options.

	// Let's say we want to remove affiliates whose username starts with 'test_'.
	if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {
		$filtered_options = array();
		foreach ( $option['options'] as $key => $affiliate_data ) {
			// Assuming $affiliate_data is an array with at least a 'label' key.
			// Adjust this condition based on the actual structure of $option['options'].
			if ( isset( $affiliate_data['label'] ) && strpos( $affiliate_data['label'], 'test_' ) === 0 ) {
				continue; // Skip this affiliate
			}
			$filtered_options[ $key ] = $affiliate_data;
		}
		$option['options'] = $filtered_options;
	}

	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/easy-affiliate/helpers/easy-affiliate-helpers.php:52

public function get_all_affiliates( $option_code, $add_any = true ) {

		$options = array();

		if ( $add_any ) {
			$options['-1'] = esc_html__( 'Any affiliate', 'uncanny-automator' );
		}

		$args = array(
			'meta_query' => array(
				array(
					'key'     => 'wafp_is_affiliate',
					'value'   => '1',
					'compare' => '=',
				),
			),
		);

		$affiliates = get_users( $args );

		foreach ( $affiliates as $user ) {
			$options[ $user->ID ] = $user->display_name;
		}

		$option = array(
			'input_type'            => 'select',
			'option_code'           => $option_code,
			/* translators: HTTP request method */
			'label'                 => esc_attr__( 'Affiliate', 'uncanny-automator' ),
			'required'              => true,
			'supports_custom_value' => true,
			'options'               => $options,
		);

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

Scroll to Top