Last active
May 21, 2016 02:21
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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