Forked from spivurno/gw-gravity-forms-get-custom-choices.php
Created
September 5, 2016 04:54
-
-
Save phillipwilhelm/7d226bc8e50c3f90c8dc94ef00d946b0 to your computer and use it in GitHub Desktop.
Gravity Wiz // Gravity Forms // Get Custom Choices Helper Function
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 | |
| /** | |
| * Gravity Wiz // Gravity Forms // Get Custom Choices Helper Function | |
| * | |
| * A function that accepts a group name of one of your Gravity Form "Custom Choices" (http://grab.by/yNaS) and | |
| * returns an array with the text and value options for each choice. | |
| * | |
| * @author David Smith <[email protected]> | |
| * @license GPL-2.0+ | |
| * @link http://gravitywiz.com/... | |
| */ | |
| function gw_get_custom_choices( $group ) { | |
| $custom_choices = GFFormsModel::get_custom_choices(); | |
| $choices = array(); | |
| foreach( $custom_choices as $group_name => $choice_group ) { | |
| if( $group_name != $group ) { | |
| continue; | |
| } | |
| foreach( $choice_group as $choice ) { | |
| list( $text, $value ) = array_pad( explode( '|', $choice ), 2, false ); | |
| $choice = array( | |
| 'text' => $text, | |
| 'value' => $value ? $value : $text | |
| ); | |
| $choices[] = $choice; | |
| } | |
| } | |
| return $choices; | |
| } | |
| ## Usage Example | |
| $colors = gw_get_custom_choices( 'Colors' ); | |
| ?> | |
| <ul> | |
| <?php foreach( $colors as $color ): ?> | |
| <li><?php echo $color['text']; ?></li> | |
| <?php endforeach; ?> | |
| </ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment