Created
May 14, 2025 21:10
-
-
Save rafaehlers/4d48a377728981ac232bbcce8153dd0a to your computer and use it in GitHub Desktop.
Remove the “Due” choice from a specific Drop Down field on Inline Edit (GravityEdit)
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 // DO NOT COPY THIS LINE | |
/** | |
* Remove the “Due” choice from a specific Drop Down field. | |
* | |
* – change 123 to your form ID | |
* – change 456 to your View ID | |
* – change 789 to your dropdown field ID | |
* | |
*/ | |
add_filter( 'gform_pre_render_123', 'gk_remove_due_choice' ); | |
function gk_remove_due_choice( $form ) { | |
$view_id = GravityView_View::getInstance()->getViewId(); | |
if($view_id == 456){ | |
foreach ( $form['fields'] as &$field ) { | |
// Target the right field; 789 is the example field ID. | |
if ( $field->id !== 789 || $field->type !== 'select' ) { | |
continue; | |
} | |
// Remove any choice whose text or value is “Due”. | |
foreach ( $field->choices as $index => $choice ) { | |
if ( rgar( $choice, 'text' ) === 'Due' || rgar( $choice, 'value' ) === 'Due' ) { | |
unset( $field->choices[ $index ] ); | |
} | |
} | |
// Re-index so Gravity Forms doesn’t complain. | |
$field->choices = array_values( $field->choices ); | |
} | |
} | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment