Filter
uncanny-automator
uap_option_get_referral_types
Filters the available referral types used within the AffiliateWP integration before they are retrieved.
add_filter( 'uap_option_get_referral_types', $callback, 10, 1 );
Description
Fires after referral types are retrieved for AffiliateWP integration. Developers can use this filter to modify, add, or remove referral types available for integration, influencing how AffiliateWP data interacts with your plugin. The `$option` parameter contains the current referral types array.
Usage
add_filter( 'uap_option_get_referral_types', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter is the current value of the referral types option that is being filtered.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the 'uap_option_get_referral_types' filter to add a custom referral type.
*
* This example demonstrates how to modify the array of referral types returned by the hook.
* We'll add a new 'custom_lead_generation' referral type with specific settings.
*/
function my_custom_uap_referral_types( $option ) {
// Ensure $option is an array before proceeding.
if ( ! is_array( $option ) ) {
return $option;
}
// Define our new custom referral type.
$custom_referral_type = array(
'name' => __( 'Custom Lead Generation', 'your-text-domain' ), // User-friendly name
'description' => __( 'Referrals generated from specific custom lead forms.', 'your-text-domain' ), // Description
'supports_tokens' => true, // This type supports dynamic tokens
'is_ajax' => false, // This type does not require AJAX for processing
'fill_values_in' => 'custom_lead_field', // A hypothetical target field in your form
'endpoint' => 'custom-lead-endpoint', // A hypothetical API endpoint
'options' => array( // Additional options specific to this type
'lead_source' => 'website_form',
'form_id' => 123,
),
);
// Add our custom referral type to the existing array.
// You can choose to prepend or append based on your needs.
// Here, we're appending it.
$option['custom_lead_generation'] = $custom_referral_type;
// It's crucial to return the modified array.
return $option;
}
// Add the filter. The second parameter '1' indicates that our callback function
// accepts only one argument (the $option array).
add_filter( 'uap_option_get_referral_types', 'my_custom_uap_referral_types', 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/affiliate-wp/helpers/affwp-helpers.php:94
public function get_referral_types( $label = null, $option_code = 'REFERRALTYPES', $args = array() ) {
if ( ! $label ) {
$label = esc_html__( 'Referral type', 'uncanny-automator' );
}
$token = key_exists( 'token', $args ) ? $args['token'] : false;
$is_ajax = key_exists( 'is_ajax', $args ) ? $args['is_ajax'] : false;
$target_field = key_exists( 'target_field', $args ) ? $args['target_field'] : '';
$end_point = key_exists( 'endpoint', $args ) ? $args['endpoint'] : '';
$any_option = key_exists( 'any_option', $args ) ? $args['any_option'] : false;
$options = array();
if ( isset( $any_option ) && $any_option == true ) {
$options['-1'] = esc_html__( 'Any type', 'uncanny-automator' );
}
foreach ( affiliate_wp()->referrals->types_registry->get_types() as $type_id => $type ) {
$title = $type['label'];
if ( empty( $title ) ) {
// translators: 1: Referral type ID
$title = sprintf( esc_html__( 'ID: %s (no title)', 'uncanny-automator' ), $type_id );
}
$options[ $type_id ] = $title;
}
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
'supports_tokens' => $token,
'is_ajax' => $is_ajax,
'fill_values_in' => $target_field,
'endpoint' => $end_point,
'options' => $options,
);
return apply_filters( 'uap_option_get_referral_types', $option );
}