Skip to content

Instantly share code, notes, and snippets.

@spivurno
Last active April 10, 2021 22:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spivurno/c37ee64c1a63300e90fe9db6218e959a to your computer and use it in GitHub Desktop.
Save spivurno/c37ee64c1a63300e90fe9db6218e959a to your computer and use it in GitHub Desktop.
Gravity Perks // GP Read Only // Disable Read Only for Admins
<?php
/**
* Gravity Perks // GP Read Only // Disable Read Only for Admins
* http://gravitywiz.com/
*/
add_filter( 'gform_pre_render', function( $form ) {
foreach( $form['fields'] as $field ) {
if( gw_has_css_class( $field, 'gp-read-only-except-admin' ) && current_user_can( 'administrator' ) ) {
$field->gwreadonly_enable = false;
}
}
return $form;
} );
/**
* Gravity Wiz // Gravity Forms // gw_has_css_class()
*
* A simple function to determine whether a form or field object has the specified CSS class.
*
* @author David Smith <david@gravitywiz.com>
* @license GPL-2.0+
* @link http://gravitywiz.com/...
*/
if( ! function_exists( 'gw_has_css_class' ) ) {
function gw_has_css_class( $form_or_field, $class ) {
if( ! isset( $form_or_field['cssClass'] ) ) {
return false;
} else {
$classes = array_map( 'trim', explode( ' ', $form_or_field['cssClass'] ) );
return in_array( $class, $classes );
}
}
}
@spivurno
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment