Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Update list options during form render.
*
* @param array $options [ [ label, value, calc, (bool) selected, etc ], ... ]
* @param array $settings
*/
add_filter( 'ninja_forms_render_options', function( $options, $settings ) {
$options[] = [
'label' => 'New Option',
'value' => 'new',
'calc' => 0,
'selected' => true
];
return $options;
}, 10, 2 );
<?php
/**
* Update list options during form render.
*
* @param array $options [ [ label, value, calc, (bool) selected, etc ], ... ]
* @param array $settings
*/
add_filter( 'ninja_forms_render_options', function( $options, $settings ) {
$options_before[] = [
'label' => 'Before',
'value' => 'before',
'calc' => 0,
'selected' => true
];
$options_after[] = [
'label' => 'After',
'value' => 'after',
'calc' => 0,
'selected' => false
];
return array_merge( $options_before, $options, $options_after );
}, 10, 2 );
<?php
/**
* Update country list options during form render.
*
* @priority >10 After the Country List is populated.
*
* @param array $options [ [ label, value, calc, (bool) selected, etc ], ... ]
* @param array $settings
*/
add_filter( 'ninja_forms_render_options_listcountry', function( $options, $settings ) {
return $options;
}, 11, 2 );
<?php
/**
* Update list options during form render.
*
* @param array $options [ [ label, value, calc, (bool) selected, etc ], ... ]
* @param array $settings
*/
add_filter( 'ninja_forms_render_options', function( $options, $settings ) {
foreach( $options as &$option ) {
if( 'two' == $option[ 'value' ] ){
$option[ 'selected' ] = true;
} else {
$option[ 'selected' ] = false;
}
}
return $options;
}, 10, 2 );
<?php
/**
* Update list options during form render.
*
* @param array $options [ [ label, value, calc, (bool) selected, etc ], ... ]
* @param array $settings
*/
add_filter( 'ninja_forms_render_options', function( $options, $settings ) {
return $options;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.