Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Wrap hooks for a specific form.
*
* @param int $form_id
*/
add_action( 'nf_get_form_id', function( $form_id ){
// Check for a specific Form ID.
if( 21 !== $form_id ) return;
/**
* Change a field's settings when localized to the page.
* ninja_forms_localize_field_{$field_type}
*
* @param array $field [ id, settings => [ type, key, label, etc. ] ]
* @return array $field
*/
add_filter( 'ninja_forms_localize_field_checkbox', function( $field ){
if( 'checkbox_1527003278102' == $field[ 'settings' ][ 'key' ] ){
// Change the `default_value` setting of the checkbox field.
$field[ 'settings' ][ 'default_value' ] = 'checked';
}
return $field;
});
} );
<?php
/**
* Change a field's settings when localized to the page.
* ninja_forms_localize_field_{$field_type}
*
* @param array $field [ id, settings => [ type, key, label, etc. ] ]
* @return array $field
*/
add_filter( 'ninja_forms_localize_field_checkbox', function( $field ){
// Change the `default_value` setting of the checkbox field.
$field[ 'settings' ][ 'default_value' ] = 'checked';
return $field;
});
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.