Skip to content

Instantly share code, notes, and snippets.

@MervinHernandez
Created December 20, 2019 01:53
Show Gist options
  • Save MervinHernandez/4c2b7f595f39f6ed9ca59c7559ecce30 to your computer and use it in GitHub Desktop.
Save MervinHernandez/4c2b7f595f39f6ed9ca59c7559ecce30 to your computer and use it in GitHub Desktop.
Gravity Forms - Unrequire Fields for Testing
/**
* 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