File tree 1 file changed +37
-0
lines changed 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Gravity Perks // Entry Blocks // Set Fields as Readonly On Edit
4
+ * https://gravitywiz.com/documentation/gravity-forms-entry-blocks/
5
+ *
6
+ * Remove fields from the Entry Blocks edit form by automatically setting the field's visibility to "administrative".
7
+ *
8
+ * Instructions
9
+ *
10
+ * 1. Install the snippet:
11
+ * https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
12
+ *
13
+ * 2. Add the "gpeb-remove-on-edit" class to the Custom CSS Class field setting for any field you want to remove from
14
+ * the edit form.
15
+ */
16
+ add_filter ( 'gform_pre_render ' , 'gpeb_remove_fields_on_edit ' );
17
+ add_filter ( 'gform_pre_process ' , 'gpeb_remove_fields_on_edit ' );
18
+
19
+ function gpeb_remove_fields_on_edit ( $ form ) {
20
+
21
+ $ is_block = (bool ) rgpost ( 'gpeb_entry_id ' );
22
+ if ( ! $ is_block ) {
23
+ $ is_block = class_exists ( 'WP_Block_Supports ' ) && rgar ( WP_Block_Supports::$ block_to_render , 'blockName ' ) === 'gp-entry-blocks/edit-form ' ;
24
+ }
25
+
26
+ if ( ! $ is_block ) {
27
+ return $ form ;
28
+ }
29
+
30
+ foreach ( $ form ['fields ' ] as &$ field ) {
31
+ if ( strpos ( $ field ->cssClass , 'gpeb-remove-on-edit ' ) !== false ) {
32
+ $ field ->visibility = 'administrative ' ;
33
+ }
34
+ }
35
+
36
+ return $ form ;
37
+ }
You can’t perform that action at this time.
0 commit comments