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