Last active
September 7, 2016 01:46
-
-
Save hellofromtonya/1a116126653dd96e4dbb to your computer and use it in GitHub Desktop.
Gravity Forms - Add new predefined bulk choices (including specifying label and value)
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
add_filter('gform_predefined_choices', 'lunarwp\add_predefined_choice'); | |
/** | |
* Add custom Bulk Predefined Choices to Gravity Forms for Regions | |
* | |
* @since 1.0.0 | |
* | |
* @param array $choices Predefined choices array | |
* @return array Amended array with our new choices added | |
*/ | |
function add_predefined_choice($choices) | |
{ | |
//* (optional) Fetch the colors from somewhere in the database to avoid hard-coding | |
//* Or just manually build it here | |
$colors['Custom Colors'] = array( | |
'Black | 000', | |
'White | fff', | |
'Gray | 555', | |
'Blue | 049cdb', | |
); | |
//* To avoid scrolling down the list when you open up the Bulk Choices, | |
//* let's add it to the top of the $choices array. | |
$choices = $colors + $choices; | |
return $choices; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment