Skip to content

Instantly share code, notes, and snippets.

@saifsultanc
Last active August 6, 2025 08:37
Show Gist options
  • Select an option

  • Save saifsultanc/727a559978a5cac34f3f9348eac891da to your computer and use it in GitHub Desktop.

Select an option

Save saifsultanc/727a559978a5cac34f3f9348eac891da to your computer and use it in GitHub Desktop.
gpi_ignore_disabled_on_gravityview.php
<?php
add_filter( 'gform_field_content', function( $content, $field, $value, $lead_form_id ) {
if ( ! rgget( 'edit' ) || ! rgget( 'gvid' ) ) {
return $content;
}
libxml_use_internal_errors( true );
$doc = new DOMDocument();
$doc->loadHTML( '<?xml encoding="utf-8" ?>' . $content );
$xpath = new DOMXPath( $doc );
// Select any element with 'gpi-disabled' class.
$nodes = $xpath->query( '//*[contains(@class, "gpi-disabled")]' );
foreach ( $nodes as $node ) {
// Remove 'disabled' attribute if present.
if ( $node->hasAttribute( 'disabled' ) ) {
$node->removeAttribute( 'disabled' );
}
// Remove 'gpi-disabled' class.
$class = $node->getAttribute( 'class' );
$class = preg_replace( '/\bgpi-disabled\b/', '', $class );
$class = trim( preg_replace( '/\s+/', ' ', $class ) );
$node->setAttribute( 'class', $class );
}
// Extract updated content from <body>.
$body = $doc->getElementsByTagName( 'body' )->item( 0 );
$cleaned = '';
foreach ( $body->childNodes as $child ) {
$cleaned .= $doc->saveHTML( $child );
}
return $cleaned;
}, 16, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment