Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kjohnson/3cd21818d5becbd532e966cbd79087a1 to your computer and use it in GitHub Desktop.
Save kjohnson/3cd21818d5becbd532e966cbd79087a1 to your computer and use it in GitHub Desktop.
<?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