Skip to content

Commit 0867ddf

Browse files
authored
gpro-readonly-on-edit.php: Added a snippet to provide disable editing functionality on GPEB, GravityView and Gravity Flow User Input.
1 parent d0ea3e5 commit 0867ddf

File tree

2 files changed

+47
-27
lines changed

2 files changed

+47
-27
lines changed
+3-27
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
11
<?php
22
/**
3-
* Gravity Perks // Entry Blocks // Set Fields as Readonly On Edit
4-
* https://gravitywiz.com/documentation/gravity-forms-entry-blocks/
5-
*
6-
* Configure fields to be readonly when editing via Entry Blocks by adding the "gpeb-readonly-on-edit" class to the
7-
* field's CSS Class Name field setting.
3+
* This snippet has evolved! 🦄
4+
* Find the new version of this snippet here:
5+
* https://github.com/gravitywiz/snippet-library/blob/master/gp-read-only/gpro-readonly-on-edit.php
86
*/
9-
add_filter( 'gform_pre_render', 'gpeb_set_readonly_on_edit' );
10-
add_filter( 'gform_pre_process', 'gpeb_set_readonly_on_edit' );
11-
12-
function gpeb_set_readonly_on_edit( $form ) {
13-
14-
$is_block = (bool) rgpost( 'gpeb_entry_id' );
15-
if ( ! $is_block ) {
16-
$is_block = class_exists( 'WP_Block_Supports' ) && rgar( WP_Block_Supports::$block_to_render, 'blockName' ) === 'gp-entry-blocks/edit-form';
17-
}
18-
19-
if ( ! $is_block ) {
20-
return $form;
21-
}
22-
23-
foreach ( $form['fields'] as &$field ) {
24-
if ( strpos( $field->cssClass, 'gpeb-readonly-on-edit' ) !== false ) {
25-
$field->gwreadonly_enable = true;
26-
}
27-
}
28-
29-
return $form;
30-
}
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Gravity Perks // GP Read Only // Set Fields as Readonly On Edit
4+
* https://gravitywiz.com/documentation/gravity-forms-read-only/
5+
*
6+
* Configure fields to be readonly when editing via Entry Blocks or GravityView or Gravity Flow User Input Step.
7+
*
8+
* Usage:
9+
*
10+
* 1. Install this code as a plugin or as a snippet.
11+
* 2. Add the `gpro-readonly-on-edit` CSS Class Name to field's Custom CSS Class setting.
12+
*
13+
* Plugin Name: GP Read Only — Set Fields as Readonly On Edit
14+
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-read-only/
15+
* Description: This snippet allows you to set read only for fields when editing.
16+
* Author: Gravity Wiz
17+
* Version: 0.1
18+
* Author URI: https://gravitywiz.com/
19+
*/
20+
21+
add_filter( 'gform_pre_render', 'gpeb_set_readonly_on_edit' );
22+
add_filter( 'gform_pre_process', 'gpeb_set_readonly_on_edit' );
23+
24+
function gpeb_set_readonly_on_edit( $form ) {
25+
26+
$is_block = (bool) rgpost( 'gpeb_entry_id' );
27+
if ( ! $is_block ) {
28+
$is_block = class_exists( 'WP_Block_Supports' ) && rgar( WP_Block_Supports::$block_to_render, 'blockName' ) === 'gp-entry-blocks/edit-form';
29+
}
30+
31+
$is_gravityview = function_exists( 'gravityview' ) && gravityview()->request->is_edit_entry();
32+
$is_gravity_flow = rgget( 'lid' ) && rgget( 'page' ) == 'gravityflow-inbox';
33+
34+
// disable the target field for GPEB, GravityView and Gravity Flow User Input step.
35+
if ( $is_block || $is_gravityview || $is_gravity_flow ) {
36+
foreach ( $form['fields'] as &$field ) {
37+
if ( strpos( $field->cssClass, 'gpro-readonly-on-edit' ) !== false ) {
38+
$field->gwreadonly_enable = true;
39+
}
40+
}
41+
}
42+
43+
return $form;
44+
}

0 commit comments

Comments
 (0)