Skip to content

Instantly share code, notes, and snippets.

@saifsultanc
Created August 12, 2025 06:29
Show Gist options
  • Select an option

  • Save saifsultanc/7b31cff00752323d226f861c4cab470f to your computer and use it in GitHub Desktop.

Select an option

Save saifsultanc/7b31cff00752323d226f861c4cab470f to your computer and use it in GitHub Desktop.
gpeb-test-snippet.php
<?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