-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
gppa-populate-acf-field-choices.php
: Added new snippet.
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
/** | ||
* Gravity Perks // Populate Anything // Populate Choice-based ACF Field as Choices | ||
* https://gravitywiz.com/documentation/gravity-forms-populate-anything/ | ||
* | ||
* Instruction Video: Incoming... | ||
* | ||
* Use Populate Anything's field settings to map a choice-based ACF field to a Gravity Forms choice-based field (e.g. | ||
* Drop Down, Radio Buttons, Checkboxes, etc). Then, use this snippet to automatically convert the ACF choices into | ||
* choices in the Gravity Forms field. | ||
*/ | ||
add_filter( 'gppa_input_choices', function ( $choices, $field ) { | ||
|
||
if ( empty( $field->choices ) ) { | ||
return $choices; | ||
} | ||
|
||
$object = rgar( $choices[0], 'object' ); | ||
if ( ! $object|| ! is_a( $object, 'WP_Post' ) || $object->post_type !== 'acf-field' ) { | ||
return $choices; | ||
} | ||
|
||
$acf_field_config = maybe_unserialize( $object->post_content ); | ||
if ( ! $acf_field_config || empty( $acf_field_config['choices'] ) ) { | ||
return $choices; | ||
} | ||
|
||
$new_choices = array(); | ||
|
||
foreach ( $acf_field_config['choices'] as $value => $label ) { | ||
$new_choices[] = array( | ||
'value' => $value, | ||
'text' => $label, | ||
'isSelected' => false, | ||
); | ||
} | ||
|
||
return $new_choices; | ||
}, 10, 2 ); |