Skip to content

Instantly share code, notes, and snippets.

@hellofromtonya
Last active September 7, 2016 01:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hellofromtonya/1a116126653dd96e4dbb to your computer and use it in GitHub Desktop.
Save hellofromtonya/1a116126653dd96e4dbb to your computer and use it in GitHub Desktop.
Gravity Forms - Add new predefined bulk choices (including specifying label and value)
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