Last active
April 10, 2021 22:46
-
-
Save spivurno/c37ee64c1a63300e90fe9db6218e959a to your computer and use it in GitHub Desktop.
Gravity Perks // GP Read Only // Disable Read Only for Admins
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
<?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 ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👉 This Gist has been migrated to the Gravity Wiz Snippet Library:
https://github.com/gravitywiz/snippet-library/blob/master/gp-read-only/gpro-disable-for-admins.php