Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.