Filter
uncanny-automator
uap_option_list_all_give_forms
Filters the list of all available Give forms for use in the Ultimate Affiliate Pro plugin, allowing for customization before display.
add_filter( 'uap_option_list_all_give_forms', $callback, 10, 1 );
Description
Filters the list of all GiveWP forms used for select options. Developers can use this hook to modify the array of form data, adding or removing forms before they are displayed in an option list. This hook fires when generating the form list for integrations.
Usage
add_filter( 'uap_option_list_all_give_forms', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter represents the current value of the option being filtered, allowing modifications to the list of GiveWP forms.
Return Value
The filtered value.
Examples
add_filter( 'uap_option_list_all_give_forms', 'my_uap_modify_give_forms_options', 10, 1 );
/**
* Modifies the options passed to the 'uap_option_list_all_give_forms' filter.
* This function is intended to add or remove specific GiveWP forms from the list
* that will be presented in the Ultimate Affiliate Program plugin's settings,
* perhaps based on certain criteria or to pre-select certain forms.
*
* @param array $option The array of options being filtered, typically containing 'options' which is an array of GiveWP forms.
* @return array The modified array of options.
*/
function my_uap_modify_give_forms_options( $option ) {
// Check if 'options' key exists and is an array, and if it contains forms.
if ( isset( $option['options'] ) && is_array( $option['options'] ) && ! empty( $option['options'] ) ) {
// Example: Remove any GiveWP forms that are marked as "draft".
// This assumes the structure of the $option['options'] array contains
// information about the form's status. You would need to inspect
// the actual structure of $option['options'] to know the exact key
// for the form status. For this example, let's assume a key like 'status'.
$option['options'] = array_filter( $option['options'], function( $give_form ) {
// Assuming $give_form is an array or object representing a GiveWP form.
// Replace 'status' with the actual key if it's different.
// For demonstration, let's assume a form object with a get_status() method.
if ( is_object( $give_form ) && method_exists( $give_form, 'get_status' ) ) {
return $give_form->get_status() !== 'draft';
}
// If it's an array, try to access status. Replace 'status' with actual key.
if ( is_array( $give_form ) && isset( $give_form['status'] ) ) {
return $give_form['status'] !== 'draft';
}
// If we can't determine the status, keep the form by default.
return true;
} );
// Example: Pre-select a specific GiveWP form by setting its ID in 'fill_values_in'.
// Let's say we want to always pre-select the form with ID 123.
// This part depends heavily on how Ultimate Affiliate Program handles pre-selection.
// If 'fill_values_in' is meant to be the ID of the form to pre-fill, then:
// if ( ! empty( $option['options'] ) ) {
// $option['fill_values_in'] = 123;
// }
// Example: Add a custom option to the list of forms.
// This might be useful if you want to add a placeholder option.
// $custom_option = array(
// 'id' => 'no_form_selected',
// 'name' => __( '--- Select a Form ---', 'your-text-domain' ),
// );
// array_unshift( $option['options'], $custom_option ); // Add to the beginning
}
// Always return the $option array, even if modified.
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/give/helpers/give-helpers.php:88
public function list_all_give_forms( $label = null, $option_code = 'MAKEDONATION', $args = array(), $tokens = array() ) {
if ( ! $label ) {
$label = esc_html_x( 'Form', 'Give', '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'] : '';
$options = array();
$query_args = array(
'post_type' => 'give_forms',
'posts_per_page' => 9999,
'post_status' => 'publish',
);
$options = Automator()->helpers->recipe->wp_query( $query_args, true, esc_html_x( 'Any form', 'Give', 'uncanny-automator' ) );
$type = 'select';
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => $type,
'required' => true,
'supports_tokens' => $token,
'is_ajax' => $is_ajax,
'fill_values_in' => $target_field,
'endpoint' => $end_point,
'options' => $options,
'relevant_tokens' => $tokens,
);
return apply_filters( 'uap_option_list_all_give_forms', $option );
}