Filter
uncanny-automator
uap_option_list_ninja_forms
Filters the options available for Ninja Forms integration within the Ultimate Affiliate Pro plugin.
add_filter( 'uap_option_list_ninja_forms', $callback, 10, 1 );
Description
Filters the list of available tokens for Ninja Forms. Developers can use this hook to add custom tokens or modify existing ones for Ninja Forms submissions within Uncanny Automator, enabling more dynamic trigger and action configurations.
Usage
add_filter( 'uap_option_list_ninja_forms', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter contains the Ninja Forms option, which can be a label, an option code, or an array of arguments.
Return Value
The filtered value.
Examples
add_filter(
'uap_option_list_ninja_forms',
function ( $option ) {
// Example: Add a custom token for the Ninja Forms plugin within Uncanny Automator.
// This assumes the $option variable is an array and we want to add a new key
// to the 'relevant_tokens' sub-array.
// Check if the 'relevant_tokens' key exists and is an array
if ( isset( $option['relevant_tokens'] ) && is_array( $option['relevant_tokens'] ) ) {
// Add a new custom token. For demonstration, let's say we want to add
// a token for the "Form Creation Date".
// In a real scenario, you'd likely fetch this information from Ninja Forms.
$option['relevant_tokens']['FORM_CREATION_DATE'] = esc_attr__( 'Form Creation Date', 'your-text-domain' );
}
// It's crucial to return the modified $option array for the filter to work.
return $option;
},
10, // Priority: 10 is the default, can be adjusted
1 // Accepted Args: The hook passes only one argument ($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/ninja-forms/helpers/ninja-forms-helpers.php:99
public function list_ninja_forms( $label = null, $option_code = 'NFFORMS', $args = array() ) {
if ( ! $label ) {
$label = esc_attr__( 'Form', '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();
if ( Automator()->helpers->recipe->load_helpers ) {
$forms = Ninja_Forms()->form()->get_forms();
if ( ! empty( $forms ) ) {
foreach ( $forms as $form ) {
$options[ $form->get_id() ] = esc_html( $form->get_setting( 'title' ) );
}
}
}
$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' => array(
$option_code => esc_attr__( 'Form title', 'uncanny-automator' ),
$option_code . '_ID' => esc_attr__( 'Form ID', 'uncanny-automator' ),
'SUBMISSION_ID' => esc_attr__( 'Submission ID', 'uncanny-automator' ),
),
);
return apply_filters( 'uap_option_list_ninja_forms', $option );
}