-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathgpro-disable-for-admins.php
30 lines (30 loc) · 1.16 KB
/
gpro-disable-for-admins.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
/**
* Gravity Perks // GP Read Only // Disable Read Only for Admins
* https://gravitywiz.com/documentation/gravity-forms-read-only/
*
* Instruction Video: https://www.loom.com/share/24aaeb27fce44dc98355b78168d6fe5d
*
* Disable the Read Only property on fields for Admin users.
* This is useful when wanting to allow administrative users to edit fields that non-admins should not be able to edit.
*
* Usage:
*
* 1. Install this code as a plugin or as a snippet.
* 2. Add the `gp-read-only-except-admin` CSS Class Name to field's Custom CSS Class setting.
*
* Plugin Name: GP Read Only — Disable Read Only for Admins
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-read-only/
* Description: This snippet allows you to disbale the Read Only property on fields for Admin users.
* Author: Gravity Wiz
* Version: 0.1
* Author URI: https://gravitywiz.com/
*/
add_filter( 'gform_pre_render', function( $form ) {
foreach ( $form['fields'] as $field ) {
if ( strpos( $field->cssClass, 'gp-read-only-except-admin' ) !== false && current_user_can( 'administrator' ) ) {
$field->gwreadonly_enable = false;
}
}
return $form;
} );