Created
August 12, 2025 06:29
-
-
Save saifsultanc/7b31cff00752323d226f861c4cab470f to your computer and use it in GitHub Desktop.
gpeb-test-snippet.php
This file contains hidden or 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 | |
| add_filter( 'gform_pre_render', 'gpeb_remove_fields_on_edit' ); | |
| add_filter( 'gform_pre_process', 'gpeb_remove_fields_on_edit' ); | |
| function gpeb_remove_fields_on_edit( $form ) { | |
| $is_block = (bool) rgpost( 'gpeb_entry_id' ); | |
| if ( ! $is_block ) { | |
| $is_block = class_exists( 'WP_Block_Supports' ) && rgar( WP_Block_Supports::$block_to_render, 'blockName' ) === 'gp-entry-blocks/edit-form'; | |
| } | |
| if ( ! $is_block ) { | |
| return $form; | |
| } | |
| foreach ( $form['fields'] as &$field ) { | |
| $page = GFFormsModel::get_page_by_number( $form, $field->pageNumber ); | |
| if ( strpos( $field->cssClass, 'gpeb-remove-on-edit' ) !== false || strpos( $page->cssClass, 'gpeb-remove-on-edit' ) !== false) { | |
| $field->visibility = 'administrative'; | |
| } | |
| if ( $field->type == 'page' && strpos( $field->cssClass, 'gpeb-remove-on-edit' ) !== false ) { | |
| $field->conditionalLogic = array( | |
| 'actionType' => 'show', | |
| 'logicType' => 'all', | |
| 'rules' => array( | |
| array( | |
| 'fieldId' => 9999, // A dummy field ID that will never match. | |
| 'operator' => 'is', | |
| 'value' => 'hide' | |
| ) | |
| ) | |
| ); | |
| } | |
| } | |
| return $form; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment