Last active
August 11, 2022 22:38
-
-
Save RadGH/ea41e83399e6c80f7511109c3a804068 to your computer and use it in GitHub Desktop.
Gets a field value from a Gravity Form field, formatted to be compatible with the "gform_field_value" filter (particularly for checkboxes). Replaced with: https://gist.github.com/RadGH/d08a7466b097dfb895ec6dede2e474f5
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 | |
// ------------------------------------------------------------------------------------- | |
// Replaced with: https://gist.github.com/RadGH/d08a7466b097dfb895ec6dede2e474f5 | |
// | |
// Gravity Forms still does not have an official method to get selected checkboxes lmao. | |
// ------------------------------------------------------------------------------------- | |
/** | |
* Get the values for a field, compatible with the filter "gform_field_value" particularly for checkbox fields. | |
* | |
* Uses the native "get_post_field_value" function which is sadly private (for no good reason). | |
* | |
* @see https://stackoverflow.com/a/40441769 | |
* | |
* @param GF_Field $field | |
* @param array $lead | |
* | |
* @return mixed | |
*/ | |
function gf_get_field_value_from_entry( GF_Field $field, array $entry ) { | |
static $formsModel = null, $getValueFn; | |
if ( $formsModel === null ) { | |
$formsModel = new GFFormsModel(); | |
$getValueFn = function( $a = null, $b = null ) { | |
return $this->get_post_field_value( $a, $b ); | |
}; | |
} | |
return $getValueFn->call( $formsModel, $field, $entry ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replaced with: https://gist.github.com/RadGH/d08a7466b097dfb895ec6dede2e474f5