Skip to content

Instantly share code, notes, and snippets.

@kjohnson
Last active May 22, 2018 15:15
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/cbd382a1014b8b3cc4cf8ab92e867011 to your computer and use it in GitHub Desktop.
Save kjohnson/cbd382a1014b8b3cc4cf8ab92e867011 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( 19 !== $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_number', function( $field ){
if( 'number_1527000740297' !== $field[ 'settings' ][ 'key' ] ) return $field;
// Check for a `min` value as a querystring. ex site.com/?min=12
if( ! isset( $_GET[ 'min' ] ) ) return $field;
// Change the `min` setting of the number field.
$field[ 'settings' ][ 'num_min' ] = intval( $_GET[ 'min' ] );
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_number', function( $field ){
// Change the `min` setting of the number field.
$field[ 'settings' ][ 'num_min' ] = 12;
return $field;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment