From f585b01a69688a36aaed5998f83fc5d246e2ba60 Mon Sep 17 00:00:00 2001 From: David Smith Date: Mon, 4 Apr 2022 22:49:41 -0400 Subject: [PATCH] Added support for mapping all checkboxes of a Checkbox field to a custom field. --- gravity-forms/gw-update-posts.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gravity-forms/gw-update-posts.php b/gravity-forms/gw-update-posts.php index 4bcd1ce3a..541ed8fce 100644 --- a/gravity-forms/gw-update-posts.php +++ b/gravity-forms/gw-update-posts.php @@ -125,6 +125,19 @@ public function update_post_by_entry( $entry, $form ) { $meta_value = rgar( $entry, $value ); + $field = GFAPI::get_field( $form, $value ); + + // Support mapping all checkboxes of a Checkbox field to a custom field. + if ( $field->get_input_type() === 'checkbox' && $value != (int) $value ) { + $meta_value = $field->get_value_export( $entry ); + if ( is_callable( 'acf_get_field' ) ) { + $acf_field = acf_get_field( $key ); + if ( $acf_field ) { + $meta_value = array_map( 'trim', explode( ',', $meta_value ) ); + } + } + } + // Check for ACF image-like custom fields. Integration powered by GP Media Library. $acf_field = is_callable( 'gp_media_library' ) && is_callable( 'acf_get_field' ) ? acf_get_field( $key ) : false; if ( $acf_field && in_array( $acf_field['type'], array( 'image', 'file', 'gallery' ), true ) ) {