Skip to content

Instantly share code, notes, and snippets.

@kjbrum
Last active May 21, 2016 02:21
Show Gist options
  • Save kjbrum/444d555c5fe0280cef78 to your computer and use it in GitHub Desktop.
Save kjbrum/444d555c5fe0280cef78 to your computer and use it in GitHub Desktop.
Un-require all required fields so you don't have to fill them out.Place this snippet into your functions.php file and then add the gfunrequire=1 parameter to the url of the page your form is on.
<?php
/**
* Gravity Forms Unrequire.
* Unrequire all required fields so you don't have to fill them out during testing.
*/
class GravityFormsUnrequire {
var $args = null;
public function __construct( $args = array() ) {
extract( wp_parse_args( $args, array(
'admins_only' => true,
'require_query_param' => false
)));
if( $admins_only && ! current_user_can( 'activate_plugins' ) )
return;
if( $require_query_param && ! isset( $_GET['gfunrequire'] ) )
return;
add_filter( 'gform_pre_validation', array( $this, 'unrequire_fields' ) );
}
function unrequire_fields( $form ) {
foreach( $form['fields'] as &$field ) {
$field['isRequired'] = false;
}
return $form;
}
}
new GravityFormsUnrequire();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment