Created
May 26, 2020 21:26
-
-
Save swoboda/badb3576de68eb58cce5ba152afbf365 to your computer and use it in GitHub Desktop.
Option groups in the Gravity Forms drop down field
This file contains 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 include the opening php tag | |
add_filter( 'gform_field_choice_markup_pre_render', function ( $choice_markup, $choice, $field ) { | |
if ( $field->get_input_type() == 'select' ) { | |
$choice_value = rgar( $choice, 'value' ); | |
if ( $choice_value === 'optgroup-start' ) { | |
return sprintf( '<optgroup label="%s">', esc_html( $choice['text'] ) ); | |
} elseif ( $choice_value === 'optgroup-end' ) { | |
return '</optgroup>'; | |
} | |
} | |
return $choice_markup; | |
}, 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment